Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java Sun Dec 17 22:34:08 2017 @@ -20,78 +20,92 @@ package org.apache.axis2.transport.http; +import org.apache.axiom.mime.ContentType; +import org.apache.axiom.mime.Header; +import org.apache.axiom.om.OMAttribute; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMOutputFormat; import org.apache.axis2.AxisFault; import org.apache.axis2.Constants; import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.NamedValue; +import org.apache.axis2.context.OperationContext; +import org.apache.axis2.description.TransportOutDescription; +import org.apache.axis2.i18n.Messages; +import org.apache.axis2.transport.MessageFormatter; +import org.apache.axis2.util.MessageProcessorSelector; +import org.apache.axis2.util.Utils; +import org.apache.axis2.wsdl.WSDLConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpStatus; +import org.apache.http.protocol.HTTP; import java.io.IOException; +import java.io.InputStream; import java.net.URL; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.GZIPInputStream; + +import javax.xml.namespace.QName; //TODO - It better if we can define these method in a interface move these into AbstractHTTPSender and get rid of this class. -public abstract class HTTPSender extends AbstractHTTPSender { +public abstract class HTTPSender { private static final Log log = LogFactory.getLog(HTTPSender.class); - /** - * 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 - */ - protected abstract void sendViaGet(MessageContext msgContext, URL url, String soapActiionString) - throws AxisFault; - /** - * 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 - */ - protected abstract void sendViaDelete(MessageContext msgContext, URL url, String soapActiionString) - throws AxisFault; - /** - * 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 - */ - protected abstract void sendViaPost(MessageContext msgContext, URL url, - String soapActionString) throws AxisFault; + private boolean chunked = false; + private String httpVersion = HTTPConstants.HEADER_PROTOCOL_11; + protected TransportOutDescription proxyOutSetting = null; + protected OMOutputFormat format = new OMOutputFormat(); + + public void setChunked(boolean chunked) { + this.chunked = chunked; + } + public void setHttpVersion(String version) throws AxisFault { + if (version != null) { + if (HTTPConstants.HEADER_PROTOCOL_11.equals(version)) { + this.httpVersion = HTTPConstants.HEADER_PROTOCOL_11; + } else if (HTTPConstants.HEADER_PROTOCOL_10.equals(version)) { + this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10; + // chunked is not possible with HTTP/1.0 + this.chunked = false; + } else { + throw new AxisFault( + "Parameter " + HTTPConstants.PROTOCOL_VERSION + + " Can have values only HTTP/1.0 or HTTP/1.1"); + } + } + } - /** - * 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 - */ - protected abstract void sendViaPut(MessageContext msgContext, URL url, - String soapActionString) throws AxisFault; + public void setFormat(OMOutputFormat format) { + this.format = format; + } - /** - * Used to handle the HTTP Response + * Start a new HTTP request. * - * @param msgContext - The MessageContext of the message - * @param method - The HTTP method used - * @throws IOException - Thrown in case an exception occurs + * @param msgContext + * The MessageContext of the request message + * @param methodName + * The HTTP method name + * @param url + * The target URL + * @param requestEntity + * The content of the request or {@code null} if the HTTP request shouldn't have any + * content (e.g. for {@code GET} requests) + * @throws AxisFault + * Thrown in case an exception occurs */ - protected abstract void handleResponse(MessageContext msgContext, - Object httpMethodBase) throws IOException; - - protected abstract void cleanup(MessageContext msgContext, Object httpMethod); + protected abstract Request createRequest(MessageContext msgContext, String methodName, URL url, + AxisRequestEntity requestEntity) throws AxisFault; - - public void send(MessageContext msgContext, URL url, String soapActionString) throws IOException { @@ -100,55 +114,373 @@ public abstract class HTTPSender extends String httpMethod = (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD); + if (httpMethod == null) { + httpMethod = Constants.Configuration.HTTP_METHOD_POST; + } - if ((httpMethod != null)) { - - if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) { - this.sendViaGet(msgContext, url, soapActionString); + MessageFormatter messageFormatter = MessageProcessorSelector + .getMessageFormatter(msgContext); + url = messageFormatter.getTargetAddress(msgContext, format, url); + String contentType = messageFormatter.getContentType(msgContext, format, soapActionString); + + HTTPAuthenticator authenticator; + Object obj = msgContext.getProperty(HTTPConstants.AUTHENTICATE); + if (obj == null) { + authenticator = null; + } else { + if (obj instanceof HTTPAuthenticator) { + authenticator = (HTTPAuthenticator) obj; + } else { + throw new AxisFault("HttpTransportProperties.Authenticator class cast exception"); + } + } - return; - } else if (Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) { - this.sendViaDelete(msgContext, url, soapActionString); + AxisRequestEntity requestEntity; + boolean gzip; + if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod) + || Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) { + requestEntity = null; + gzip = false; + } else if (Constants.Configuration.HTTP_METHOD_POST.equalsIgnoreCase(httpMethod) + || Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) { + gzip = msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST); + requestEntity = new AxisRequestEntity(messageFormatter, msgContext, format, + contentType, chunked, gzip, authenticator != null && authenticator.isAllowedRetry()); + } else { + throw new AxisFault("Unsupported HTTP method " + httpMethod); + } - return; - } else if (Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) { - this.sendViaPut(msgContext, url, soapActionString); + Request request = createRequest(msgContext, httpMethod, url, requestEntity); - return; + if (msgContext.getOptions() != null && msgContext.getOptions().isManageSession()) { + // setting the cookie in the out path + Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING); + + if (cookieString != null) { + StringBuffer buffer = new StringBuffer(); + buffer.append(cookieString); + request.setHeader(HTTPConstants.HEADER_COOKIE, buffer.toString()); } } - this.sendViaPost(msgContext, url, soapActionString); + if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) { + request.enableHTTP10(); + } + + request.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType); + + String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString); + + if (soapAction != null && !msgContext.isDoingREST()) { + request.setHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction); + } + + if (gzip) { + request.setHeader(HTTPConstants.HEADER_CONTENT_ENCODING, + HTTPConstants.COMPRESSION_GZIP); + } + + // set the custom headers, if available + addCustomHeaders(msgContext, request); + + if (authenticator != null) { + request.enableAuthentication(authenticator); + } + + setTimeouts(msgContext, request); + + try { + request.execute(); + boolean cleanup = true; + try { + int statusCode = request.getStatusCode(); + log.trace("Handling response - " + statusCode); + boolean processResponse; + boolean fault; + if (statusCode == HttpStatus.SC_ACCEPTED) { + processResponse = false; + fault = false; + } else if (statusCode >= 200 && statusCode < 300) { + processResponse = true; + fault = false; + } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR + || statusCode == HttpStatus.SC_BAD_REQUEST) { + processResponse = true; + fault = true; + } else { + throw new AxisFault(Messages.getMessage("transportError", String.valueOf(statusCode), + request.getStatusText())); + } + obtainHTTPHeaderInformation(request, msgContext); + if (processResponse) { + OperationContext opContext = msgContext.getOperationContext(); + MessageContext inMessageContext = opContext == null ? null + : opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + if (opContext != null) { + InputStream in = request.getResponseContent(); + if (in != null) { + String contentEncoding = request.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING); + if (contentEncoding != null) { + if (contentEncoding.equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) { + in = new GZIPInputStream(in); + // If the content-encoding is identity we can basically ignore + // it. + } else if (!"identity".equalsIgnoreCase(contentEncoding)) { + throw new AxisFault("HTTP :" + "unsupported content-encoding of '" + + contentEncoding + "' found"); + } + } + opContext.setProperty(MessageContext.TRANSPORT_IN, in); + // This implements the behavior of the HTTPClient 3.x based transport in + // Axis2 1.7: if AUTO_RELEASE_CONNECTION is enabled, we set the input stream + // in the message context, but we nevertheless release the connection. + // It is unclear in which situation this would actually be the right thing + // to do. + if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) { + log.debug("AUTO_RELEASE_CONNECTION enabled; are you sure that you really want that?"); + } else { + cleanup = false; + } + } + } + if (fault) { + if (inMessageContext != null) { + inMessageContext.setProcessingFault(true); + } + if (Utils.isClientThreadNonBlockingPropertySet(msgContext)) { + throw new AxisFault(Messages. + getMessage("transportError", + String.valueOf(statusCode), + request.getStatusText())); + } + } + } + } finally { + if (cleanup) { + request.releaseConnection(); + } + } + } catch (IOException e) { + log.info("Unable to send to url[" + url + "]", e); + throw AxisFault.makeFault(e); + } } + private void addCustomHeaders(MessageContext msgContext, Request request) { + + boolean isCustomUserAgentSet = false; + // set the custom headers, if available + Object httpHeadersObj = msgContext.getProperty(HTTPConstants.HTTP_HEADERS); + if (httpHeadersObj != null) { + if (httpHeadersObj instanceof List) { + List httpHeaders = (List) httpHeadersObj; + for (int i = 0; i < httpHeaders.size(); i++) { + NamedValue nv = (NamedValue) httpHeaders.get(i); + if (nv != null) { + if (HTTPConstants.HEADER_USER_AGENT.equals(nv.getName())) { + isCustomUserAgentSet = true; + } + request.addHeader(nv.getName(), nv.getValue()); + } + } + + } + if (httpHeadersObj instanceof Map) { + Map httpHeaders = (Map) httpHeadersObj; + for (Iterator iterator = httpHeaders.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = (Map.Entry) iterator.next(); + String key = (String) entry.getKey(); + String value = (String) entry.getValue(); + if (HTTPConstants.HEADER_USER_AGENT.equals(key)) { + isCustomUserAgentSet = true; + } + request.addHeader(key, value); + } + } + } + + // we have to consider the TRANSPORT_HEADERS map as well + Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); + if (transportHeaders != null) { + removeUnwantedHeaders(msgContext); + + Set headerEntries = transportHeaders.entrySet(); + + for (Object headerEntry : headerEntries) { + if (headerEntry instanceof Map.Entry) { + Header[] headers = request.getRequestHeaders(); + + boolean headerAdded = false; + for (Header header : headers) { + if (header.getName() != null + && header.getName().equals(((Map.Entry) headerEntry).getKey())) { + headerAdded = true; + break; + } + } + + if (!headerAdded) { + request.addHeader(((Map.Entry) headerEntry).getKey().toString(), + ((Map.Entry) headerEntry).getValue().toString()); + } + } + } + } + + if (!isCustomUserAgentSet) { + String userAgentString = getUserAgent(msgContext); + request.setHeader(HTTPConstants.HEADER_USER_AGENT, userAgentString); + } + + } + /** - * Used to determine the family of HTTP status codes to which the given code - * belongs. + * Remove unwanted headers from the transport headers map of outgoing + * request. These are headers which should be dictated by the transport and + * not the user. We remove these as these may get copied from the request + * messages * - * @param statusCode - * - The HTTP status code + * @param msgContext + * the Axis2 Message context from which these headers should be + * removed */ - protected HTTPStatusCodeFamily getHTTPStatusCodeFamily(int statusCode) { - switch (statusCode / 100) { - case 1: - return HTTPStatusCodeFamily.INFORMATIONAL; - case 2: - return HTTPStatusCodeFamily.SUCCESSFUL; - case 3: - return HTTPStatusCodeFamily.REDIRECTION; - case 4: - return HTTPStatusCodeFamily.CLIENT_ERROR; - case 5: - return HTTPStatusCodeFamily.SERVER_ERROR; - default: - return HTTPStatusCodeFamily.OTHER; + private void removeUnwantedHeaders(MessageContext msgContext) { + Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS); + + if (headers == null || headers.isEmpty()) { + return; + } + + Iterator iter = headers.keySet().iterator(); + while (iter.hasNext()) { + String headerName = (String) iter.next(); + if (HTTP.CONN_DIRECTIVE.equalsIgnoreCase(headerName) + || HTTP.TRANSFER_ENCODING.equalsIgnoreCase(headerName) + || HTTP.DATE_HEADER.equalsIgnoreCase(headerName) + || HTTP.CONTENT_TYPE.equalsIgnoreCase(headerName) + || HTTP.CONTENT_LEN.equalsIgnoreCase(headerName)) { + iter.remove(); + } } } + + private String getUserAgent(MessageContext messageContext) { + String userAgentString = "Axis2"; + boolean locked = false; + if (messageContext.getParameter(HTTPConstants.USER_AGENT) != null) { + OMElement userAgentElement = messageContext.getParameter(HTTPConstants.USER_AGENT) + .getParameterElement(); + userAgentString = userAgentElement.getText().trim(); + OMAttribute lockedAttribute = userAgentElement.getAttribute(new QName("locked")); + if (lockedAttribute != null) { + if (lockedAttribute.getAttributeValue().equalsIgnoreCase("true")) { + locked = true; + } + } + } + // Runtime overing part + if (!locked) { + if (messageContext.getProperty(HTTPConstants.USER_AGENT) != null) { + userAgentString = (String) messageContext.getProperty(HTTPConstants.USER_AGENT); + } + } + + return userAgentString; + } + /** - * The set of HTTP status code families. + * This is used to get the dynamically set time out values from the message + * context. If the values are not available or invalid then the default + * values or the values set by the configuration will be used + * + * @param msgContext + * the active MessageContext + * @param request + * request */ - protected enum HTTPStatusCodeFamily { - INFORMATIONAL, SUCCESSFUL, REDIRECTION, CLIENT_ERROR, SERVER_ERROR, OTHER + private void setTimeouts(MessageContext msgContext, Request request) { + // If the SO_TIMEOUT of CONNECTION_TIMEOUT is set by dynamically the + // override the static config + Integer tempSoTimeoutProperty = (Integer) msgContext.getProperty(HTTPConstants.SO_TIMEOUT); + Integer tempConnTimeoutProperty = (Integer) msgContext + .getProperty(HTTPConstants.CONNECTION_TIMEOUT); + long timeout = msgContext.getOptions().getTimeOutInMilliSeconds(); + + if (tempConnTimeoutProperty != null) { + // timeout for initial connection + request.setConnectionTimeout(tempConnTimeoutProperty); + } + + if (tempSoTimeoutProperty != null) { + // SO_TIMEOUT -- timeout for blocking reads + request.setSocketTimeout(tempSoTimeoutProperty); + } else { + // set timeout in client + if (timeout > 0) { + request.setSocketTimeout((int) timeout); + } + } + } + + private void obtainHTTPHeaderInformation(Request request, MessageContext msgContext) throws AxisFault { + // Set RESPONSE properties onto the REQUEST message context. They will + // need to be copied off the request context onto + // the response context elsewhere, for example in the + // OutInOperationClient. + msgContext.setProperty( + MessageContext.TRANSPORT_HEADERS, + new CommonsTransportHeaders(request.getResponseHeaders())); + msgContext.setProperty( + HTTPConstants.MC_HTTP_STATUS_CODE, + new Integer(request.getStatusCode())); + + String contentTypeString = request.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE); + if (contentTypeString != null) { + ContentType contentType; + try { + contentType = new ContentType(contentTypeString); + } catch (ParseException ex) { + throw AxisFault.makeFault(ex); + } + String charSetEnc = contentType.getParameter(HTTPConstants.CHAR_SET_ENCODING); + MessageContext inMessageContext = msgContext.getOperationContext().getMessageContext( + WSDLConstants.MESSAGE_LABEL_IN_VALUE); + if (inMessageContext != null) { + inMessageContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentTypeString); + inMessageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc); + } else { + // Transport details will be stored in a HashMap so that anybody + // interested can + // retrieve them + Map<String,String> transportInfoMap = new HashMap<String,String>(); + transportInfoMap.put(Constants.Configuration.CONTENT_TYPE, contentTypeString); + transportInfoMap.put(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc); + // the HashMap is stored in the outgoing message. + msgContext.setProperty(Constants.Configuration.TRANSPORT_INFO_MAP, transportInfoMap); + } + } + + Map<String,String> cookies = request.getCookies(); + if (cookies != null) { + String customCookieId = (String) msgContext.getProperty(Constants.CUSTOM_COOKIE_ID); + String cookieString = null; + if (customCookieId != null) { + cookieString = buildCookieString(cookies, customCookieId); + } + if (cookieString == null) { + cookieString = buildCookieString(cookies, Constants.SESSION_COOKIE); + } + if (cookieString == null) { + cookieString = buildCookieString(cookies, Constants.SESSION_COOKIE_JSESSIONID); + } + if (cookieString != null) { + msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, cookieString); + } + } } + private String buildCookieString(Map<String,String> cookies, String name) { + String value = cookies.get(name); + return value == null ? null : name + "=" + value; + } }
Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Sun Dec 17 22:34:08 2017 @@ -54,6 +54,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.SocketException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Iterator; import java.util.Map; import java.util.zip.GZIPInputStream; @@ -382,4 +384,20 @@ public class HTTPTransportUtils { epr.append('/'); return new EndpointReference[]{new EndpointReference(epr.toString())}; } + + static InputStream getMetaInfResourceAsStream(AxisService service, String name) { + ClassLoader classLoader = service.getClassLoader(); + if (classLoader instanceof URLClassLoader) { + // Only search the service class loader and skip searching the ancestors to + // avoid local file inclusion vulnerabilities such as AXIS2-5846. + URL url = ((URLClassLoader)classLoader).findResource("META-INF/" + name); + try { + return url == null ? null : url.openStream(); + } catch (IOException ex) { + return null; + } + } else { + return null; + } + } } Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/HTTPWorker.java Sun Dec 17 22:34:08 2017 @@ -22,7 +22,6 @@ package org.apache.axis2.transport.http; import org.apache.axis2.Constants; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; -import org.apache.axis2.deployment.DeploymentConstants; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; import org.apache.axis2.engine.Handler.InvocationResponse; @@ -100,8 +99,7 @@ public class HTTPWorker implements Worke Iterator i = services.values().iterator(); while (i.hasNext()) { AxisService service = (AxisService) i.next(); - InputStream stream = service.getClassLoader(). - getResourceAsStream("META-INF/" + file); + InputStream stream = HTTPTransportUtils.getMetaInfResourceAsStream(service, file); if (stream != null) { OutputStream out = response.getOutputStream(); response.setContentType("text/xml"); @@ -205,8 +203,7 @@ public class HTTPWorker implements Worke schema.write(response.getOutputStream()); return; } else { - InputStream instream = service.getClassLoader() - .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName); + InputStream instream = HTTPTransportUtils.getMetaInfResourceAsStream(service, schemaName); if (instream != null) { response.setStatus(HttpStatus.SC_OK); Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/ListingAgent.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/ListingAgent.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/ListingAgent.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/ListingAgent.java Sun Dec 17 22:34:08 2017 @@ -58,8 +58,6 @@ public class ListingAgent extends Abstra private static final String LIST_MULTIPLE_SERVICE_JSP_NAME = "listServices.jsp"; - private static final String LIST_SINGLE_SERVICE_JSP_NAME = - "listSingleService.jsp"; private static final String LIST_FAULTY_SERVICES_JSP_NAME = "listFaultyService.jsp"; public ListingAgent(ConfigurationContext aConfigContext) { @@ -69,7 +67,7 @@ public class ListingAgent extends Abstra public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { - + httpServletRequest = new ForbidSessionCreationWrapper(httpServletRequest); String query = httpServletRequest.getQueryString(); if (query != null) { if (HttpUtils.indexOfIngnoreCase(query , "wsdl2") > 0 || HttpUtils.indexOfIngnoreCase(query, "wsdl") > 0 || @@ -88,7 +86,7 @@ public class ListingAgent extends Abstra String serviceName = req.getParameter("serviceName"); if (serviceName != null) { AxisService service = configContext.getAxisConfiguration().getService(serviceName); - req.getSession().setAttribute(Constants.SINGLE_SERVICE, service); + req.setAttribute(Constants.SINGLE_SERVICE, service); } renderView(LIST_FAULTY_SERVICES_JSP_NAME, req, res); } @@ -127,7 +125,7 @@ public class ListingAgent extends Abstra Iterator<AxisService> i = services.values().iterator(); while (i.hasNext()) { AxisService service = (AxisService) i.next(); - InputStream stream = service.getClassLoader().getResourceAsStream("META-INF/" + schema); + InputStream stream = HTTPTransportUtils.getMetaInfResourceAsStream(service, schema); if (stream != null) { OutputStream out = res.getOutputStream(); res.setContentType("text/xml"); @@ -192,16 +190,10 @@ public class ListingAgent extends Abstra } else if (policy >= 0) { handlePolicyRequest(req, res, serviceName, axisService); return; - } else { - req.getSession().setAttribute(Constants.SINGLE_SERVICE, axisService); } - } else { - req.getSession().setAttribute(Constants.SINGLE_SERVICE, null); - res.sendError(HttpServletResponse.SC_NOT_FOUND, url); } } - - renderView(LIST_SINGLE_SERVICE_JSP_NAME, req, res); + res.sendError(HttpServletResponse.SC_NOT_FOUND, url); } private void handlePolicyRequest(HttpServletRequest req, @@ -248,12 +240,7 @@ public class ListingAgent extends Abstra } } else { - - OutputStream out = res.getOutputStream(); - res.setContentType("text/html"); - String outStr = "<b>No policy found for id=" - + idParam + "</b>"; - out.write(outStr.getBytes()); + res.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { @@ -284,12 +271,7 @@ public class ListingAgent extends Abstra e); } } else { - - OutputStream out = res.getOutputStream(); - res.setContentType("text/html"); - String outStr = "<b>No effective policy for " - + serviceName + " service</b>"; - out.write(outStr.getBytes()); + res.sendError(HttpServletResponse.SC_NOT_FOUND); } } } @@ -387,9 +369,9 @@ public class ListingAgent extends Abstra if(listServiceDisabled()){ return; } - populateSessionInformation(req); - req.getSession().setAttribute(Constants.ERROR_SERVICE_MAP, - configContext.getAxisConfiguration().getFaultyServices()); + populateRequestAttributes(req); + req.setAttribute(Constants.ERROR_SERVICE_MAP, + configContext.getAxisConfiguration().getFaultyServices()); renderView(LIST_MULTIPLE_SERVICE_JSP_NAME, req, res); } Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/AxisRequestEntityImpl.java Sun Dec 17 22:34:08 2017 @@ -19,9 +19,6 @@ package org.apache.axis2.transport.http.impl.httpclient4; -import org.apache.axiom.om.OMOutputFormat; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.transport.MessageFormatter; import org.apache.axis2.transport.http.AxisRequestEntity; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.http.Header; @@ -36,46 +33,57 @@ import java.io.OutputStream; * This Request Entity is used by the HttpComponentsTransportSender. This wraps the * Axis2 message formatter object. */ -public class AxisRequestEntityImpl extends AxisRequestEntity implements HttpEntity { +public class AxisRequestEntityImpl implements HttpEntity { + private final AxisRequestEntity entity; - /** - * Method calls to this request entity are delegated to the following Axis2 - * message formatter object. - * - * @param messageFormatter - * @param msgContext - * @param format - * @param soapAction - * @param chunked - * @param isAllowedRetry - */ - public AxisRequestEntityImpl(MessageFormatter messageFormatter, MessageContext msgContext, - OMOutputFormat format, String soapAction, boolean chunked, boolean isAllowedRetry) { - super(messageFormatter, msgContext, format, soapAction, chunked, isAllowedRetry); + public AxisRequestEntityImpl(AxisRequestEntity entity) { + this.entity = entity; } + @Override public Header getContentType() { - return new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, getContentTypeAsString()); + return new BasicHeader(HTTPConstants.HEADER_CONTENT_TYPE, entity.getContentType()); } + @Override public Header getContentEncoding() { return null; } + @Override public InputStream getContent() throws IOException { - return getRequestEntityContent(); + // Implementations are allowed to throw UnsupportedOperationException and this method is + // never called for outgoing requests anyway. + throw new UnsupportedOperationException(); } + @Override public void writeTo(OutputStream outputStream) throws IOException { - writeRequest(outputStream); + entity.writeRequest(outputStream); } + @Override public boolean isStreaming() { return false; } + @Override public void consumeContent() { - // TODO: Handle this correctly + // We don't need to do anything here. } + @Override + public long getContentLength() { + return entity.getContentLength(); + } + + @Override + public boolean isChunked() { + return entity.isChunked(); + } + + @Override + public boolean isRepeatable() { + return entity.isRepeatable(); + } } Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPClient4TransportSender.java Sun Dec 17 22:34:08 2017 @@ -19,31 +19,43 @@ package org.apache.axis2.transport.http.impl.httpclient4; +import java.io.IOException; +import java.io.InputStream; + import org.apache.axis2.AxisFault; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; -import org.apache.axis2.transport.http.AbstractHTTPSender; -import org.apache.axis2.transport.http.CommonsHTTPTransportSender; +import org.apache.axis2.context.OperationContext; +import org.apache.axis2.transport.http.AbstractHTTPTransportSender; import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.HTTPSender; import org.apache.axis2.transport.http.HTTPTransportConstants; -import org.apache.axis2.transport.http.HTTPTransportSender; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * The Class HTTPClient4TransportSender use HC HTTPClient 4.X. */ -public class HTTPClient4TransportSender extends CommonsHTTPTransportSender implements - HTTPTransportSender { +public class HTTPClient4TransportSender extends AbstractHTTPTransportSender { private static final Log log = LogFactory.getLog(HTTPClient4TransportSender.class); @Override public void cleanup(MessageContext msgContext) throws AxisFault { - // We don't need to call cleanup here because httpclient4 releases - // the connection and cleanup automatically - // TODO : Don't do this if we're not on the right thread! Can we confirm? log.trace("cleanup() releasing connection"); + + OperationContext opContext = msgContext.getOperationContext(); + if (opContext != null) { + InputStream in = (InputStream)opContext.getProperty(MessageContext.TRANSPORT_IN); + if (in != null) { + try { + in.close(); + } catch (IOException ex) { + // Ignore + } + } + } + // guard against multiple calls msgContext.removeProperty(HTTPConstants.HTTP_METHOD); @@ -56,7 +68,7 @@ public class HTTPClient4TransportSender @Override - protected AbstractHTTPSender createHTTPSender() { + protected HTTPSender createHTTPSender() { return new HTTPSenderImpl(); } Modified: axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java?rev=1818518&r1=1818517&r2=1818518&view=diff ============================================================================== --- axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java (original) +++ axis/axis2/java/core/branches/AXIS2-4091/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java Sun Dec 17 22:34:08 2017 @@ -33,9 +33,12 @@ import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.NTCredentials; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.params.ClientPNames; -import org.apache.http.conn.params.ConnRoutePNames; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.impl.client.AbstractHttpClient; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; import javax.xml.namespace.QName; import java.net.URL; @@ -58,12 +61,14 @@ public class HTTPProxyConfigurator { * * @param messageContext * in message context for - * @param httpClient - * instance + * @param requestConfig + * the request configuration to fill in + * @param clientContext + * the HTTP client context * @throws org.apache.axis2.AxisFault * if Proxy settings are invalid */ - public static void configure(MessageContext messageContext, AbstractHttpClient httpClient) + public static void configure(MessageContext messageContext, RequestConfig.Builder requestConfig, HttpClientContext clientContext) throws AxisFault { Credentials proxyCredentials = null; @@ -136,17 +141,21 @@ public class HTTPProxyConfigurator { } String port = System.getProperty(HTTPTransportConstants.HTTP_PROXY_PORT); - if (port != null) { + if (port != null && !port.isEmpty()) { proxyPort = Integer.parseInt(port); } if (proxyCredentials != null) { // TODO : Set preemptive authentication, but its not recommended in HC 4 - httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, true); - - httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, proxyCredentials); + requestConfig.setAuthenticationEnabled(true); + CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); + if (credsProvider == null) { + credsProvider = new BasicCredentialsProvider(); + clientContext.setCredentialsProvider(credsProvider); + } + credsProvider.setCredentials(AuthScope.ANY, proxyCredentials); HttpHost proxy = new HttpHost(proxyHost, proxyPort); - httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); + requestConfig.setProxy(proxy); } }
