messagecontext.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 2,012 行 · 第 1/5 页
JAVA
2,012 行
/*
* 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.context;
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.impl.MTOMConstants;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.RelatesTo;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.client.Options;
import org.apache.axis2.description.AxisMessage;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.HandlerDescription;
import org.apache.axis2.description.ModuleConfiguration;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.engine.Phase;
import org.apache.axis2.engine.AxisError;
import org.apache.axis2.util.LoggingControl;
import org.apache.axis2.util.MetaDataEntry;
import org.apache.axis2.util.ObjectStateUtils;
import org.apache.axis2.util.SelfManagedDataHolder;
import org.apache.axis2.util.JavaUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.neethi.Policy;
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
/**
* <p>Axis2 states are held in two information models, called description hierarchy
* and context hierarchy. Description hierarchy hold deployment configuration
* and it's values does not change unless deployment configuration change
* occurs where Context hierarchy hold run time information. Both hierarchies
* consists four levels, Global, Service Group, Operation and Message. Please
* look at "Information Model" section of "Axis2 Architecture Guide" for more
* information.</p>
* <p>MessageContext hold run time information about one Message invocation. It
* hold reference to OperationContext, ServiceGroupContext, and Configuration
* Context tied with current message. For an example if you need accesses to other
* messages of the current invocation, you can get to them via OperationContext.
* Addition to class attributes define in Message context, message context stores
* the information as name value pairs. Those name value pairs,and class attributes
* tweak the execution behavior of message context and some of them can be find in
* org.apache.axis2.Constants class. (TODO we should provide list of supported
* options). You may set them at any level of context hierarchy and they will
* affect invocations related to their child elements. </p>
*/
public class MessageContext extends AbstractContext implements Externalizable {
/*
* setup for logging
*/
private static final Log log = LogFactory.getLog(MessageContext.class);
/**
* @serial An ID which can be used to correlate operations on a single
* message in the log files, irrespective of thread switches, persistence,
* etc.
*/
private String logCorrelationID = null;
/**
* This string will be used to hold a form of the logCorrelationID that
* is more suitable for output than its generic form.
*/
private transient String logCorrelationIDString = null;
private static final String myClassName = "MessageContext";
/**
* @serial The serialization version ID tracks the version of the class.
* If a class definition changes, then the serialization/externalization
* of the class is affected. If a change to the class is made which is
* not compatible with the serialization/externalization of the class,
* then the serialization version ID should be updated.
* Refer to the "serialVer" utility to compute a serialization
* version ID.
*/
private static final long serialVersionUID = -7753637088257391858L;
/**
* @serial Tracks the revision level of a class to identify changes to the
* class definition that are compatible to serialization/externalization.
* If a class definition changes, then the serialization/externalization
* of the class is affected.
* Refer to the writeExternal() and readExternal() methods.
*/
// supported revision levels, add a new level to manage compatible changes
private static final int REVISION_1 = 1;
// current revision level of this object
private static final int revisionID = REVISION_1;
/**
* A place to store the current MessageContext
*/
public static ThreadLocal currentMessageContext = new ThreadLocal();
public static MessageContext getCurrentMessageContext() {
return (MessageContext) currentMessageContext.get();
}
public static void setCurrentMessageContext(MessageContext ctx) {
currentMessageContext.set(ctx);
}
/**
* @serial Options on the message
*/
protected Options options;
public final static int IN_FLOW = 1;
public final static int IN_FAULT_FLOW = 3;
public final static int OUT_FLOW = 2;
public final static int OUT_FAULT_FLOW = 4;
public static final String REMOTE_ADDR = "REMOTE_ADDR";
public static final String TRANSPORT_ADDR = "TRANSPORT_ADDR";
public static final String TRANSPORT_HEADERS = "TRANSPORT_HEADERS";
/**
* message attachments
* NOTE: Serialization of message attachments is handled as part of the
* overall message serialization. If this needs to change, then
* investigate having the Attachment class implement the
* java.io.Externalizable interface.
*/
public transient Attachments attachments;
/**
* Field TRANSPORT_OUT
*/
public static final String TRANSPORT_OUT = "TRANSPORT_OUT";
/**
* Field TRANSPORT_IN
*/
public static final String TRANSPORT_IN = "TRANSPORT_IN";
/**
* Field CHARACTER_SET_ENCODING
*/
public static final String CHARACTER_SET_ENCODING = "CHARACTER_SET_ENCODING";
/**
* Field UTF_8. This is the 'utf-8' value for CHARACTER_SET_ENCODING
* property.
*/
public static final String UTF_8 = "UTF-8";
/**
* Field UTF_16. This is the 'utf-16' value for CHARACTER_SET_ENCODING
* property.
*/
public static final String UTF_16 = "utf-16";
/**
* Field TRANSPORT_SUCCEED
*/
public static final String TRANSPORT_SUCCEED = "TRANSPORT_SUCCEED";
/**
* Field DEFAULT_CHAR_SET_ENCODING. This is the default value for
* CHARACTER_SET_ENCODING property.
*/
public static final String DEFAULT_CHAR_SET_ENCODING = UTF_8;
/**
* @serial The direction flow in use to figure out which path the message is in
* (send or receive)
*/
public int FLOW = IN_FLOW;
/**
* To invoke fireAndforget method we have to hand over transport sending logic to a thread
* other wise user has to wait till it get transport response (in the case of HTTP its HTTP
* 202)
*/
public static final String TRANSPORT_NON_BLOCKING = "transportNonBlocking";
/**
* This property allows someone (e.g. RM) to disable an async callback from
* being invoked if a fault occurs during message transmission. If this is
* not set, it can be assumed that the fault will be delivered via
* Callback.onError(...).
*/
public static final String DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR =
"disableTransmissionErrorCallback";
/**
* @serial processingFault
*/
private boolean processingFault;
/**
* @serial paused
*/
private boolean paused;
/**
* @serial outputWritten
*/
public boolean outputWritten;
/**
* @serial newThreadRequired
*/
private boolean newThreadRequired;
/**
* @serial isSOAP11
*/
private boolean isSOAP11 = true;
/**
* @serial The chain of Handlers/Phases for processing this message
*/
private ArrayList executionChain;
/**
* @serial The chain of executed Handlers/Phases from processing
*/
private LinkedList executedPhases;
/**
* @serial Flag to indicate if we are doing REST
*/
private boolean doingREST;
/**
* @serial Flag to indicate if we are doing MTOM
*/
private boolean doingMTOM;
/**
* @serial Flag to indicate if we are doing SWA
*/
private boolean doingSwA;
/**
* AxisMessage associated with this message context
*/
private transient AxisMessage axisMessage;
/**
* AxisOperation associated with this message context
*/
private transient AxisOperation axisOperation;
/**
* AxisService
*/
private transient AxisService axisService;
/**
* AxisServiceGroup
* <p/>
* Note the service group can be set independently of the service
* so the service might not match up with this serviceGroup
*/
private transient AxisServiceGroup axisServiceGroup;
/**
* ConfigurationContext
*/
private transient ConfigurationContext configurationContext;
/**
* @serial Index into the executuion chain of the currently executing handler
*/
private int currentHandlerIndex;
/**
* @serial Index into the current Phase of the currently executing handler (if any)
*/
private int currentPhaseIndex;
/**
* If we're processing this MC due to flowComplete() being called in the case
* of an Exception, this will hold the Exception which caused the problem.
*/
private Exception failureReason;
/**
* @serial SOAP envelope
*/
private SOAPEnvelope envelope;
/**
* @serial OperationContext
*/
private OperationContext operationContext;
/**
* @serial responseWritten
*/
private boolean responseWritten;
/**
* @serial serverSide
*/
private boolean serverSide;
/**
* @serial ServiceContext
*/
private ServiceContext serviceContext;
/**
* @serial service context ID
*/
private String serviceContextID;
/**
* @serial service group context
*/
private ServiceGroupContext serviceGroupContext;
/**
* @serial Holds a key to retrieve the correct ServiceGroupContext.
*/
private String serviceGroupContextId;
/**
* @serial sessionContext
*/
private SessionContext sessionContext;
/**
* transport out description
*/
private transient TransportOutDescription transportOut;
/**
* transport in description
*/
private transient TransportInDescription transportIn;
/**
* @serial incoming transport name
*/
//The value will be set by the transport receiver and there will be validation for the transport
//at the dispatch phase (its post condition)
private String incomingTransportName;
/*
* SelfManagedData will hold message-specific data set by handlers
* Note that this list is not explicitly saved by the MessageContext, but
* rather through the SelfManagedDataManager interface implemented by handlers
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?