001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.transport.http.util;
020:
021: import org.apache.axiom.om.OMElement;
022: import org.apache.axiom.om.impl.builder.StAXBuilder;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.Constants;
025: import org.apache.axis2.context.MessageContext;
026: import org.apache.axis2.description.Parameter;
027: import org.apache.axis2.transport.TransportUtils;
028: import org.apache.axis2.transport.http.HTTPConstants;
029: import org.apache.axis2.transport.http.HTTPTransportUtils;
030: import org.apache.axis2.util.JavaUtils;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036: import java.io.IOException;
037:
038: /**
039: * @deprecated Since we are not using this class and this might lead to mis-use of this class, we will
040: * removing this class in a future release.
041: */
042: public class SOAPUtil {
043: private static final Log log = LogFactory.getLog(SOAPUtil.class);
044:
045: public SOAPUtil() {
046: }
047:
048: /**
049: * Handle SOAP Messages
050: *
051: * @param msgContext
052: * @param request
053: * @param response
054: * @throws AxisFault
055: */
056: public boolean processPostRequest(MessageContext msgContext,
057: HttpServletRequest request, HttpServletResponse response)
058: throws AxisFault {
059: try {
060: response.setHeader("Content-Type", "text/html");
061:
062: if (server(msgContext) != null) {
063: response.setHeader("Server", server(msgContext));
064: }
065: String soapAction = request
066: .getHeader(HTTPConstants.HEADER_SOAP_ACTION);
067: msgContext.setProperty(
068: Constants.Configuration.CONTENT_TYPE, request
069: .getContentType());
070: HTTPTransportUtils.processHTTPPostRequest(msgContext,
071: request.getInputStream(), response
072: .getOutputStream(), request
073: .getContentType(), soapAction, request
074: .getRequestURL().toString());
075:
076: response
077: .setContentType("text/xml; charset="
078: + msgContext
079: .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
080:
081: if (!TransportUtils.isResponseWritten(msgContext)) {
082: Integer statusCode = (Integer) msgContext
083: .getProperty(Constants.RESPONSE_CODE);
084: if (statusCode != null) {
085: response.setStatus(statusCode.intValue());
086: } else {
087: response.setStatus(HttpServletResponse.SC_ACCEPTED);
088: }
089: }
090:
091: boolean closeReader = true;
092: Parameter parameter = msgContext.getConfigurationContext()
093: .getAxisConfiguration().getParameter(
094: "axis2.close.reader");
095: if (parameter != null) {
096: closeReader = JavaUtils.isTrueExplicitly(parameter
097: .getValue());
098: }
099: if (closeReader) {
100: try {
101: ((StAXBuilder) msgContext.getEnvelope()
102: .getBuilder()).close();
103: } catch (Exception e) {
104: log.debug(e);
105: }
106: }
107: return true;
108: } catch (AxisFault axisFault) {
109: throw axisFault;
110: } catch (IOException ioException) {
111: throw AxisFault.makeFault(ioException);
112: }
113: }
114:
115: private String server(MessageContext messageContext) {
116: if (messageContext.getParameter(HTTPConstants.SERVER) != null) {
117: OMElement userAgentElement = messageContext.getParameter(
118: HTTPConstants.SERVER).getParameterElement();
119: return userAgentElement.getText().trim();
120:
121: }
122: return null;
123:
124: }
125: }
|