All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ovh.ws.jsonizer.common.http.JerseyHttpClient Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2012, OVH. All rights reserved.
 *
 * Licensed 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 com.ovh.ws.jsonizer.common.http;

import java.net.URI;

import javax.ws.rs.core.HttpHeaders;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

public class JerseyHttpClient extends AbstractHttpClient {

	private Client client;

	public JerseyHttpClient() {
		client = Client.create();
	}

	/**
	 * Constructor with Threadpool size property.
	 */
	public JerseyHttpClient(Integer threadpoolSize) {
		ClientConfig cc = new DefaultClientConfig();
		cc.getProperties().put(ClientConfig.PROPERTY_THREADPOOL_SIZE, threadpoolSize);
		client = Client.create(cc);
	}

	@Override
	public WebResource resource(URI uri) {
		return new JerseyWebResource(client, uri);
	}

	@Override
	public AsyncWebResource asyncResource(URI uri) {
		return new JerseyAsyncWebResource(client, uri);
	}

	@Override
	public void setUserAgent(String userAgent) {
		client.addFilter(new HTTPHeaderFilter(HttpHeaders.USER_AGENT, userAgent));
	}

	@Override
	public void setTimeout(Integer interval) {
		client.setReadTimeout(interval);
	}

	protected void setClient(Client client) {
		this.client = client;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy