org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl Maven / Gradle / Ivy
/**
* 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.spec;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.client.AsyncInvoker;
import javax.ws.rs.client.CompletionStageRxInvoker;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.client.RxInvoker;
import javax.ws.rs.client.SyncInvoker;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.GenericType;
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.ext.RuntimeDelegate;
import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.jaxrs.client.AbstractClient;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.utils.HttpUtils;
public class InvocationBuilderImpl implements Invocation.Builder {
private static final String PROPERTY_KEY = "jaxrs.filter.properties";
private WebClient webClient;
private SyncInvoker sync;
private Configuration config;
public InvocationBuilderImpl(WebClient webClient,
Configuration config) {
this.webClient = webClient;
this.sync = webClient.sync();
this.config = config;
}
public WebClient getWebClient() {
return this.webClient;
}
@Override
public Response delete() {
return sync.delete();
}
@Override
public T delete(Class cls) {
return sync.delete(cls);
}
@Override
public T delete(GenericType type) {
return sync.delete(type);
}
@Override
public Response get() {
return sync.get();
}
@Override
public T get(Class cls) {
return sync.get(cls);
}
@Override
public T get(GenericType type) {
return sync.get(type);
}
@Override
public Response head() {
return sync.head();
}
@Override
public Response method(String method) {
return sync.method(method);
}
@Override
public T method(String method, Class cls) {
return sync.method(method, cls);
}
@Override
public T method(String method, GenericType type) {
return sync.method(method, type);
}
@Override
public Response method(String method, Entity> entity) {
return sync.method(method, entity);
}
@Override
public T method(String method, Entity> entity, Class cls) {
return sync.method(method, entity, cls);
}
@Override
public T method(String method, Entity> entity, GenericType type) {
return sync.method(method, entity, type);
}
@Override
public Response options() {
return sync.options();
}
@Override
public T options(Class cls) {
return sync.options(cls);
}
@Override
public T options(GenericType type) {
return sync.options(type);
}
@Override
public Response post(Entity> entity) {
return sync.post(entity);
}
@Override
public T post(Entity> entity, Class cls) {
return sync.post(entity, cls);
}
@Override
public T post(Entity> entity, GenericType type) {
return sync.post(entity, type);
}
@Override
public Response put(Entity> entity) {
return sync.put(entity);
}
@Override
public T put(Entity> entity, Class cls) {
return sync.put(entity, cls);
}
@Override
public T put(Entity> entity, GenericType type) {
return sync.put(entity, type);
}
@Override
public Response trace() {
return sync.trace();
}
@Override
public T trace(Class cls) {
return sync.trace(cls);
}
@Override
public T trace(GenericType type) {
return sync.trace(type);
}
@Override
public Builder accept(String... types) {
webClient.accept(types);
return this;
}
@Override
public Builder accept(MediaType... types) {
webClient.accept(types);
return this;
}
@Override
public Builder acceptEncoding(String... enc) {
webClient.acceptEncoding(enc);
return this;
}
@Override
public Builder acceptLanguage(Locale... lang) {
for (Locale l : lang) {
webClient.acceptLanguage(HttpUtils.toHttpLanguage(l));
}
return this;
}
@Override
public Builder acceptLanguage(String... lang) {
webClient.acceptLanguage(lang);
return this;
}
@Override
public Builder cacheControl(CacheControl control) {
webClient.header(HttpHeaders.CACHE_CONTROL, control.toString());
return this;
}
@Override
public Builder cookie(Cookie cookie) {
webClient.cookie(cookie);
return this;
}
@Override
public Builder cookie(String name, String value) {
webClient.header(HttpHeaders.COOKIE, name + "=" + value);
return this;
}
@Override
public Builder header(String name, Object value) {
RuntimeDelegate rd = HttpUtils.getOtherRuntimeDelegate();
doSetHeader(rd, name, value);
return this;
}
@Override
public Builder headers(MultivaluedMap headers) {
webClient.removeAllHeaders();
if (headers != null) {
RuntimeDelegate rd = HttpUtils.getOtherRuntimeDelegate();
for (Map.Entry> entry : headers.entrySet()) {
for (Object value : entry.getValue()) {
doSetHeader(rd, entry.getKey(), value);
}
}
}
return this;
}
private void doSetHeader(RuntimeDelegate rd, String name, Object value) {
HeaderDelegate
© 2015 - 2025 Weber Informatics LLC | Privacy Policy