messagecontextsavectest.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,277 行 · 第 1/4 页
JAVA
1,277 行
/*
* 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.engine;
import junit.framework.TestCase;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.context.ServiceGroupContext;
import org.apache.axis2.description.AxisMessage;
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.InOutAxisOperation;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.dispatchers.AddressingBasedDispatcher;
import org.apache.axis2.dispatchers.RequestURIBasedDispatcher;
import org.apache.axis2.dispatchers.SOAPActionBasedDispatcher;
import org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
import org.apache.axis2.transport.http.SimpleHTTPServer;
import org.apache.axis2.util.MetaDataEntry;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
/**
* Provides tests that focus on the message context object graph
*/
public class MessageContextSaveCTest extends TestCase {
protected static final Log log = LogFactory.getLog(MessageContextSaveCTest.class);
private File persistentStore = null;
//-------------------------------------------------------------------------
// variables for the object graph
//-------------------------------------------------------------------------
// used on a save of a message context, uses the same setup
// as the regular top-level objects. the difference is that
// the phase contains handlers that split the action across
// two handlers
private ConfigurationContext saveConfigurationContext = null;
private AxisConfiguration saveAxisConfiguration = null;
// used on a restore of a message context, uses the same setup
// as the regular top-level objects with the exception that the
// context objects don't exist. also, the phase contains handlers
// that split the action across two handlers
private ConfigurationContext restoreConfigurationContext = null;
private AxisConfiguration restoreAxisConfiguration = null;
// used on a restore of a message context, uses the same setup
// as the regular top-level objects with service-level context objects
// with the name service name. also, the phase contains handlers
// that split the action across two handlers
private ConfigurationContext equivConfigurationContext = null;
private AxisConfiguration equivAxisConfiguration = null;
//------------------------------
// service group ABC
//------------------------------
private String serviceGroupName_ABC = "ABCServiceGroup";
private String serviceName_A = "ServiceA";
private String serviceName_B = "ServiceB";
private String serviceName_C = "ServiceC";
private QName service_QName_A = new QName(serviceName_A);
private QName service_QName_B = new QName(serviceName_B);
private QName service_QName_C = new QName(serviceName_C);
private String operationName_A1 = "TestOperationA1";
private String operationName_A2 = "TestOperationA2";
private QName operation_QName_A1 = new QName(operationName_A1);
private QName operation_QName_A2 = new QName(operationName_A2);
private ServiceGroupContext srvGrpCtx_ABC_save = null;
private AxisServiceGroup axisSrvGrp_ABC_save = null;
private AxisServiceGroup axisSrvGrp_ABC_restore = null;
private ServiceGroupContext srvGrpCtx_ABC_equiv = null;
private AxisServiceGroup axisSrvGrp_ABC_equiv = null;
private ServiceContext srvCtx_A_save = null;
private ServiceContext srvCtx_B_save = null;
private ServiceContext srvCtx_C_save = null;
private AxisService axisSrv_A_save = null;
private AxisService axisSrv_B_save = null;
private AxisService axisSrv_C_save = null;
private ServiceContext srvCtx_A_restore = null;
private ServiceContext srvCtx_B_restore = null;
private ServiceContext srvCtx_C_restore = null;
private AxisService axisSrv_A_restore = null;
private AxisService axisSrv_B_restore = null;
private AxisService axisSrv_C_restore = null;
private ServiceContext srvCtx_A_equiv = null;
private ServiceContext srvCtx_B_equiv = null;
private ServiceContext srvCtx_C_equiv = null;
private AxisService axisSrv_A_equiv = null;
private AxisService axisSrv_B_equiv = null;
private AxisService axisSrv_C_equiv = null;
private OperationContext opCtx_A1_save = null;
private OperationContext opCtx_A2_save = null;
private AxisOperation axisOp_A1_save = null;
private AxisOperation axisOp_A2_save = null;
private OperationContext opCtx_A1_restore = null;
private OperationContext opCtx_A2_restore = null;
private AxisOperation axisOp_A1_restore = null;
private AxisOperation axisOp_A2_restore = null;
private OperationContext opCtx_A1_equiv = null;
private OperationContext opCtx_A2_equiv = null;
private AxisOperation axisOp_A1_equiv = null;
private AxisOperation axisOp_A2_equiv = null;
private MessageContext msgCtx_A1_1_save = null;
private MessageContext msgCtx_A1_2_save = null;
private MessageContext msgCtx_A2_save = null;
private MessageContext msgCtx_A1_1_equiv = null;
private MessageContext msgCtx_A1_2_equiv = null;
private MessageContext msgCtx_A2_equiv = null;
//-------------------------------------
// objects needed for message context
//------------------------------------
private TransportOutDescription transportOut = null;
private TransportOutDescription transportOut2 = null;
private TransportOutDescription transportOut3 = null;
private TransportInDescription transportIn = null;
private TransportInDescription transportIn2 = null;
private TransportInDescription transportIn3 = null;
private Phase phaseSave = null;
private Phase phaseRestore = null;
private Phase phaseEquiv = null;
private ArrayList executedHandlers = null;
private MessageContext restoredMessageContext = null;
//-------------------------------------------------------------------------
// methods
//-------------------------------------------------------------------------
public MessageContextSaveCTest(String arg0) {
super(arg0);
try {
prepare();
}
catch (Exception e) {
log.debug("MessageContextSaveCTest:constructor: error in setting up object graph [" +
e.getClass().getName() + " : " + e.getMessage() + "]");
}
}
//
// prepare the object hierarchy for testing
//
private void prepare() throws Exception {
//-----------------------------------------------------------------
// setup the top-level objects
//-----------------------------------------------------------------
DispatchPhase dispatchPhase = new DispatchPhase();
dispatchPhase.setName("Dispatch");
AddressingBasedDispatcher abd = new AddressingBasedDispatcher();
abd.initDispatcher();
RequestURIBasedDispatcher rud = new RequestURIBasedDispatcher();
rud.initDispatcher();
SOAPActionBasedDispatcher sabd = new SOAPActionBasedDispatcher();
sabd.initDispatcher();
SOAPMessageBodyBasedDispatcher smbd = new SOAPMessageBodyBasedDispatcher();
smbd.initDispatcher();
dispatchPhase.addHandler(abd);
dispatchPhase.addHandler(rud);
dispatchPhase.addHandler(sabd);
dispatchPhase.addHandler(smbd);
saveAxisConfiguration = new AxisConfiguration();
saveConfigurationContext = new ConfigurationContext(saveAxisConfiguration);
saveConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-only", new RawXMLINOnlyMessageReceiver());
saveConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-out", new RawXMLINOutMessageReceiver());
saveConfigurationContext.getAxisConfiguration().getInFlowPhases().add(dispatchPhase);
restoreAxisConfiguration = new AxisConfiguration();
restoreConfigurationContext = new ConfigurationContext(restoreAxisConfiguration);
restoreConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-only", new RawXMLINOnlyMessageReceiver());
restoreConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-out", new RawXMLINOutMessageReceiver());
restoreConfigurationContext.getAxisConfiguration().getInFlowPhases().add(dispatchPhase);
equivAxisConfiguration = new AxisConfiguration();
equivConfigurationContext = new ConfigurationContext(equivAxisConfiguration);
equivConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-only", new RawXMLINOnlyMessageReceiver());
equivConfigurationContext.getAxisConfiguration().addMessageReceiver(
"http://www.w3.org/2004/08/wsdl/in-out", new RawXMLINOutMessageReceiver());
equivConfigurationContext.getAxisConfiguration().getInFlowPhases().add(dispatchPhase);
//----------------------------
// transport-related objects
//----------------------------
transportOut = new TransportOutDescription("null");
transportOut2 = new TransportOutDescription("happy");
transportOut3 = new TransportOutDescription("golucky");
transportOut.setSender(new CommonsHTTPTransportSender());
transportOut2.setSender(new CommonsHTTPTransportSender());
transportOut3.setSender(new CommonsHTTPTransportSender());
saveAxisConfiguration.addTransportOut(transportOut3);
saveAxisConfiguration.addTransportOut(transportOut2);
saveAxisConfiguration.addTransportOut(transportOut);
restoreAxisConfiguration.addTransportOut(transportOut3);
restoreAxisConfiguration.addTransportOut(transportOut2);
restoreAxisConfiguration.addTransportOut(transportOut);
equivAxisConfiguration.addTransportOut(transportOut3);
equivAxisConfiguration.addTransportOut(transportOut2);
equivAxisConfiguration.addTransportOut(transportOut);
transportIn = new TransportInDescription("null");
transportIn2 = new TransportInDescription("always");
transportIn3 = new TransportInDescription("thebest");
transportIn.setReceiver(new SimpleHTTPServer());
transportIn2.setReceiver(new SimpleHTTPServer());
transportIn3.setReceiver(new SimpleHTTPServer());
saveAxisConfiguration.addTransportIn(transportIn2);
saveAxisConfiguration.addTransportIn(transportIn);
saveAxisConfiguration.addTransportIn(transportIn3);
restoreAxisConfiguration.addTransportIn(transportIn2);
restoreAxisConfiguration.addTransportIn(transportIn);
restoreAxisConfiguration.addTransportIn(transportIn3);
equivAxisConfiguration.addTransportIn(transportIn2);
equivAxisConfiguration.addTransportIn(transportIn);
equivAxisConfiguration.addTransportIn(transportIn3);
//----------------------------
// phase-related objects
//----------------------------
persistentStore = File.createTempFile("mcObjTest", null);
phaseSave = new Phase("PhaseTest");
phaseSave.addHandler(new TempHandler(1, 1));
phaseSave.addHandler(new SaveHandler(2, persistentStore, true));
phaseSave.addHandler(new TempHandler(3, 1));
ArrayList phases_Save = new ArrayList();
phases_Save.add(phaseSave);
saveAxisConfiguration.setInPhasesUptoAndIncludingPostDispatch(phases_Save);
phaseRestore = new Phase("PhaseTest");
phaseRestore.addHandler(new TempHandler(1, 1));
phaseRestore.addHandler(new SaveHandler(2, persistentStore, false));
phaseRestore.addHandler(new TempHandler(3, 1));
ArrayList phases_Restore = new ArrayList();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?