diff options
Diffstat (limited to 'java/sca/modules')
3 files changed, 44 insertions, 25 deletions
diff --git a/java/sca/modules/binding-jsonrpc-runtime/pom.xml b/java/sca/modules/binding-jsonrpc-runtime/pom.xml index f80a21101f..b599945b75 100644 --- a/java/sca/modules/binding-jsonrpc-runtime/pom.xml +++ b/java/sca/modules/binding-jsonrpc-runtime/pom.xml @@ -67,9 +67,9 @@ </dependency> <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1</version> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.0</version> </dependency> <dependency> diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java index 12f69dffc7..f3abf82520 100644 --- a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java +++ b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java @@ -19,9 +19,12 @@ package org.apache.tuscany.sca.binding.jsonrpc.provider; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.util.EntityUtils; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; import org.apache.tuscany.sca.interfacedef.Operation; @@ -52,7 +55,8 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { } public Message invoke(Message msg) { - PostMethod post = null; + HttpPost post = null; + HttpResponse response = null; try { JSONObject jsonRequest = null;; @@ -76,19 +80,19 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { throw new RuntimeException("Unable to parse JSON parameter", e); } - post = new PostMethod(uri); + post = new HttpPost(uri); String req = jsonRequest.toString(); - StringRequestEntity entity = new StringRequestEntity(req, "application/json", "UTF-8"); - post.setRequestEntity(entity); + StringEntity entity = new StringEntity(req, "application/json; charset\"UTF-8\""); + post.setEntity(entity); - httpClient.executeMethod(post); - int status = post.getStatusCode(); + response = httpClient.execute(post); - if (status == 200) { + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //success JSONObject jsonResponse = null; try { - jsonResponse = new JSONObject(post.getResponseBodyAsString()); + + jsonResponse = new JSONObject(EntityUtils.toString(response.getEntity())); //check requestId if (! jsonResponse.getString("id").equalsIgnoreCase(requestId)) { @@ -106,10 +110,6 @@ public class JSONRPCBindingInvoker implements Invoker, DataExchangeSemantics { } catch (Exception e) { e.printStackTrace(); msg.setFaultBody(e); - } finally { - if (post != null) { - post.releaseConnection(); - } } return msg; diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java index 8950d6c8ac..2a23ff4960 100644 --- a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java +++ b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java @@ -19,9 +19,20 @@ package org.apache.tuscany.sca.binding.jsonrpc.provider; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpConnectionManager; -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +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.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; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; @@ -57,10 +68,18 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider JSONRPCDatabindingHelper.setDataBinding(referenceContract.getInterface()); // Create an HTTP client - HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); - connectionManager.getParams().setDefaultMaxConnectionsPerHost(10); - connectionManager.getParams().setConnectionTimeout(60000); - httpClient = new HttpClient(connectionManager); + 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)); + + ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(defaultParameters, supportedSchemes); + + httpClient = new DefaultHttpClient(connectionManager, defaultParameters); } public InterfaceContract getBindingInterfaceContract() { |