httptransportutils.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 405 行 · 第 1/2 页
JAVA
405 行
/*
* 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.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPProcessingException;
import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisEngine;
import org.apache.axis2.engine.Handler.InvocationResponse;
import org.apache.axis2.transport.TransportUtils;
import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.util.Utils;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.zip.GZIPInputStream;
public class HTTPTransportUtils {
/**
* @deprecated This was used only by the now deprecated processHTTPGetRequest() method.
*/
public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl,
Map map, ConfigurationContext configCtx)
throws AxisFault {
String[] values =
Utils.parseRequestURLForServiceAndOperation(requestUrl,
configCtx.getServiceContextPath());
if (values == null) {
return new SOAP11Factory().getDefaultEnvelope();
}
if ((values[1] != null) && (values[0] != null)) {
String srvice = values[0];
AxisService service = configCtx.getAxisConfiguration().getService(srvice);
if (service == null) {
throw new AxisFault("service not found: " + srvice);
}
String operation = values[1];
SOAPFactory soapFactory = new SOAP11Factory();
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
OMNamespace omNs = soapFactory.createOMNamespace(service.getSchematargetNamespace(),
service.getSchemaTargetNamespacePrefix());
soapFactory.createOMNamespace(service.getSchematargetNamespace(),
service.getSchemaTargetNamespacePrefix());
OMElement opElement = soapFactory.createOMElement(operation, omNs);
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String name = (String) it.next();
String value = (String) map.get(name);
OMElement omEle = soapFactory.createOMElement(name, omNs);
omEle.setText(value);
opElement.addChild(omEle);
}
envelope.getBody().addChild(opElement);
return envelope;
} else {
return null;
}
}
/**
* <p>
* Checks whether MTOM needs to be enabled for the message represented by
* the msgContext. We check value assigned to the "enableMTOM" property
* either using the config files (axis2.xml, services.xml) or
* programatically. Programatic configuration is given priority. If the
* given value is "optional", MTOM will be enabled only if the incoming
* message was an MTOM message.
* </p>
*
* @param msgContext
* @return true if SwA needs to be enabled
*/
public static boolean doWriteMTOM(MessageContext msgContext) {
boolean enableMTOM;
Object enableMTOMObject = null;
// First check the whether MTOM is enabled by the configuration
// (Eg:Axis2.xml, services.xml)
Parameter parameter = msgContext.getParameter(Constants.Configuration.ENABLE_MTOM);
if (parameter != null) {
enableMTOMObject = parameter.getValue();
}
// Check whether the configuration is overridden programatically..
// Priority given to programatically setting of the value
Object property = msgContext.getProperty(Constants.Configuration.ENABLE_MTOM);
if (property != null) {
enableMTOMObject = property;
}
enableMTOM = JavaUtils.isTrueExplicitly(enableMTOMObject);
// Handle the optional value for enableMTOM
// If the value for 'enableMTOM' is given as optional and if the request
// message was a MTOM message we sent out MTOM
if (!enableMTOM && msgContext.isDoingMTOM() && (enableMTOMObject instanceof String)) {
if (((String) enableMTOMObject).equalsIgnoreCase(Constants.VALUE_OPTIONAL)) {
enableMTOM = true;
}
}
return enableMTOM;
}
/**
* <p>
* Checks whether SOAP With Attachments (SwA) needs to be enabled for the
* message represented by the msgContext. We check value assigned to the
* "enableSwA" property either using the config files (axis2.xml,
* services.xml) or programatically. Programatic configuration is given
* priority. If the given value is "optional", SwA will be enabled only if
* the incoming message was SwA type.
* </p>
*
* @param msgContext
* @return true if SwA needs to be enabled
*/
public static boolean doWriteSwA(MessageContext msgContext) {
boolean enableSwA;
Object enableSwAObject = null;
// First check the whether SwA is enabled by the configuration
// (Eg:Axis2.xml, services.xml)
Parameter parameter = msgContext.getParameter(Constants.Configuration.ENABLE_SWA);
if (parameter != null) {
enableSwAObject = parameter.getValue();
}
// Check whether the configuration is overridden programatically..
// Priority given to programatically setting of the value
Object property = msgContext.getProperty(Constants.Configuration.ENABLE_SWA);
if (property != null) {
enableSwAObject = property;
}
enableSwA = JavaUtils.isTrueExplicitly(enableSwAObject);
// Handle the optional value for enableSwA
// If the value for 'enableSwA' is given as optional and if the request
// message was a SwA message we sent out SwA
if (!enableSwA && msgContext.isDoingSwA() && (enableSwAObject instanceof String)) {
if (((String) enableSwAObject).equalsIgnoreCase(Constants.VALUE_OPTIONAL)) {
enableSwA = true;
}
}
return enableSwA;
}
/**
* Utility method to query CharSetEncoding. First look in the
* MessageContext. If it's not there look in the OpContext. Use the defualt,
* if it's not given in either contexts.
*
* @param msgContext
* @return CharSetEncoding
*/
public static String getCharSetEncoding(MessageContext msgContext) {
String charSetEnc = (String) msgContext
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
if (charSetEnc == null) {
OperationContext opctx = msgContext.getOperationContext();
if (opctx != null) {
charSetEnc = (String) opctx
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?