Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B66C445D9 for ; Mon, 6 Jun 2011 15:21:18 +0000 (UTC) Received: (qmail 43023 invoked by uid 500); 6 Jun 2011 15:21:18 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 42971 invoked by uid 500); 6 Jun 2011 15:21:18 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 42964 invoked by uid 99); 6 Jun 2011 15:21:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 15:21:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 15:21:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A43C2238896F; Mon, 6 Jun 2011 15:20:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1132667 - in /geronimo/bundles/trunk/axis2: pom.xml src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java src/main/java/org/apache/axis2/transport/http/HTTPSender.java Date: Mon, 06 Jun 2011 15:20:52 -0000 To: scm@geronimo.apache.org From: xuhaihong@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110606152052.A43C2238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: xuhaihong Date: Mon Jun 6 15:20:52 2011 New Revision: 1132667 URL: http://svn.apache.org/viewvc?rev=1132667&view=rev Log: Try the patch of AXIS2-5062 from Geronimo side, fix the connection leak while using JAXWS client API Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java (with props) Modified: geronimo/bundles/trunk/axis2/pom.xml geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Modified: geronimo/bundles/trunk/axis2/pom.xml URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/pom.xml?rev=1132667&r1=1132666&r2=1132667&view=diff ============================================================================== --- geronimo/bundles/trunk/axis2/pom.xml (original) +++ geronimo/bundles/trunk/axis2/pom.xml Mon Jun 6 15:20:52 2011 @@ -310,6 +310,7 @@ org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$5.class=target/classes/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$5.class, org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$6.class=target/classes/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$6.class, org/apache/axis2/transport/http/AbstractHTTPSender.class=target/classes/org/apache/axis2/transport/http/AbstractHTTPSender.class, + org/apache/axis2/transport/http/HTTPSender.class=target/classes/org/apache/axis2/transport/http/HTTPSender.class, org/apache/axis2/client/OperationClient.class=target/classes/org/apache/axis2/client/OperationClient.class, org/apache/axis2/jaxws/description/impl/PostRI216MethodRetrieverImpl.class=target/classes/org/apache/axis2/jaxws/description/impl/PostRI216MethodRetrieverImpl.class, org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class=target/classes/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class Modified: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?rev=1132667&r1=1132666&r2=1132667&view=diff ============================================================================== --- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java (original) +++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Mon Jun 6 15:20:52 2011 @@ -373,26 +373,36 @@ public class JAXWSProxyHandler extends B } if (!operationDesc.isOneWay()) { - InvocationContext responseIC = controller.invoke(requestIC); + try { + InvocationContext responseIC = controller.invoke(requestIC); - //Check to see if we need to maintain session state - checkMaintainSessionState(request, requestIC); + //Check to see if we need to maintain session state + checkMaintainSessionState(request, requestIC); - MessageContext responseContext = responseIC.getResponseMessageContext(); - - // Migrate the properties from the response MessageContext back - // to the client response context bag. - ApplicationContextMigratorUtil.performMigrationFromMessageContext( - Constants.APPLICATION_CONTEXT_MIGRATOR_LIST_ID, - getResponseContext(), responseContext); - - Object responseObj = createResponse(method, args, responseContext, operationDesc); + MessageContext responseContext = responseIC.getResponseMessageContext(); - if (log.isDebugEnabled()) { - log.debug("Exiting the method invokeSEIMethod() - Sync"); + // Migrate the properties from the response MessageContext back + // to the client response context bag. + ApplicationContextMigratorUtil.performMigrationFromMessageContext(Constants.APPLICATION_CONTEXT_MIGRATOR_LIST_ID, getResponseContext(), responseContext); + + Object responseObj = createResponse(method, args, responseContext, operationDesc); + + if (log.isDebugEnabled()) { + log.debug("Exiting the method invokeSEIMethod() - Sync"); + } + + return responseObj; + } finally { + try { + if (request != null && request.getAxisMessageContext() != null) { + org.apache.axis2.context.MessageContext axisMsgCtx = request.getAxisMessageContext(); + if (axisMsgCtx.getTransportOut() != null && axisMsgCtx.getTransportOut().getSender() != null) { + axisMsgCtx.getTransportOut().getSender().cleanup(axisMsgCtx); + } + } + } catch (Exception ignore) { + } } - - return responseObj; } if (log.isDebugEnabled()) { Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java?rev=1132667&view=auto ============================================================================== --- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java (added) +++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java Mon Jun 6 15:20:52 2011 @@ -0,0 +1,314 @@ +/* + * 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.axis2.transport.http; + + +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.OperationContext; +import org.apache.axis2.i18n.Messages; +import org.apache.axis2.transport.MessageFormatter; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.IOException; +import java.net.URL; + +public class HTTPSender extends AbstractHTTPSender { + + private static final Log log = LogFactory.getLog(HTTPSender.class); + + public void send(MessageContext msgContext, URL url, String soapActionString) + throws IOException { + + // execute the HtttpMethodBase - a connection manager can be given for + // handle multiple + + String httpMethod = + (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD); + + if ((httpMethod != null)) { + + if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) { + this.sendViaGet(msgContext, url, soapActionString); + + return; + } else if (Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) { + this.sendViaDelete(msgContext, url, soapActionString); + + return; + } else if (Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) { + this.sendViaPut(msgContext, url, soapActionString); + + return; + } + } + + this.sendViaPost(msgContext, url, soapActionString); + } + + /** + * Used to send a request via HTTP Get method + * + * @param msgContext - The MessageContext of the message + * @param url - The target URL + * @param soapActiionString - The soapAction string of the request + * @throws AxisFault - Thrown in case an exception occurs + */ + private void sendViaGet(MessageContext msgContext, URL url, String soapActiionString) + throws AxisFault { + + GetMethod getMethod = new GetMethod(); + HttpClient httpClient = getHttpClient(msgContext); + MessageFormatter messageFormatter = + populateCommonProperties(msgContext, url, getMethod, httpClient, soapActiionString); + + // Need to have this here because we can have soap action when using the soap response MEP + String soapAction = + messageFormatter.formatSOAPAction(msgContext, format, soapActiionString); + + if (soapAction != null) { + getMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction); + } + try { + executeMethod(httpClient, msgContext, url, getMethod); + handleResponse(msgContext, getMethod); + } catch (IOException e) { + log.info("Unable to sendViaGet to url[" + url + "]", e); + throw AxisFault.makeFault(e); + } finally { + cleanup(msgContext, getMethod); + } + } + + private void cleanup(MessageContext msgContext, HttpMethod method) { + if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) { + log.trace("AutoReleasing " + method); + method.releaseConnection(); + } + } + + /** + * Used to send a request via HTTP Delete Method + * + * @param msgContext - The MessageContext of the message + * @param url - The target URL + * @param soapActiionString - The soapAction string of the request + * @throws AxisFault - Thrown in case an exception occurs + */ + private void sendViaDelete(MessageContext msgContext, URL url, String soapActiionString) + throws AxisFault { + + DeleteMethod deleteMethod = new DeleteMethod(); + HttpClient httpClient = getHttpClient(msgContext); + populateCommonProperties(msgContext, url, deleteMethod, httpClient, soapActiionString); + + try { + executeMethod(httpClient, msgContext, url, deleteMethod); + handleResponse(msgContext, deleteMethod); + } catch (IOException e) { + log.info("Unable to sendViaDelete to url[" + url + "]", e); + throw AxisFault.makeFault(e); + } finally { + cleanup(msgContext, deleteMethod); + } + } + + /** + * Used to send a request via HTTP Post Method + * + * @param msgContext - The MessageContext of the message + * @param url - The target URL + * @param soapActionString - The soapAction string of the request + * @throws AxisFault - Thrown in case an exception occurs + */ + private void sendViaPost(MessageContext msgContext, URL url, + String soapActionString) throws AxisFault { + + + HttpClient httpClient = getHttpClient(msgContext); + +/* What's up with this, it never gets used anywhere?? --Glen + String charEncoding = + (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); + + if (charEncoding == null) { + charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING; + } +*/ + + PostMethod postMethod = new PostMethod(); + if (log.isTraceEnabled()) { + log.trace(Thread.currentThread() + " PostMethod " + postMethod + " / " + httpClient); + } + MessageFormatter messageFormatter = + populateCommonProperties(msgContext, url, postMethod, httpClient, soapActionString); + + postMethod.setRequestEntity(new AxisRequestEntity(messageFormatter, + msgContext, format, soapActionString, + chunked, isAllowedRetry)); + + if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) { + postMethod.setContentChunked(true); + } + + String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString); + + if (soapAction != null) { + postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction); + } + + /* + * main excecution takes place.. + */ + try { + executeMethod(httpClient, msgContext, url, postMethod); + handleResponse(msgContext, postMethod); + } catch (IOException e) { + log.info("Unable to sendViaPost to url[" + url + "]", e); + throw AxisFault.makeFault(e); + } finally { + cleanup(msgContext, postMethod); + } + } + + /** + * Used to send a request via HTTP Put Method + * + * @param msgContext - The MessageContext of the message + * @param url - The target URL + * @param soapActionString - The soapAction string of the request + * @throws AxisFault - Thrown in case an exception occurs + */ + private void sendViaPut(MessageContext msgContext, URL url, + String soapActionString) throws AxisFault { + + + HttpClient httpClient = getHttpClient(msgContext); + +/* Same deal - this value never gets used, why is it here? --Glen + String charEncoding = + (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); + + if (charEncoding == null) { + charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING; + } +*/ + + PutMethod putMethod = new PutMethod(); + MessageFormatter messageFormatter = + populateCommonProperties(msgContext, url, putMethod, httpClient, soapActionString); + + putMethod.setRequestEntity(new AxisRequestEntity(messageFormatter, + msgContext, format, soapActionString, + chunked, isAllowedRetry)); + + if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) { + putMethod.setContentChunked(true); + } + + String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString); + if (soapAction != null) { + putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction); + } + + /* + * main excecution takes place.. + */ + try { + executeMethod(httpClient, msgContext, url, putMethod); + handleResponse(msgContext, putMethod); + } catch (IOException e) { + log.info("Unable to sendViaPut to url[" + url + "]", e); + throw AxisFault.makeFault(e); + } finally { + cleanup(msgContext, putMethod); + } + } + + /** + * Used to handle the HTTP Response + * + * @param msgContext - The MessageContext of the message + * @param method - The HTTP method used + * @throws IOException - Thrown in case an exception occurs + */ + private void handleResponse(MessageContext msgContext, + HttpMethodBase method) throws IOException { + int statusCode = method.getStatusCode(); + log.trace("Handling response - " + statusCode); + if (statusCode == HttpStatus.SC_OK) { + // Save the HttpMethod so that we can release the connection when cleaning up + msgContext.setProperty(HTTPConstants.HTTP_METHOD, method); + processResponse(method, msgContext); + } else if (statusCode == HttpStatus.SC_ACCEPTED) { + /* When an HTTP 202 Accepted code has been received, this will be the case of an execution + * of an in-only operation. In such a scenario, the HTTP response headers should be returned, + * i.e. session cookies. */ + obtainHTTPHeaderInformation(method, msgContext); + // Since we don't expect any content with a 202 response, we must release the connection + method.releaseConnection(); + } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR || + statusCode == HttpStatus.SC_BAD_REQUEST) { + // Save the HttpMethod so that we can release the connection when cleaning up + msgContext.setProperty(HTTPConstants.HTTP_METHOD, method); + Header contenttypeHeader = + method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE); + String value = null; + if (contenttypeHeader != null) { + value = contenttypeHeader.getValue(); + } + OperationContext opContext = msgContext.getOperationContext(); + if(opContext!=null){ + MessageContext inMessageContext = + opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + if(inMessageContext!=null){ + inMessageContext.setProcessingFault(true); + } + } + if (value != null) { + + processResponse(method, msgContext); + } + + if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) { + throw new AxisFault(Messages.getMessage("transportError", + String.valueOf(statusCode), + method.getStatusText())); + } + } else { + msgContext.setProperty(HTTPConstants.HTTP_METHOD, method); + throw new AxisFault(Messages.getMessage("transportError", + String.valueOf(statusCode), + method.getStatusText())); + } + } +} Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/transport/http/HTTPSender.java ------------------------------------------------------------------------------ svn:mime-type = text/plain