diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/common-http')
3 files changed, 77 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF index 942e695a71..ccb1db35c5 100644 --- a/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF @@ -8,7 +8,18 @@ Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-Description: Apache Tuscany SCA Common HTTP Bundle-SymbolicName: org.apache.tuscany.sca.common.http Bundle-DocURL: http://www.apache.org/ -Export-Package: org.apache.tuscany.sca.common.http;version="2.0.0" -Import-Package: javax.servlet.http +Export-Package: org.apache.tuscany.sca.common.http;version="2.0.0";uses:="javax.servlet.http", + org.apache.tuscany.sca.common.http.client;version="2.0.0";uses:="org.apache.http.client" +Import-Package: javax.servlet.http, + org.apache.http, + org.apache.http.client, + org.apache.http.conn, + org.apache.http.conn.scheme, + org.apache.http.conn.ssl, + org.apache.http.impl.client, + org.apache.http.impl.conn.tsccm, + org.apache.http.params, + org.apache.http.protocol +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/trunk/modules/common-http/pom.xml b/sca-java-2.x/trunk/modules/common-http/pom.xml index 2fa94a708c..4cdd7fc98d 100644 --- a/sca-java-2.x/trunk/modules/common-http/pom.xml +++ b/sca-java-2.x/trunk/modules/common-http/pom.xml @@ -35,6 +35,12 @@ <version>2.5</version> <!-- to keep compatible with older servlet containers --> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.0.3</version> + </dependency> <dependency> <groupId>junit</groupId> diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/client/HttpClientFactory.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/client/HttpClientFactory.java new file mode 100644 index 0000000000..225bc952fb --- /dev/null +++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/client/HttpClientFactory.java @@ -0,0 +1,58 @@ +/* + * 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.tuscany.sca.common.http.client; + +import org.apache.http.HttpHost; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.PlainSocketFactory; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.apache.http.protocol.HTTP; + +/** + * + */ +public class HttpClientFactory { + + public HttpClient createHttpClient() { + HttpParams defaultParameters = new BasicHttpParams(); + //defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 10); + HttpProtocolParams.setContentCharset(defaultParameters, HTTP.UTF_8); + HttpConnectionParams.setConnectionTimeout(defaultParameters, 60000); + HttpConnectionParams.setSoTimeout(defaultParameters, 60000); + + SchemeRegistry supportedSchemes = new SchemeRegistry(); + supportedSchemes.register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80)); + supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); + + ClientConnectionManager connectionManager = + new ThreadSafeClientConnManager(defaultParameters, supportedSchemes); + + return new DefaultHttpClient(connectionManager, defaultParameters); + } +} |