@Override public WebClient accept(String... types) { return (WebClient)super.accept(types); }
@Override public WebClient acceptEncoding(String ...encodings) { return (WebClient)super.acceptEncoding(encodings); }
@Override public WebClient acceptLanguage(String ...languages) { return (WebClient)super.acceptLanguage(languages); }
private void convertMatrixOrQueryToBuilder(UriBuilder ub, String paramName, Object pValue, ParameterType pt, Annotation[] anns) { Object convertedValue = convertParamValue(pValue, anns); addMatrixOrQueryToBuilder(ub, paramName, pt, convertedValue); }
/** * {@inheritDoc} */ public Client header(String name, Object... values) { if (values == null) { throw new IllegalArgumentException(); } if (HttpHeaders.CONTENT_TYPE.equals(name)) { if (values.length > 1) { throw new IllegalArgumentException("Content-Type can have a single value only"); } type(convertParamValue(values[0], null)); } else { for (Object o : values) { possiblyAddHeader(name, convertParamValue(o, null)); } } return this; }
Map<String, Object> invocationContext, boolean proxy) { checkClosed(); Message m = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(); m.put(Message.REQUESTOR_ROLE, Boolean.TRUE); m.put(Message.INBOUND_MESSAGE, Boolean.FALSE); setRequestMethod(m, httpMethod); m.put(Message.PROTOCOL_HEADERS, headers); if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME)) { body = checkIfBodyEmpty(body, ct); setEmptyRequestPropertyIfNeeded(m, body); m.setContent(List.class, getContentsList(body)); m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates()); PhaseInterceptorChain chain = setupOutInterceptorChain(cfg); chain.setFaultObserver(setupInFaultObserver(cfg)); m.setInterceptorChain(chain); exchange = createExchange(m, exchange); exchange.put(Message.REST_MESSAGE, Boolean.TRUE); exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST))); setContexts(m, exchange, invocationContext, proxy); prepareConduitSelector(m, currentURI, 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); } }
@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 Object[] preProcessResult(Message message) throws Exception { Exchange exchange = message.getExchange(); Exception ex = message.getContent(Exception.class); if (ex != null || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY)) && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY))) { getConfiguration().getConduitSelector().complete(exchange); } if (ex != null) { checkClientException(message, ex); } checkClientException(message, exchange.get(Exception.class)); List<?> result = exchange.get(List.class); return result != null ? result.toArray() : null; }
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()); }
? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { convertMatrixOrQueryToBuilder(ub, paramName, it.next(), pt, anns); convertMatrixOrQueryToBuilder(ub, paramName, pValue, pt, anns); addMatrixOrQueryToBuilder(ub, paramName, pt, pValues); for (Map.Entry<String, List<Object>> entry : values.entrySet()) { for (Object v : entry.getValue()) { convertMatrixOrQueryToBuilder(ub, entry.getKey(), v, pt, anns);
protected String convertParamValue(Object pValue, Annotation[] anns) { return convertParamValue(pValue, pValue == null ? null : pValue.getClass(), anns); } protected String convertParamValue(Object pValue, Class<?> pClass, Annotation[] anns) {
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))); }
@Override public WebClient cookie(Cookie cookie) { return (WebClient)super.cookie(cookie); }
Map<String, Object> invocationContext, boolean proxy) { checkClosed(); Message m = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(); m.put(Message.REQUESTOR_ROLE, Boolean.TRUE); m.put(Message.INBOUND_MESSAGE, Boolean.FALSE); setRequestMethod(m, httpMethod); m.put(Message.PROTOCOL_HEADERS, headers); if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME)) { body = checkIfBodyEmpty(body, ct); setEmptyRequestPropertyIfNeeded(m, body); m.setContent(List.class, getContentsList(body)); m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates()); PhaseInterceptorChain chain = setupOutInterceptorChain(cfg); chain.setFaultObserver(setupInFaultObserver(cfg)); m.setInterceptorChain(chain); exchange = createExchange(m, exchange); exchange.put(Message.REST_MESSAGE, Boolean.TRUE); exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST))); setContexts(m, exchange, invocationContext, proxy); prepareConduitSelector(m, currentURI, proxy);
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); } }
/** * {@inheritDoc} */ @Override public Client header(String name, Object... values) { if (values == null) { throw new IllegalArgumentException(); } if (HttpHeaders.CONTENT_TYPE.equals(name)) { if (values.length > 1) { throw new IllegalArgumentException("Content-Type can have a single value only"); } type(convertParamValue(values[0], null)); } else { for (Object o : values) { possiblyAddHeader(name, convertParamValue(o, null)); } } return this; }
@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; } }
private void convertMatrixOrQueryToBuilder(UriBuilder ub, String paramName, Object pValue, ParameterType pt, Annotation[] anns) { Object convertedValue = convertParamValue(pValue, anns); addMatrixOrQueryToBuilder(ub, paramName, pt, convertedValue); }
protected Object[] preProcessResult(Message message) throws Exception { Exchange exchange = message.getExchange(); Exception ex = message.getContent(Exception.class); if (ex == null) { ex = message.getExchange().get(Exception.class); } if (ex == null && !exchange.isOneWay()) { synchronized (exchange) { while (exchange.get("IN_CHAIN_COMPLETE") == null) { exchange.wait(cfg.getSynchronousTimeout()); } } } if (ex == null) { ex = message.getContent(Exception.class); } if (ex != null || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY)) && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY))) { getConfiguration().getConduitSelector().complete(exchange); } if (ex != null) { checkClientException(message, ex); } checkClientException(message, exchange.get(Exception.class)); List<?> result = exchange.get(List.class); return result != null ? result.toArray() : null; }