protected URI calculateNewRequestURI(Map<String, Object> reqContext) { URI newBaseURI = URI.create(reqContext.get(Message.ENDPOINT_ADDRESS).toString()); URI requestURI = URI.create(reqContext.get(Message.REQUEST_URI).toString()); return calculateNewRequestURI(newBaseURI, requestURI, PropertyUtils.isTrue(reqContext.get(PROXY_PROPERTY))); }
protected URI calculateNewRequestURI(Map<String, Object> reqContext) { URI newBaseURI = URI.create(reqContext.get(Message.ENDPOINT_ADDRESS).toString()); URI requestURI = URI.create(reqContext.get(Message.REQUEST_URI).toString()); return calculateNewRequestURI(newBaseURI, requestURI, MessageUtils.isTrue(reqContext.get(PROXY_PROPERTY))); }
protected URI calculateNewRequestURI(Map<String, Object> reqContext) { URI newBaseURI = URI.create(reqContext.get(Message.ENDPOINT_ADDRESS).toString()); URI requestURI = URI.create(reqContext.get(Message.REQUEST_URI).toString()); return calculateNewRequestURI(newBaseURI, requestURI, PropertyUtils.isTrue(reqContext.get(PROXY_PROPERTY))); }
@SuppressWarnings("unchecked") protected Object[] retryInvoke(BindingOperationInfo oi, Object[] params, Map<String, Object> context, Exchange exchange) throws Exception { try { Object body = params.length == 0 ? null : params[0]; Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)context.get(REQUEST_CONTEXT)); MultivaluedMap<String, String> headers = (MultivaluedMap<String, String>)reqContext.get(Message.PROTOCOL_HEADERS); URI newRequestURI = calculateNewRequestURI(reqContext); // TODO: if failover conduit selector fails to find a failover target // then it will revert to the previous endpoint; that is not very likely // but possible - thus ideally we need to resert base and current URI only // if we get the same ConduitInitiatior endpoint instance before and after // retryInvoke. Object response = retryInvoke(newRequestURI, headers, body, exchange, context); exchange.put(List.class, getContentsList(response)); return new Object[]{response}; } catch (Throwable t) { Exception ex = t instanceof Exception ? (Exception)t : new Exception(t); exchange.put(Exception.class, ex); return null; } }
@SuppressWarnings("unchecked") public Object[] invoke(BindingOperationInfo oi, Object[] params, Map<String, Object> context, Exchange exchange) throws Exception { try { Object body = params.length == 0 ? null : params[0]; Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)context.get(REQUEST_CONTEXT)); MultivaluedMap<String, String> headers = (MultivaluedMap<String, String>)reqContext.get(Message.PROTOCOL_HEADERS); URI newRequestURI = calculateNewRequestURI(reqContext); // TODO: if failover conduit selector fails to find a failover target // then it will revert to the previous endpoint; that is not very likely // but possible - thus ideally we need to resert base and current URI only // if we get the same ConduitInitiatior endpoint instance before and after // retryInvoke. Object response = retryInvoke(newRequestURI, headers, body, exchange, context); exchange.put(List.class, getContentsList(response)); return new Object[]{response}; } catch (Throwable t) { Exception ex = t instanceof Exception ? (Exception)t : new Exception(t); exchange.put(Exception.class, ex); return null; } }
@SuppressWarnings("unchecked") protected Object[] retryInvoke(BindingOperationInfo oi, Object[] params, Map<String, Object> context, Exchange exchange) throws Exception { try { Object body = params.length == 0 ? null : params[0]; Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)context.get(REQUEST_CONTEXT)); MultivaluedMap<String, String> headers = (MultivaluedMap<String, String>)reqContext.get(Message.PROTOCOL_HEADERS); URI newRequestURI = calculateNewRequestURI(reqContext); // TODO: if failover conduit selector fails to find a failover target // then it will revert to the previous endpoint; that is not very likely // but possible - thus ideally we need to resert base and current URI only // if we get the same ConduitInitiatior endpoint instance before and after // retryInvoke. Object response = retryInvoke(newRequestURI, headers, body, exchange, context); exchange.put(List.class, getContentsList(response)); return new Object[]{response}; } catch (Throwable t) { Exception ex = t instanceof Exception ? (Exception)t : new Exception(t); exchange.put(Exception.class, ex); return null; } }
protected void completeExchange(Exchange exchange, boolean proxy) { // higher level conduits such as FailoverTargetSelector need to // clear the request state but a fair number of response objects // depend on InputStream being still open thus lower-level conduits // operating on InputStream don't have to close streams pro-actively exchange.put(KEEP_CONDUIT_ALIVE, true); getConfiguration().getConduitSelector().complete(exchange); String s = (String)exchange.getOutMessage().get(Message.BASE_PATH); if (s != null && !state.getBaseURI().toString().equals(s)) { // usually the (failover) conduit change will result in a retry call // which in turn will reset the base and current request URI. // In some cases, such as the "upfront" load-balancing, etc, the retries // won't be executed so it is necessary to reset the base address calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy); return; } s = (String)exchange.getOutMessage().get("transport.retransmit.url"); if (s != null && !state.getBaseURI().toString().equals(s)) { calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy); } }
protected void completeExchange(Exchange exchange, boolean proxy) { // higher level conduits such as FailoverTargetSelector need to // clear the request state but a fair number of response objects // depend on InputStream being still open thus lower-level conduits // operating on InputStream don't have to close streams pro-actively exchange.put(KEEP_CONDUIT_ALIVE, true); getConfiguration().getConduitSelector().complete(exchange); String s = (String)exchange.getOutMessage().get(Message.BASE_PATH); if (s != null && !state.getBaseURI().toString().equals(s)) { // usually the (failover) conduit change will result in a retry call // which in turn will reset the base and current request URI. // In some cases, such as the "upfront" load-balancing, etc, the retries // won't be executed so it is necessary to reset the base address calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy); return; } s = (String)exchange.getOutMessage().get("transport.retransmit.url"); if (s != null && !state.getBaseURI().toString().equals(s)) { calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy); } }
protected void prepareConduitSelector(Message message, URI currentURI, boolean proxy) { try { cfg.prepareConduitSelector(message); } catch (Fault ex) { LOG.warning("Failure to prepare a message from conduit selector"); } message.getExchange().put(ConduitSelector.class, cfg.getConduitSelector()); message.getExchange().put(Service.class, cfg.getConduitSelector().getEndpoint().getService()); String address = (String)message.get(Message.ENDPOINT_ADDRESS); // custom conduits may override the initial/current address if (address.startsWith(HTTP_SCHEME) && !address.equals(currentURI.toString())) { URI baseAddress = URI.create(address); currentURI = calculateNewRequestURI(baseAddress, currentURI, proxy); message.put(Message.ENDPOINT_ADDRESS, currentURI.toString()); message.put(Message.REQUEST_URI, currentURI.toString()); } message.put(Message.BASE_PATH, getBaseURI().toString()); }
protected void completeExchange(Object response, Exchange exchange, boolean proxy) { // higher level conduits such as FailoverTargetSelector need to // clear the request state but a fair number of response objects // depend on InputStream being still open thus lower-level conduits // operating on InputStream don't have to close streams pro-actively exchange.put(KEEP_CONDUIT_ALIVE, true); getConfiguration().getConduitSelector().complete(exchange); String s = (String)exchange.getOutMessage().get(Message.BASE_PATH); if (s != null && !state.getBaseURI().toString().equals(s)) { // usually the (failover) conduit change will result in a retry call // which in turn will reset the base and current request URI. // In some cases, such as the "upfront" load-balancing, etc, the retries // won't be executed so it is necessary to reset the base address calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy); } }
protected void prepareConduitSelector(Message message, URI currentURI, boolean proxy) { try { cfg.prepareConduitSelector(message); } catch (Fault ex) { LOG.warning("Failure to prepare a message from conduit selector"); } message.getExchange().put(ConduitSelector.class, cfg.getConduitSelector()); message.getExchange().put(Service.class, cfg.getConduitSelector().getEndpoint().getService()); String address = (String)message.get(Message.ENDPOINT_ADDRESS); // custom conduits may override the initial/current address if (address.startsWith(HTTP_SCHEME) && !address.equals(currentURI.toString())) { URI baseAddress = URI.create(address); currentURI = calculateNewRequestURI(baseAddress, currentURI, proxy); message.put(Message.ENDPOINT_ADDRESS, currentURI.toString()); message.put(Message.REQUEST_URI, currentURI.toString()); } message.put(Message.BASE_PATH, getBaseURI().toString()); }
protected void prepareConduitSelector(Message message, URI currentURI, boolean proxy) { try { cfg.prepareConduitSelector(message); } catch (Fault ex) { LOG.warning("Failure to prepare a message from conduit selector"); } message.getExchange().put(ConduitSelector.class, cfg.getConduitSelector()); message.getExchange().put(Service.class, cfg.getConduitSelector().getEndpoint().getService()); String address = (String)message.get(Message.ENDPOINT_ADDRESS); // custom conduits may override the initial/current address if (address.startsWith(HTTP_SCHEME) && !address.equals(currentURI.toString())) { URI baseAddress = URI.create(address); currentURI = calculateNewRequestURI(baseAddress, currentURI, proxy); message.put(Message.ENDPOINT_ADDRESS, currentURI.toString()); message.put(Message.REQUEST_URI, currentURI.toString()); } message.put(Message.BASE_PATH, getBaseURI().toString()); }