|
Apache CXF example source code file (JAXRSClientFactoryBean.java)
The Apache CXF JAXRSClientFactoryBean.java source code/** * 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.net.URI; import java.util.Map; import java.util.logging.Logger; import javax.ws.rs.core.MultivaluedMap; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.ProxyHelper; import org.apache.cxf.configuration.security.AuthorizationPolicy; import org.apache.cxf.endpoint.ConduitSelector; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.endpoint.UpfrontConduitSelector; import org.apache.cxf.feature.AbstractFeature; import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean; import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean; import org.apache.cxf.jaxrs.JAXRSServiceImpl; import org.apache.cxf.jaxrs.impl.MetadataMap; import org.apache.cxf.jaxrs.model.ClassResourceInfo; import org.apache.cxf.service.Service; public class JAXRSClientFactoryBean extends AbstractJAXRSFactoryBean { private static final Logger LOG = LogUtils.getL7dLogger(JAXRSClientFactoryBean.class); private String username; private String password; private boolean inheritHeaders; private MultivaluedMap<String, String> headers; private ClientState initialState; private boolean threadSafe; public JAXRSClientFactoryBean() { this(new JAXRSServiceFactoryBean()); } public JAXRSClientFactoryBean(JAXRSServiceFactoryBean serviceFactory) { super(serviceFactory); serviceFactory.setEnableStaticResolution(true); } public void setThreadSafe(boolean threadSafe) { this.threadSafe = threadSafe; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public void setInheritHeaders(boolean ih) { inheritHeaders = ih; } public void setResourceClass(Class cls) { setServiceClass(cls); } public void setServiceClass(Class cls) { serviceFactory.setResourceClass(cls); } public void setHeaders(Map<String, String> map) { headers = new MetadataMap<String, String>(); for (Map.Entry<String, String> entry : map.entrySet()) { String[] values = entry.getValue().split(","); for (String v : values) { if (v.length() != 0) { headers.add(entry.getKey(), v); } } } } public Map getHeaders() { return headers; } public WebClient createWebClient() { Service service = new JAXRSServiceImpl(getAddress(), getServiceName()); getServiceFactory().setService(service); try { Endpoint ep = createEndpoint(); ClientState actualState = getActualState(); WebClient client = actualState == null ? new WebClient(getAddress()) : new WebClient(actualState); initClient(client, ep, actualState == null); return client; } catch (Exception ex) { LOG.severe(ex.getClass().getName() + " : " + ex.getLocalizedMessage()); throw new RuntimeException(ex); } } private ClientState getActualState() { if (threadSafe) { initialState = new ThreadLocalClientState(getAddress()); } if (initialState != null) { return headers != null ? initialState.newState(URI.create(getAddress()), headers, null) : initialState; } else { return null; } } public <T> T create(Class Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF JAXRSClientFactoryBean.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.