Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.jaxrs.client;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.ClientException;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.InterceptorProvider;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.impl.ResponseImpl;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.model.Parameter;
import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.FormUtils;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
/**
* Proxy-based client implementation
*
*/
public class ClientProxyImpl extends AbstractClient implements
InvocationHandlerAware, InvocationHandler {
private static final Logger LOG = LogUtils.getL7dLogger(ClientProxyImpl.class);
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ClientProxyImpl.class);
private static final String SLASH = "/";
private ClassResourceInfo cri;
private ClassLoader proxyLoader;
private boolean inheritHeaders;
private boolean isRoot;
private Map valuesMap = Collections.emptyMap();
public ClientProxyImpl(URI baseURI,
ClassLoader loader,
ClassResourceInfo cri,
boolean isRoot,
boolean inheritHeaders,
Object... varValues) {
this(new LocalClientState(baseURI), loader, cri, isRoot, inheritHeaders, varValues);
}
public ClientProxyImpl(ClientState initialState,
ClassLoader loader,
ClassResourceInfo cri,
boolean isRoot,
boolean inheritHeaders,
Object... varValues) {
super(initialState);
this.proxyLoader = loader;
this.cri = cri;
this.isRoot = isRoot;
this.inheritHeaders = inheritHeaders;
initValuesMap(varValues);
}
private void initValuesMap(Object... varValues) {
if (isRoot) {
List vars = cri.getURITemplate().getVariables();
valuesMap = new LinkedHashMap();
for (int i = 0; i < vars.size(); i++) {
if (varValues.length > 0) {
if (i < varValues.length) {
valuesMap.put(vars.get(i), varValues[i]);
} else {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
"ROOT_VARS_MISMATCH", BUNDLE, vars.size(), varValues.length);
LOG.info(msg.toString());
break;
}
} else {
valuesMap.put(vars.get(i), "");
}
}
}
}
/**
* Updates the current state if Client method is invoked, otherwise
* does the remote invocation or returns a new proxy if subresource
* method is invoked. Can throw an expected exception if ResponseExceptionMapper
* is registered
*/
public Object invoke(Object o, Method m, Object[] params) throws Throwable {
Class> declaringClass = m.getDeclaringClass();
if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass
|| Object.class == declaringClass) {
return m.invoke(this, params);
}
resetResponse();
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
if (ori == null) {
reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
}
MultivaluedMap types = getParametersInfo(params, ori);
List