protected Message createMessage(Object body, OperationResourceInfo ori, MultivaluedMap<String, String> headers, URI currentURI, Exchange exchange, Map<String, Object> invocationContext, boolean isProxy) { return createMessage(body, ori.getHttpMethod(), headers, currentURI, exchange, invocationContext, isProxy); }
protected Object doInvokeAsync(OperationResourceInfo ori, Message outMessage, InvocationCallback<Object> asyncCallback) { outMessage.getExchange().setSynchronous(false); setAsyncMessageObserverIfNeeded(outMessage.getExchange()); JaxrsClientCallback<?> cb = newJaxrsClientCallback(asyncCallback, ori.getMethodToInvoke().getReturnType(), ori.getMethodToInvoke().getGenericReturnType()); outMessage.getExchange().put(JaxrsClientCallback.class, cb); doRunInterceptorChain(outMessage); return null; }
protected ClientProxyImpl createClientProxy(ClassResourceInfo cri, boolean isRoot, ClientState actualState, Object[] varValues) { if (actualState == null) { return new ClientProxyImpl(URI.create(getAddress()), proxyLoader, cri, isRoot, inheritHeaders, varValues); } else { return new ClientProxyImpl(actualState, proxyLoader, cri, isRoot, inheritHeaders, varValues); } }
protected MultivaluedMap<String, String> handleForm(Method m, Object[] params, MultivaluedMap<ParameterType, Parameter> map, List<Parameter> beanParams) { MultivaluedMap<String, String> form = new MetadataMap<>(); List<Parameter> fm = getParameters(map, ParameterType.FORM); fm.forEach(p -> { addFormValue(form, p.getName(), params[p.getIndex()], getParamAnnotations(m, p)); }); beanParams.stream(). map(p -> getValuesFromBeanParam(params[p.getIndex()], FormParam.class)). forEachOrdered(values -> { values.forEach((key, value) -> { addFormValue(form, key, value.getValue(), value.getAnns()); }); }); return form; }
protected void handleHeaders(Method m, Object[] params, MultivaluedMap<String, String> headers, List<Parameter> beanParams, MultivaluedMap<ParameterType, Parameter> map) { List<Parameter> hs = getParameters(map, ParameterType.HEADER); hs.stream(). filter(p -> params[p.getIndex()] != null). forEachOrdered(p -> { headers.add(p.getName(), convertParamValue(params[p.getIndex()], getParamAnnotations(m, p))); }); beanParams.stream(). map(p -> getValuesFromBeanParam(params[p.getIndex()], HeaderParam.class)). forEachOrdered(values -> { values.forEach((key, value) -> { if (value != null) { headers.add(key, convertParamValue(value.getValue(), value.getAnns())); } }); }); }
protected void handleMatrixes(Method m, Object[] params, MultivaluedMap<ParameterType, Parameter> map, List<Parameter> beanParams, UriBuilder ub) { List<Parameter> mx = getParameters(map, ParameterType.MATRIX); mx.stream(). filter(p -> params[p.getIndex()] != null). forEachOrdered(p -> { addMatrixQueryParamsToBuilder(ub, p.getName(), ParameterType.MATRIX, getParamAnnotations(m, p), params[p.getIndex()]); }); beanParams.stream(). map(p -> getValuesFromBeanParam(params[p.getIndex()], MatrixParam.class)). forEachOrdered(values -> { values.forEach((key, value) -> { if (value != null) { addMatrixQueryParamsToBuilder(ub, key, ParameterType.MATRIX, value.getAnns(), value.getValue()); } }); }); }
resetResponse(); OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m); if (ori == null) { if (m.isDefault()) { return invokeDefaultMethod(declaringClass, o, m, params); reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD"); MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori); List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN); int bodyIndex = getBodyIndex(types, ori); List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex); UriBuilder builder = getCurrentBuilder().clone(); if (isRoot) { addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue()); addNonEmptyPath(builder, ori.getURITemplate().getValue()); handleMatrixes(m, params, types, beanParamsList, builder); handleQueries(m, params, types, beanParamsList, builder); MultivaluedMap<String, String> headers = getHeaders(); MultivaluedMap<String, String> paramHeaders = new MetadataMap<>(); handleHeaders(m, params, paramHeaders, beanParamsList, types); handleCookies(m, params, paramHeaders, beanParamsList, types);
Bus configuredBus = getConfiguration().getBus(); Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus); ClassLoaderHolder origLoader = null; Message outMessage = createMessage(body, ori, headers, uri, exchange, invocationContext, true); if (bodyIndex != -1) { outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]); setSupportOnewayResponseProperty(outMessage); outMessage.setContent(OperationResourceInfo.class, ori); setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName()); outMessage.getExchange().put(Method.class, ori.getMethodToInvoke()); getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex)); Map<String, Object> reqContext = getRequestContext(outMessage); reqContext.put(OperationResourceInfo.class.getName(), ori); reqContext.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex); InvocationCallback<Object> asyncCallback = checkAsyncCallback(ori, reqContext, outMessage); if (asyncCallback != null) { return doInvokeAsync(ori, outMessage, asyncCallback); doRunInterceptorChain(outMessage); Object[] results = preProcessResult(outMessage); if (results != null && results.length == 1) { return results[0];
protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable { try { Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build(); ((ResponseImpl)r).setMessage(outMessage); getState().setResponse(r); checkResponse(method, r, outMessage); if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) { return null; method.getGenericReturnType()); returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType); return readBody(r, outMessage, returnType,
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { try { Object entity = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass()); cb.handleResponse(message, new Object[] {entity}); } catch (Throwable t) { cb.handleException(message, t); } finally { completeExchange(message.getExchange(), false); closeAsyncResponseIfPossible(r, message, cb); } } }
@Override protected void doRunInterceptorChain(Message message) { setTimeouts(cfg.getRequestContext()); super.doRunInterceptorChain(message); }
List<Parameter> beanParams, MultivaluedMap<ParameterType, Parameter> map) { super.handleHeaders(m, params, headers, beanParams, map);
protected void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) { if (pValue != null) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns)); } } else { FormUtils.addPropertyToForm(form, name, name.isEmpty() ? pValue : convertParamValue(pValue, anns)); } } }
resetResponse(); OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m); if (ori == null) { if (m.isDefault()) { return invokeDefaultMethod(declaringClass, o, m, params); reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD"); MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori); List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN); int bodyIndex = getBodyIndex(types, ori); List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex); UriBuilder builder = getCurrentBuilder().clone(); if (isRoot) { addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue()); addNonEmptyPath(builder, ori.getURITemplate().getValue()); handleMatrixes(m, params, types, beanParamsList, builder); handleQueries(m, params, types, beanParamsList, builder); MultivaluedMap<String, String> headers = getHeaders(); MultivaluedMap<String, String> paramHeaders = new MetadataMap<>(); handleHeaders(m, params, paramHeaders, beanParamsList, types); handleCookies(m, params, paramHeaders, beanParamsList, types);
Bus configuredBus = getConfiguration().getBus(); Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus); ClassLoaderHolder origLoader = null; Message outMessage = createMessage(body, ori, headers, uri, exchange, invocationContext, true); if (bodyIndex != -1) { outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]); setSupportOnewayResponseProperty(outMessage); outMessage.setContent(OperationResourceInfo.class, ori); setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName()); outMessage.getExchange().put(Method.class, ori.getMethodToInvoke()); getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex)); Map<String, Object> reqContext = getRequestContext(outMessage); reqContext.put(OperationResourceInfo.class.getName(), ori); reqContext.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex); InvocationCallback<Object> asyncCallback = checkAsyncCallback(ori, reqContext, outMessage); if (asyncCallback != null) { return doInvokeAsync(ori, outMessage, asyncCallback); doRunInterceptorChain(outMessage); Object[] results = preProcessResult(outMessage); if (results != null && results.length == 1) { return results[0];
protected void handleHeaders(Method m, Object[] params, MultivaluedMap<String, String> headers, List<Parameter> beanParams, MultivaluedMap<ParameterType, Parameter> map) { List<Parameter> hs = getParameters(map, ParameterType.HEADER); hs.stream(). filter(p -> params[p.getIndex()] != null). forEachOrdered(p -> { headers.add(p.getName(), convertParamValue(params[p.getIndex()], getParamAnnotations(m, p))); }); beanParams.stream(). map(p -> getValuesFromBeanParam(params[p.getIndex()], HeaderParam.class)). forEachOrdered(values -> { values.forEach((key, value) -> { if (value != null) { headers.add(key, convertParamValue(value.getValue(), value.getAnns())); } }); }); }
protected void handleQueries(Method m, Object[] params, MultivaluedMap<ParameterType, Parameter> map, List<Parameter> beanParams, UriBuilder ub) { List<Parameter> qs = getParameters(map, ParameterType.QUERY); qs.stream(). filter(p -> params[p.getIndex()] != null). forEachOrdered(p -> { addMatrixQueryParamsToBuilder(ub, p.getName(), ParameterType.QUERY, getParamAnnotations(m, p), params[p.getIndex()]); }); beanParams.stream(). map(p -> getValuesFromBeanParam(params[p.getIndex()], QueryParam.class)). forEachOrdered(values -> { values.forEach((key, value) -> { if (value != null) { addMatrixQueryParamsToBuilder(ub, key, ParameterType.QUERY, value.getAnns(), value.getValue()); } }); }); }
protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable { try { Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build(); ((ResponseImpl)r).setOutMessage(outMessage); getState().setResponse(r); checkResponse(method, r, outMessage); if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) { return null; Class<?> returnType = getReturnType(method, outMessage); Type genericType = InjectionUtils.processGenericTypeIfNeeded(serviceCls, method.getGenericReturnType()); returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType); return readBody(r, outMessage, returnType,
private MultivaluedMap<String, String> handleForm(Method m, Object[] params, MultivaluedMap<ParameterType, Parameter> map, List<Parameter> beanParams) { MultivaluedMap<String, String> form = new MetadataMap<String, String>(); List<Parameter> fm = getParameters(map, ParameterType.FORM); for (Parameter p : fm) { addFormValue(form, p.getName(), params[p.getIndex()], getParamAnnotations(m, p)); } for (Parameter p : beanParams) { Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], FormParam.class); for (Map.Entry<String, BeanPair> entry : values.entrySet()) { addFormValue(form, entry.getKey(), entry.getValue().getValue(), entry.getValue().getAnns()); } } return form; }
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { try { Object entity = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass()); cb.handleResponse(message, new Object[] {entity}); } catch (Throwable t) { cb.handleException(message, t); } finally { completeExchange(message.getExchange(), false); closeAsyncResponseIfPossible(r, message, cb); } } }