0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one
0003: * or more contributor license agreements. See the NOTICE file
0004: * distributed with this work for additional information
0005: * regarding copyright ownership. The ASF licenses this file
0006: * to you under the Apache License, Version 2.0 (the
0007: * "License"); you may not use this file except in compliance
0008: * with the License. You may obtain a copy of the License at
0009: *
0010: * http://www.apache.org/licenses/LICENSE-2.0
0011: *
0012: * Unless required by applicable law or agreed to in writing,
0013: * software distributed under the License is distributed on an
0014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015: * KIND, either express or implied. See the License for the
0016: * specific language governing permissions and limitations
0017: * under the License.
0018: */
0019:
0020: package org.apache.axis2.engine;
0021:
0022: import junit.framework.TestCase;
0023: import org.apache.axiom.om.OMAbstractFactory;
0024: import org.apache.axiom.om.util.UUIDGenerator;
0025: import org.apache.axiom.soap.SOAPFactory;
0026: import org.apache.axis2.AxisFault;
0027: import org.apache.axis2.addressing.EndpointReference;
0028: import org.apache.axis2.context.ConfigurationContext;
0029: import org.apache.axis2.context.MessageContext;
0030: import org.apache.axis2.context.OperationContext;
0031: import org.apache.axis2.context.ServiceContext;
0032: import org.apache.axis2.context.ServiceGroupContext;
0033: import org.apache.axis2.description.AxisMessage;
0034: import org.apache.axis2.description.AxisOperation;
0035: import org.apache.axis2.description.AxisService;
0036: import org.apache.axis2.description.AxisServiceGroup;
0037: import org.apache.axis2.description.HandlerDescription;
0038: import org.apache.axis2.description.InOutAxisOperation;
0039: import org.apache.axis2.description.TransportInDescription;
0040: import org.apache.axis2.description.TransportOutDescription;
0041: import org.apache.axis2.dispatchers.AddressingBasedDispatcher;
0042: import org.apache.axis2.dispatchers.RequestURIBasedDispatcher;
0043: import org.apache.axis2.dispatchers.SOAPActionBasedDispatcher;
0044: import org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher;
0045: import org.apache.axis2.handlers.AbstractHandler;
0046: import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
0047: import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
0048: import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
0049: import org.apache.axis2.transport.http.SimpleHTTPServer;
0050: import org.apache.axis2.util.MetaDataEntry;
0051: import org.apache.axis2.wsdl.WSDLConstants;
0052: import org.apache.commons.logging.Log;
0053: import org.apache.commons.logging.LogFactory;
0054:
0055: import javax.xml.namespace.QName;
0056: import java.io.File;
0057: import java.io.FileInputStream;
0058: import java.io.FileOutputStream;
0059: import java.io.ObjectInputStream;
0060: import java.io.ObjectOutputStream;
0061: import java.util.ArrayList;
0062: import java.util.HashMap;
0063: import java.util.Iterator;
0064: import java.util.LinkedHashMap;
0065:
0066: /**
0067: * Provides tests that focus on the message context object graph
0068: */
0069: public class MessageContextSaveCTest extends TestCase {
0070: protected static final Log log = LogFactory
0071: .getLog(MessageContextSaveCTest.class);
0072:
0073: private File persistentStore = null;
0074:
0075: //-------------------------------------------------------------------------
0076: // variables for the object graph
0077: //-------------------------------------------------------------------------
0078: // used on a save of a message context, uses the same setup
0079: // as the regular top-level objects. the difference is that
0080: // the phase contains handlers that split the action across
0081: // two handlers
0082: private ConfigurationContext saveConfigurationContext = null;
0083: private AxisConfiguration saveAxisConfiguration = null;
0084:
0085: // used on a restore of a message context, uses the same setup
0086: // as the regular top-level objects with the exception that the
0087: // context objects don't exist. also, the phase contains handlers
0088: // that split the action across two handlers
0089: private ConfigurationContext restoreConfigurationContext = null;
0090: private AxisConfiguration restoreAxisConfiguration = null;
0091:
0092: // used on a restore of a message context, uses the same setup
0093: // as the regular top-level objects with service-level context objects
0094: // with the name service name. also, the phase contains handlers
0095: // that split the action across two handlers
0096: private ConfigurationContext equivConfigurationContext = null;
0097: private AxisConfiguration equivAxisConfiguration = null;
0098:
0099: //------------------------------
0100: // service group ABC
0101: //------------------------------
0102: private String serviceGroupName_ABC = "ABCServiceGroup";
0103:
0104: private String serviceName_A = "ServiceA";
0105: private String serviceName_B = "ServiceB";
0106: private String serviceName_C = "ServiceC";
0107: private QName service_QName_A = new QName(serviceName_A);
0108: private QName service_QName_B = new QName(serviceName_B);
0109: private QName service_QName_C = new QName(serviceName_C);
0110:
0111: private String operationName_A1 = "TestOperationA1";
0112: private String operationName_A2 = "TestOperationA2";
0113: private QName operation_QName_A1 = new QName(operationName_A1);
0114: private QName operation_QName_A2 = new QName(operationName_A2);
0115:
0116: private ServiceGroupContext srvGrpCtx_ABC_save = null;
0117: private AxisServiceGroup axisSrvGrp_ABC_save = null;
0118:
0119: private AxisServiceGroup axisSrvGrp_ABC_restore = null;
0120:
0121: private ServiceGroupContext srvGrpCtx_ABC_equiv = null;
0122: private AxisServiceGroup axisSrvGrp_ABC_equiv = null;
0123:
0124: private ServiceContext srvCtx_A_save = null;
0125: private ServiceContext srvCtx_B_save = null;
0126: private ServiceContext srvCtx_C_save = null;
0127: private AxisService axisSrv_A_save = null;
0128: private AxisService axisSrv_B_save = null;
0129: private AxisService axisSrv_C_save = null;
0130:
0131: private ServiceContext srvCtx_A_restore = null;
0132: private ServiceContext srvCtx_B_restore = null;
0133: private ServiceContext srvCtx_C_restore = null;
0134: private AxisService axisSrv_A_restore = null;
0135: private AxisService axisSrv_B_restore = null;
0136: private AxisService axisSrv_C_restore = null;
0137:
0138: private ServiceContext srvCtx_A_equiv = null;
0139: private ServiceContext srvCtx_B_equiv = null;
0140: private ServiceContext srvCtx_C_equiv = null;
0141: private AxisService axisSrv_A_equiv = null;
0142: private AxisService axisSrv_B_equiv = null;
0143: private AxisService axisSrv_C_equiv = null;
0144:
0145: private OperationContext opCtx_A1_save = null;
0146: private OperationContext opCtx_A2_save = null;
0147: private AxisOperation axisOp_A1_save = null;
0148: private AxisOperation axisOp_A2_save = null;
0149:
0150: private OperationContext opCtx_A1_restore = null;
0151: private OperationContext opCtx_A2_restore = null;
0152: private AxisOperation axisOp_A1_restore = null;
0153: private AxisOperation axisOp_A2_restore = null;
0154:
0155: private OperationContext opCtx_A1_equiv = null;
0156: private OperationContext opCtx_A2_equiv = null;
0157: private AxisOperation axisOp_A1_equiv = null;
0158: private AxisOperation axisOp_A2_equiv = null;
0159:
0160: private MessageContext msgCtx_A1_1_save = null;
0161: private MessageContext msgCtx_A1_2_save = null;
0162: private MessageContext msgCtx_A2_save = null;
0163:
0164: private MessageContext msgCtx_A1_1_equiv = null;
0165: private MessageContext msgCtx_A1_2_equiv = null;
0166: private MessageContext msgCtx_A2_equiv = null;
0167:
0168: //-------------------------------------
0169: // objects needed for message context
0170: //------------------------------------
0171:
0172: private TransportOutDescription transportOut = null;
0173: private TransportOutDescription transportOut2 = null;
0174: private TransportOutDescription transportOut3 = null;
0175: private TransportInDescription transportIn = null;
0176: private TransportInDescription transportIn2 = null;
0177: private TransportInDescription transportIn3 = null;
0178:
0179: private Phase phaseSave = null;
0180: private Phase phaseRestore = null;
0181: private Phase phaseEquiv = null;
0182:
0183: private ArrayList executedHandlers = null;
0184:
0185: private MessageContext restoredMessageContext = null;
0186:
0187: //-------------------------------------------------------------------------
0188: // methods
0189: //-------------------------------------------------------------------------
0190:
0191: public MessageContextSaveCTest(String arg0) {
0192: super (arg0);
0193:
0194: try {
0195: prepare();
0196: } catch (Exception e) {
0197: log
0198: .debug("MessageContextSaveCTest:constructor: error in setting up object graph ["
0199: + e.getClass().getName()
0200: + " : "
0201: + e.getMessage() + "]");
0202: }
0203: }
0204:
0205: //
0206: // prepare the object hierarchy for testing
0207: //
0208: private void prepare() throws Exception {
0209: //-----------------------------------------------------------------
0210: // setup the top-level objects
0211: //-----------------------------------------------------------------
0212:
0213: DispatchPhase dispatchPhase = new DispatchPhase();
0214: dispatchPhase.setName("Dispatch");
0215:
0216: AddressingBasedDispatcher abd = new AddressingBasedDispatcher();
0217: abd.initDispatcher();
0218:
0219: RequestURIBasedDispatcher rud = new RequestURIBasedDispatcher();
0220: rud.initDispatcher();
0221:
0222: SOAPActionBasedDispatcher sabd = new SOAPActionBasedDispatcher();
0223: sabd.initDispatcher();
0224:
0225: SOAPMessageBodyBasedDispatcher smbd = new SOAPMessageBodyBasedDispatcher();
0226: smbd.initDispatcher();
0227:
0228: dispatchPhase.addHandler(abd);
0229: dispatchPhase.addHandler(rud);
0230: dispatchPhase.addHandler(sabd);
0231: dispatchPhase.addHandler(smbd);
0232:
0233: saveAxisConfiguration = new AxisConfiguration();
0234: saveConfigurationContext = new ConfigurationContext(
0235: saveAxisConfiguration);
0236: saveConfigurationContext.getAxisConfiguration()
0237: .addMessageReceiver(
0238: "http://www.w3.org/2004/08/wsdl/in-only",
0239: new RawXMLINOnlyMessageReceiver());
0240: saveConfigurationContext.getAxisConfiguration()
0241: .addMessageReceiver(
0242: "http://www.w3.org/2004/08/wsdl/in-out",
0243: new RawXMLINOutMessageReceiver());
0244: saveConfigurationContext.getAxisConfiguration()
0245: .getInFlowPhases().add(dispatchPhase);
0246:
0247: restoreAxisConfiguration = new AxisConfiguration();
0248: restoreConfigurationContext = new ConfigurationContext(
0249: restoreAxisConfiguration);
0250: restoreConfigurationContext.getAxisConfiguration()
0251: .addMessageReceiver(
0252: "http://www.w3.org/2004/08/wsdl/in-only",
0253: new RawXMLINOnlyMessageReceiver());
0254: restoreConfigurationContext.getAxisConfiguration()
0255: .addMessageReceiver(
0256: "http://www.w3.org/2004/08/wsdl/in-out",
0257: new RawXMLINOutMessageReceiver());
0258: restoreConfigurationContext.getAxisConfiguration()
0259: .getInFlowPhases().add(dispatchPhase);
0260:
0261: equivAxisConfiguration = new AxisConfiguration();
0262: equivConfigurationContext = new ConfigurationContext(
0263: equivAxisConfiguration);
0264: equivConfigurationContext.getAxisConfiguration()
0265: .addMessageReceiver(
0266: "http://www.w3.org/2004/08/wsdl/in-only",
0267: new RawXMLINOnlyMessageReceiver());
0268: equivConfigurationContext.getAxisConfiguration()
0269: .addMessageReceiver(
0270: "http://www.w3.org/2004/08/wsdl/in-out",
0271: new RawXMLINOutMessageReceiver());
0272: equivConfigurationContext.getAxisConfiguration()
0273: .getInFlowPhases().add(dispatchPhase);
0274:
0275: //----------------------------
0276: // transport-related objects
0277: //----------------------------
0278: transportOut = new TransportOutDescription("null");
0279: transportOut2 = new TransportOutDescription("happy");
0280: transportOut3 = new TransportOutDescription("golucky");
0281: transportOut.setSender(new CommonsHTTPTransportSender());
0282: transportOut2.setSender(new CommonsHTTPTransportSender());
0283: transportOut3.setSender(new CommonsHTTPTransportSender());
0284:
0285: saveAxisConfiguration.addTransportOut(transportOut3);
0286: saveAxisConfiguration.addTransportOut(transportOut2);
0287: saveAxisConfiguration.addTransportOut(transportOut);
0288:
0289: restoreAxisConfiguration.addTransportOut(transportOut3);
0290: restoreAxisConfiguration.addTransportOut(transportOut2);
0291: restoreAxisConfiguration.addTransportOut(transportOut);
0292:
0293: equivAxisConfiguration.addTransportOut(transportOut3);
0294: equivAxisConfiguration.addTransportOut(transportOut2);
0295: equivAxisConfiguration.addTransportOut(transportOut);
0296:
0297: transportIn = new TransportInDescription("null");
0298: transportIn2 = new TransportInDescription("always");
0299: transportIn3 = new TransportInDescription("thebest");
0300: transportIn.setReceiver(new SimpleHTTPServer());
0301: transportIn2.setReceiver(new SimpleHTTPServer());
0302: transportIn3.setReceiver(new SimpleHTTPServer());
0303:
0304: saveAxisConfiguration.addTransportIn(transportIn2);
0305: saveAxisConfiguration.addTransportIn(transportIn);
0306: saveAxisConfiguration.addTransportIn(transportIn3);
0307:
0308: restoreAxisConfiguration.addTransportIn(transportIn2);
0309: restoreAxisConfiguration.addTransportIn(transportIn);
0310: restoreAxisConfiguration.addTransportIn(transportIn3);
0311:
0312: equivAxisConfiguration.addTransportIn(transportIn2);
0313: equivAxisConfiguration.addTransportIn(transportIn);
0314: equivAxisConfiguration.addTransportIn(transportIn3);
0315:
0316: //----------------------------
0317: // phase-related objects
0318: //----------------------------
0319: persistentStore = File.createTempFile("mcObjTest", null);
0320:
0321: phaseSave = new Phase("PhaseTest");
0322: phaseSave.addHandler(new TempHandler(1, 1));
0323: phaseSave.addHandler(new SaveHandler(2, persistentStore, true));
0324: phaseSave.addHandler(new TempHandler(3, 1));
0325:
0326: ArrayList phases_Save = new ArrayList();
0327: phases_Save.add(phaseSave);
0328:
0329: saveAxisConfiguration
0330: .setInPhasesUptoAndIncludingPostDispatch(phases_Save);
0331:
0332: phaseRestore = new Phase("PhaseTest");
0333: phaseRestore.addHandler(new TempHandler(1, 1));
0334: phaseRestore.addHandler(new SaveHandler(2, persistentStore,
0335: false));
0336: phaseRestore.addHandler(new TempHandler(3, 1));
0337:
0338: ArrayList phases_Restore = new ArrayList();
0339: phases_Restore.add(phaseRestore);
0340:
0341: restoreAxisConfiguration
0342: .setInPhasesUptoAndIncludingPostDispatch(phases_Restore);
0343:
0344: phaseEquiv = new Phase("PhaseTest");
0345: phaseEquiv.addHandler(new TempHandler(1, 1));
0346: phaseEquiv
0347: .addHandler(new SaveHandler(2, persistentStore, true));
0348: phaseEquiv.addHandler(new TempHandler(3, 1));
0349:
0350: ArrayList phases_Equiv = new ArrayList();
0351: phases_Equiv.add(phaseEquiv);
0352:
0353: equivAxisConfiguration
0354: .setInPhasesUptoAndIncludingPostDispatch(phases_Equiv);
0355:
0356: //-----------------------------------------------------------------
0357: // setup the axis side of the hierachy
0358: //-----------------------------------------------------------------
0359: // ABC group
0360: //----------------------------
0361:
0362: axisSrvGrp_ABC_save = new AxisServiceGroup(
0363: saveAxisConfiguration);
0364: axisSrvGrp_ABC_save.setServiceGroupName(serviceGroupName_ABC);
0365:
0366: axisSrv_A_save = new AxisService(service_QName_A.getLocalPart());
0367: axisSrv_B_save = new AxisService(service_QName_B.getLocalPart());
0368: axisSrv_C_save = new AxisService(service_QName_C.getLocalPart());
0369:
0370: axisSrvGrp_ABC_save.addService(axisSrv_A_save);
0371: axisSrvGrp_ABC_save.addService(axisSrv_B_save);
0372: axisSrvGrp_ABC_save.addService(axisSrv_C_save);
0373:
0374: axisOp_A1_save = new InOutAxisOperation(operation_QName_A1);
0375: axisOp_A2_save = new InOutAxisOperation(operation_QName_A2);
0376:
0377: axisOp_A1_save.setMessageReceiver(new MessageReceiver() {
0378: public void receive(MessageContext messageCtx) {
0379: }
0380: });
0381:
0382: axisOp_A2_save.setMessageReceiver(new MessageReceiver() {
0383: public void receive(MessageContext messageCtx) {
0384: }
0385: });
0386:
0387: axisSrv_A_save.addOperation(axisOp_A1_save);
0388: axisSrv_A_save.mapActionToOperation(operation_QName_A1
0389: .getLocalPart(), axisOp_A1_save);
0390:
0391: axisSrv_A_save.addOperation(axisOp_A2_save);
0392: axisSrv_A_save.mapActionToOperation(operation_QName_A2
0393: .getLocalPart(), axisOp_A2_save);
0394:
0395: saveAxisConfiguration.addService(axisSrv_A_save);
0396: saveAxisConfiguration.addService(axisSrv_B_save);
0397: saveAxisConfiguration.addService(axisSrv_C_save);
0398:
0399: //---------------------
0400:
0401: axisSrvGrp_ABC_restore = new AxisServiceGroup(
0402: restoreAxisConfiguration);
0403: axisSrvGrp_ABC_restore
0404: .setServiceGroupName(serviceGroupName_ABC);
0405:
0406: axisSrv_A_restore = new AxisService(service_QName_A
0407: .getLocalPart());
0408: axisSrv_B_restore = new AxisService(service_QName_B
0409: .getLocalPart());
0410: axisSrv_C_restore = new AxisService(service_QName_C
0411: .getLocalPart());
0412:
0413: axisSrvGrp_ABC_restore.addService(axisSrv_A_restore);
0414: axisSrvGrp_ABC_restore.addService(axisSrv_B_restore);
0415: axisSrvGrp_ABC_restore.addService(axisSrv_C_restore);
0416:
0417: axisOp_A1_restore = new InOutAxisOperation(operation_QName_A1);
0418: axisOp_A2_restore = new InOutAxisOperation(operation_QName_A2);
0419:
0420: axisOp_A1_restore.setMessageReceiver(new MessageReceiver() {
0421: public void receive(MessageContext messageCtx) {
0422: }
0423: });
0424:
0425: axisOp_A2_restore.setMessageReceiver(new MessageReceiver() {
0426: public void receive(MessageContext messageCtx) {
0427: }
0428: });
0429:
0430: axisSrv_A_restore.addOperation(axisOp_A1_restore);
0431: axisSrv_A_restore.mapActionToOperation(operation_QName_A1
0432: .getLocalPart(), axisOp_A1_restore);
0433:
0434: axisSrv_A_restore.addOperation(axisOp_A2_restore);
0435: axisSrv_A_restore.mapActionToOperation(operation_QName_A2
0436: .getLocalPart(), axisOp_A2_restore);
0437:
0438: restoreAxisConfiguration.addService(axisSrv_A_restore);
0439: restoreAxisConfiguration.addService(axisSrv_B_restore);
0440: restoreAxisConfiguration.addService(axisSrv_C_restore);
0441:
0442: axisOp_A1_save.getRemainingPhasesInFlow().add(phaseSave);
0443: axisOp_A2_save.getRemainingPhasesInFlow().add(phaseSave);
0444:
0445: axisOp_A1_restore.getRemainingPhasesInFlow().add(phaseRestore);
0446: axisOp_A2_restore.getRemainingPhasesInFlow().add(phaseRestore);
0447:
0448: //-------------------------------
0449:
0450: axisSrvGrp_ABC_equiv = new AxisServiceGroup(
0451: equivAxisConfiguration);
0452: axisSrvGrp_ABC_equiv.setServiceGroupName(serviceGroupName_ABC);
0453:
0454: axisSrv_A_equiv = new AxisService(service_QName_A
0455: .getLocalPart());
0456: axisSrv_B_equiv = new AxisService(service_QName_B
0457: .getLocalPart());
0458: axisSrv_C_equiv = new AxisService(service_QName_C
0459: .getLocalPart());
0460:
0461: axisSrvGrp_ABC_equiv.addService(axisSrv_A_equiv);
0462: axisSrvGrp_ABC_equiv.addService(axisSrv_B_equiv);
0463: axisSrvGrp_ABC_equiv.addService(axisSrv_C_equiv);
0464:
0465: axisOp_A1_equiv = new InOutAxisOperation(operation_QName_A1);
0466: axisOp_A2_equiv = new InOutAxisOperation(operation_QName_A2);
0467:
0468: axisOp_A1_equiv.setMessageReceiver(new MessageReceiver() {
0469: public void receive(MessageContext messageCtx) {
0470: }
0471: });
0472:
0473: axisOp_A2_equiv.setMessageReceiver(new MessageReceiver() {
0474: public void receive(MessageContext messageCtx) {
0475: }
0476: });
0477:
0478: axisSrv_A_equiv.addOperation(axisOp_A1_equiv);
0479: axisSrv_A_equiv.mapActionToOperation(operation_QName_A1
0480: .getLocalPart(), axisOp_A1_equiv);
0481:
0482: axisSrv_A_equiv.addOperation(axisOp_A2_equiv);
0483: axisSrv_A_equiv.mapActionToOperation(operation_QName_A2
0484: .getLocalPart(), axisOp_A2_equiv);
0485:
0486: equivAxisConfiguration.addService(axisSrv_A_equiv);
0487: equivAxisConfiguration.addService(axisSrv_B_equiv);
0488: equivAxisConfiguration.addService(axisSrv_C_equiv);
0489:
0490: //-----------------------------------------------------------------
0491: // setup the context objects
0492: //-----------------------------------------------------------------
0493: srvGrpCtx_ABC_save = saveConfigurationContext
0494: .createServiceGroupContext(axisSrvGrp_ABC_save);
0495: srvGrpCtx_ABC_save.setId(serviceGroupName_ABC);
0496:
0497: srvCtx_A_save = srvGrpCtx_ABC_save
0498: .getServiceContext(axisSrv_A_save);
0499: srvCtx_B_save = srvGrpCtx_ABC_save
0500: .getServiceContext(axisSrv_B_save);
0501: srvCtx_C_save = srvGrpCtx_ABC_save
0502: .getServiceContext(axisSrv_C_save);
0503:
0504: opCtx_A1_save = srvCtx_A_save
0505: .createOperationContext(operation_QName_A1);
0506: opCtx_A2_save = srvCtx_A_save
0507: .createOperationContext(operation_QName_A2);
0508:
0509: //----------------------------------------
0510:
0511: srvGrpCtx_ABC_equiv = equivConfigurationContext
0512: .createServiceGroupContext(axisSrvGrp_ABC_equiv);
0513: srvGrpCtx_ABC_equiv.setId(serviceGroupName_ABC);
0514:
0515: srvCtx_A_equiv = srvGrpCtx_ABC_equiv
0516: .getServiceContext(axisSrv_A_equiv);
0517: srvCtx_B_equiv = srvGrpCtx_ABC_equiv
0518: .getServiceContext(axisSrv_B_equiv);
0519: srvCtx_C_equiv = srvGrpCtx_ABC_equiv
0520: .getServiceContext(axisSrv_C_equiv);
0521:
0522: opCtx_A1_equiv = srvCtx_A_equiv
0523: .createOperationContext(operation_QName_A1);
0524: opCtx_A2_equiv = srvCtx_A_equiv
0525: .createOperationContext(operation_QName_A2);
0526:
0527: //----------------------------------------
0528: // message context objects
0529: //----------------------------------------
0530: msgCtx_A1_1_save = createMessageContext(opCtx_A1_save,
0531: saveConfigurationContext, MessageContext.IN_FLOW);
0532: msgCtx_A1_2_save = createMessageContext(opCtx_A1_save,
0533: saveConfigurationContext, MessageContext.OUT_FLOW);
0534: msgCtx_A2_save = createMessageContext(opCtx_A2_save,
0535: saveConfigurationContext, MessageContext.IN_FLOW);
0536:
0537: msgCtx_A1_1_equiv = createMessageContext(opCtx_A1_equiv,
0538: equivConfigurationContext, MessageContext.IN_FLOW);
0539: msgCtx_A1_2_equiv = createMessageContext(opCtx_A1_equiv,
0540: equivConfigurationContext, MessageContext.OUT_FLOW);
0541: msgCtx_A2_equiv = createMessageContext(opCtx_A2_equiv,
0542: equivConfigurationContext, MessageContext.IN_FLOW);
0543:
0544: //-----------------------------------------------------------------
0545: // other objects
0546: //-----------------------------------------------------------------
0547: executedHandlers = new ArrayList();
0548: }
0549:
0550: private MessageContext createMessageContext(OperationContext oc,
0551: ConfigurationContext cc, int flowType) throws Exception {
0552: MessageContext mc = cc.createMessageContext();
0553:
0554: mc.setFLOW(flowType);
0555: mc.setTransportIn(transportIn);
0556: mc.setTransportOut(transportOut);
0557:
0558: mc.setServerSide(true);
0559: // mc.setProperty(MessageContext.TRANSPORT_OUT, System.out);
0560:
0561: SOAPFactory omFac = OMAbstractFactory.getSOAP11Factory();
0562: mc.setEnvelope(omFac.getDefaultEnvelope());
0563:
0564: AxisOperation axisOperation = oc.getAxisOperation();
0565: String action = axisOperation.getName().getLocalPart();
0566: mc.setSoapAction(action);
0567: // System.out.flush();
0568:
0569: mc.setMessageID(UUIDGenerator.getUUID());
0570:
0571: axisOperation.registerOperationContext(mc, oc);
0572: mc.setOperationContext(oc);
0573:
0574: ServiceContext sc = oc.getServiceContext();
0575: mc.setServiceContext(sc);
0576:
0577: mc.setTo(new EndpointReference("axis2/services/NullService"));
0578: mc.setWSAAction("DummyOp");
0579:
0580: AxisMessage axisMessage = axisOperation
0581: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
0582: mc.setAxisMessage(axisMessage);
0583:
0584: return mc;
0585: }
0586:
0587: protected void setUp() throws Exception {
0588: //org.apache.log4j.BasicConfigurator.configure();
0589: }
0590:
0591: public void testHierarchyNewContext() throws Exception {
0592: String title = "MessageContextSaveCTest:testHierarchyNewContext(): ";
0593:
0594: AxisEngine engineSave = new AxisEngine(saveConfigurationContext);
0595:
0596: MessageContext mc = msgCtx_A1_2_save;
0597: OperationContext oc = mc.getOperationContext();
0598: log
0599: .debug(title
0600: + "*** Original OperationContext message context table ****");
0601: showMCTable(oc);
0602:
0603: // run the message through the message processing
0604: // this causes the message context to get saved
0605: log
0606: .debug(title
0607: + "- - - Save the message context from the engine - - - -");
0608: engineSave.receive(mc);
0609:
0610: LinkedHashMap original_object_graph = getObjectGraphInfo(mc);
0611: log.debug(title + "*** Originial object graph ****");
0612: showObjectGraphInfo(original_object_graph);
0613:
0614: log
0615: .debug(title
0616: + "- - - Restore the message context on a separate engine - - - - - - - - - - - - - - - -");
0617: AxisEngine engineRestore = new AxisEngine(
0618: restoreConfigurationContext);
0619: MessageContext mc2 = restoreMessageContext(persistentStore,
0620: restoreConfigurationContext);
0621:
0622: LinkedHashMap restored_object_graph = getObjectGraphInfo(mc2);
0623: log.debug(title + "*** Restored object graph ****");
0624: showObjectGraphInfo(restored_object_graph);
0625:
0626: OperationContext oc2 = mc2.getOperationContext();
0627: log
0628: .debug(title
0629: + "*** Restored OperationContext message context table ****");
0630: showMCTable(oc2);
0631:
0632: boolean mcTableMatch = compareMCTable(oc, oc2);
0633: assertTrue(mcTableMatch);
0634:
0635: // resume the restored paused message context on an engine that has the
0636: // same setup as the engine where the save occurred
0637: // but doesn't have the Context objects
0638: log
0639: .debug(title
0640: + "- - - Resume the restored message context - - - - - - - - - - - - - - - -");
0641: engineRestore.resume(mc2);
0642:
0643: LinkedHashMap resumed_object_graph = getObjectGraphInfo(mc2);
0644: log.debug(title + "*** Post Resumed object graph ****");
0645: showObjectGraphInfo(resumed_object_graph);
0646:
0647: // compare object hashcodes - expect differences
0648: boolean expectFalse = compareObjectGraphInfo(
0649: original_object_graph, restored_object_graph, true);
0650: assertFalse(expectFalse);
0651:
0652: boolean expectSameObjectIds = compareObjectGraphInfo(
0653: original_object_graph, restored_object_graph, false);
0654: assertTrue(expectSameObjectIds);
0655:
0656: boolean isSame = compareObjectGraphInfo(restored_object_graph,
0657: resumed_object_graph, false);
0658: assertTrue(isSame);
0659:
0660: }
0661:
0662: public void testHierarchyReuse() throws Exception {
0663: String title = "MessageContextSaveCTest:testHierarchyReuse(): ";
0664:
0665: AxisEngine engineSave = new AxisEngine(saveConfigurationContext);
0666:
0667: MessageContext mc = msgCtx_A1_1_save;
0668:
0669: // run the message through the message processing
0670: // this causes the message context to get saved
0671: log
0672: .debug(title
0673: + "- - - Save the message context from the engine - - - -");
0674: engineSave.receive(mc);
0675:
0676: LinkedHashMap original_object_graph = getObjectGraphInfo(mc);
0677: log.debug(title + "*** Originial object graph ****");
0678: showObjectGraphInfo(original_object_graph);
0679:
0680: log
0681: .debug(title
0682: + "- - - Restore the message context on a separate engine - - - - - - - - - - - - - - - -");
0683: AxisEngine engineEquiv = new AxisEngine(
0684: equivConfigurationContext);
0685: MessageContext mc2 = restoreMessageContext(persistentStore,
0686: equivConfigurationContext);
0687:
0688: LinkedHashMap restored_object_graph = getObjectGraphInfo(mc2);
0689: log.debug(title + "*** Restored object graph ****");
0690: showObjectGraphInfo(restored_object_graph);
0691:
0692: // we don't use strict checking here since the engine where the
0693: // restoration takes place is a "copy", ie, there are new objects
0694: // for the same names/identifications
0695: boolean hasEquivalence = compareObjectGraphInfo(
0696: original_object_graph, restored_object_graph, false);
0697: assertTrue(hasEquivalence);
0698:
0699: // get an object graph from an equivalent message context on the separate engine
0700: // we would expect a strict match of the object graphs between the
0701: // restored message context and the message context on the separate engine
0702: LinkedHashMap separate_object_graph = getObjectGraphInfo(msgCtx_A1_1_equiv);
0703:
0704: // compare the restored object graph with the existing object graph
0705: boolean expectStrict = compareObjectGraphInfo(
0706: restored_object_graph, separate_object_graph, true);
0707: assertTrue(expectStrict);
0708:
0709: // resume the restored paused message context on an engine that has the
0710: // same setup as the engine where the save occurred
0711: // and save has the Service-level Context objects
0712: log
0713: .debug(title
0714: + "- - - Resume the restored message context - - - - - - - - - - - - - - - -");
0715: engineEquiv.resume(mc2);
0716:
0717: LinkedHashMap resumed_object_graph = getObjectGraphInfo(mc2);
0718: log.debug(title + "*** Post Resumed object graph ****");
0719: showObjectGraphInfo(resumed_object_graph);
0720:
0721: // there should be no changes in the object graph in our case after the resume
0722: hasEquivalence = compareObjectGraphInfo(restored_object_graph,
0723: resumed_object_graph, true);
0724: assertTrue(hasEquivalence);
0725:
0726: }
0727:
0728: /**
0729: * Restores a previously saved message context
0730: */
0731: public MessageContext restoreMessageContext(File restoreFile,
0732: ConfigurationContext cc) {
0733: String title = "restoreMessageContext(): ";
0734:
0735: MessageContext restoredMC = null;
0736:
0737: File theFile = restoreFile;
0738: String theFilename = null;
0739:
0740: // the configuration context to use for message context activation
0741: ConfigurationContext cfgCtx = cc;
0742:
0743: boolean restoredOk = false;
0744:
0745: if ((theFile != null) && (theFile.exists())) {
0746: theFilename = theFile.getName();
0747: log.debug(title + "temp file = [" + theFilename + "]");
0748:
0749: // ---------------------------------------------------------
0750: // restore from the temporary file
0751: // ---------------------------------------------------------
0752: try {
0753: // setup an input stream to the file
0754: FileInputStream inStream = new FileInputStream(theFile);
0755:
0756: // attach a stream capable of reading objects from the
0757: // stream connected to the file
0758: ObjectInputStream inObjStream = new ObjectInputStream(
0759: inStream);
0760:
0761: // try to restore the message context
0762: log.debug(title + "restoring a message context.....");
0763: restoredOk = false;
0764:
0765: MessageContext msgContext2 = (MessageContext) inObjStream
0766: .readObject();
0767: inObjStream.close();
0768: inStream.close();
0769:
0770: msgContext2.activate(cfgCtx);
0771:
0772: restoredOk = true;
0773: log.debug(title + "....restored message context.....");
0774:
0775: // now put the restored message context in the global
0776: // variable for the test
0777: restoredMC = msgContext2;
0778: } catch (Exception ex2) {
0779: log.debug(title
0780: + "error with restoring message context = ["
0781: + ex2.getClass().getName() + " : "
0782: + ex2.getMessage() + "]");
0783: ex2.printStackTrace();
0784: restoredMessageContext = null;
0785: }
0786:
0787: assertTrue(restoredOk);
0788:
0789: // if the restore of the message context succeeded,
0790: // then don't keep the temporary file around
0791: boolean removeTmpFile = restoredOk;
0792: if (removeTmpFile) {
0793: try {
0794: theFile.delete();
0795: } catch (Exception e) {
0796: // just absorb it
0797: }
0798: }
0799: }
0800:
0801: return restoredMC;
0802: }
0803:
0804: private LinkedHashMap getObjectGraphInfo(MessageContext msgCtx) {
0805: if (msgCtx == null) {
0806: return null;
0807: }
0808:
0809: MetaDataEntry metaMC = null;
0810: MetaDataEntry metaOC = null;
0811: MetaDataEntry metaSC = null;
0812: MetaDataEntry metaSGC = null;
0813: MetaDataEntry metaCC = null;
0814: MetaDataEntry metaAO = null;
0815: MetaDataEntry metaAS = null;
0816: MetaDataEntry metaASG = null;
0817: MetaDataEntry metaAC = null;
0818:
0819: String keyMC = null;
0820: String keyOC = null;
0821: String keySC = null;
0822: String keySGC = null;
0823: String keyCC = null;
0824: String keyAO = null;
0825: String keyAS = null;
0826: String keyASG = null;
0827: String keyAC = null;
0828:
0829: LinkedHashMap objInfo = new LinkedHashMap();
0830:
0831: // get the identification info about the primary objects in the object graph
0832: // class name
0833: // name string
0834: // hashcode string
0835:
0836: // message context
0837: keyMC = msgCtx.getClass().getName();
0838: metaMC = new MetaDataEntry(keyMC, msgCtx.getMessageID(), "["
0839: + msgCtx.hashCode() + "]");
0840: objInfo.put(keyMC, metaMC);
0841:
0842: // operation context
0843: OperationContext oc = msgCtx.getOperationContext();
0844: keyOC = oc.getClass().getName();
0845: metaOC = new MetaDataEntry(keyOC, oc.getOperationName(), "["
0846: + oc.hashCode() + "]");
0847: objInfo.put(keyOC, metaOC);
0848:
0849: // service context
0850: ServiceContext sc = msgCtx.getServiceContext();
0851: keySC = sc.getClass().getName();
0852: metaSC = new MetaDataEntry(keySC, sc.getName(), "["
0853: + sc.hashCode() + "]");
0854: objInfo.put(keySC, metaSC);
0855:
0856: // service group context
0857: ServiceGroupContext sgc = msgCtx.getServiceGroupContext();
0858: keySGC = sgc.getClass().getName();
0859: metaSGC = new MetaDataEntry(keySGC, sgc.getId(), "["
0860: + sgc.hashCode() + "]");
0861: objInfo.put(keySGC, metaSGC);
0862:
0863: // configuration context
0864: ConfigurationContext cc = msgCtx.getConfigurationContext();
0865: keyCC = cc.getClass().getName();
0866: metaCC = new MetaDataEntry(keyCC, null, "[" + cc.hashCode()
0867: + "]");
0868: objInfo.put(keyCC, metaCC);
0869:
0870: // axis operation
0871: AxisOperation ao = msgCtx.getAxisOperation();
0872: keyAO = ao.getClass().getName();
0873: metaAO = new MetaDataEntry(keyAO, ao.getName().toString(), "["
0874: + ao.hashCode() + "]");
0875: objInfo.put(keyAO, metaAO);
0876:
0877: // axis service
0878: AxisService as = msgCtx.getAxisService();
0879: keyAS = as.getClass().getName();
0880: metaAS = new MetaDataEntry(keyAS, as.getName(), "["
0881: + as.hashCode() + "]");
0882: objInfo.put(keyAS, metaAS);
0883:
0884: // axis service group
0885: AxisServiceGroup asg = msgCtx.getAxisServiceGroup();
0886: keyASG = asg.getClass().getName();
0887: metaASG = new MetaDataEntry(keyASG, asg.getServiceGroupName(),
0888: "[" + asg.hashCode() + "]");
0889: objInfo.put(keyASG, metaASG);
0890:
0891: // axis configuration
0892: AxisConfiguration ac = cc.getAxisConfiguration();
0893: keyAC = ac.getClass().getName();
0894: metaAC = new MetaDataEntry(keyAC, null, "[" + ac.hashCode()
0895: + "]");
0896: objInfo.put(keyAC, metaAC);
0897:
0898: return objInfo;
0899: }
0900:
0901: /**
0902: * Compare two mappings containing object graph info.
0903: * This uses the class name and object ID.
0904: * <p/>
0905: * Strict comparison includes the object hash codes. If
0906: * you expect the same object to be represented in
0907: * both maps, you may want to use Strict checking.
0908: * <p/>
0909: *
0910: * @param map1 The first object graph info map
0911: * @param map2 The second object graph info map
0912: * @param strict TRUE if strict comparison
0913: * @return Outcome of the comparison: TRUE if equivalent, FALSE otherwise
0914: */
0915: private boolean compareObjectGraphInfo(LinkedHashMap map1,
0916: LinkedHashMap map2, boolean strict) {
0917: String title = "MessageContextSaveCTest: compareObjectGraphInfo(): ";
0918:
0919: if ((map1 != null) && (map2 != null)) {
0920: if (map1.size() != map2.size()) {
0921: log
0922: .debug(title
0923: + "Object graph info mappings are different sizes.");
0924: return false;
0925: }
0926:
0927: Iterator it = map1.keySet().iterator();
0928:
0929: while (it.hasNext()) {
0930: // the key is the class name associated with the object
0931: String key = (String) it.next();
0932:
0933: // skip certain objects, those will always be unique
0934: if ((key.indexOf("MessageContext") == -1)
0935: && (key.indexOf("OperationContext") == -1)
0936: && (key.indexOf("ConfigurationContext") == -1)
0937: && (key.indexOf("AxisConfiguration") == -1)) {
0938: // the class names listed above were not found
0939: // so we're dealing with the other objects
0940: MetaDataEntry value1 = (MetaDataEntry) map1
0941: .get(key);
0942: MetaDataEntry value2 = (MetaDataEntry) map2
0943: .get(key);
0944:
0945: if ((value1 != null) && (value2 != null)) {
0946: // check the object identification
0947: String name1 = value1.getName();
0948: String name2 = value2.getName();
0949:
0950: if ((name1 != null) && (name2 != null)) {
0951: if (name1.equals(name2) == false) {
0952: log.debug(title + "name1 [" + name1
0953: + "] != name2 [" + name2
0954: + "]");
0955: return false;
0956: }
0957: } else if ((name1 == null) && (name2 == null)) {
0958: // ok
0959: } else {
0960: // mismatch
0961: log.debug(title + "name1 [" + name1
0962: + "] != name2 [" + name2 + "]");
0963: return false;
0964: }
0965:
0966: // Strict testing means checking the object hashcodes.
0967: // Use this option when you expect the same
0968: // objects in the map.
0969: if (strict) {
0970: String code1 = value1.getExtraName();
0971: String code2 = value2.getExtraName();
0972:
0973: if ((code1 != null) && (code2 != null)) {
0974: if (code1.equals(code2) == false) {
0975: log.debug(title + "name [" + name1
0976: + "] code1 [" + code1
0977: + "] != code2 [" + code2
0978: + "]");
0979: return false;
0980: }
0981: } else if ((code1 == null)
0982: && (code2 == null)) {
0983: // ok
0984: } else {
0985: // mismatch
0986: log.debug(title + "name [" + name1
0987: + "]code1 [" + code1
0988: + "] != code2 [" + code2
0989: + "]");
0990: return false;
0991: }
0992: }
0993: } else if ((value1 == null) && (value2 == null)) {
0994: // ok
0995: } else {
0996: // mismatch
0997: log.debug(title + "value1 [" + value1
0998: + "] != value2 [" + value2 + "]");
0999: return false;
1000: }
1001: }
1002: }
1003:
1004: return true;
1005:
1006: } else if ((map1 == null) && (map2 == null)) {
1007: return true;
1008: } else {
1009: log.debug(title
1010: + "mismatch: one or more of the maps are null. ");
1011: return false;
1012: }
1013:
1014: }
1015:
1016: private void showObjectGraphInfo(LinkedHashMap map) {
1017: if (map == null) {
1018: return;
1019: }
1020:
1021: Iterator it = map.keySet().iterator();
1022:
1023: while (it.hasNext()) {
1024: String metaClassName = (String) it.next();
1025: MetaDataEntry meta = (MetaDataEntry) map.get(metaClassName);
1026:
1027: if (meta != null) {
1028: String classname = meta.getClassName();
1029: String name = meta.getName();
1030: String hashcode = meta.getExtraName();
1031:
1032: log.debug("class[" + classname + "] id[" + name
1033: + "] hashcode" + hashcode + " ");
1034: }
1035:
1036: }
1037:
1038: }
1039:
1040: private boolean compareMCTable(OperationContext oc1,
1041: OperationContext oc2) {
1042: String title = "compareMCTable: ";
1043:
1044: if ((oc1 != null) && (oc2 != null)) {
1045: HashMap mcTable1 = oc1.getMessageContexts();
1046: HashMap mcTable2 = oc2.getMessageContexts();
1047:
1048: if ((mcTable1 != null) && (mcTable2 != null)) {
1049: if ((!mcTable1.isEmpty()) && (!mcTable2.isEmpty())) {
1050: int size1 = mcTable1.size();
1051: int size2 = mcTable2.size();
1052:
1053: if (size1 != size2) {
1054: log
1055: .debug(title
1056: + " Return FALSE: table sizes don't match size1["
1057: + size1 + "] != size2 ["
1058: + size2 + "] ");
1059: return false;
1060: }
1061:
1062: Iterator it1 = mcTable1.keySet().iterator();
1063:
1064: while (it1.hasNext()) {
1065: String key1 = (String) it1.next();
1066: MessageContext mc1 = (MessageContext) mcTable1
1067: .get(key1);
1068: MessageContext mc2 = (MessageContext) mcTable2
1069: .get(key1);
1070:
1071: if ((mc1 != null) && (mc2 != null)) {
1072: // check the IDs
1073: String id1 = mc1.getMessageID();
1074: String id2 = mc2.getMessageID();
1075:
1076: if ((id1 != null) && (id2 != null)) {
1077: if (!id1.equals(id2)) {
1078: log
1079: .debug(title
1080: + " Return FALSE: message IDs don't match id1["
1081: + id1
1082: + "] != id2 ["
1083: + id2 + "] ");
1084: return false;
1085: }
1086: } else if ((id1 == null) && (id2 == null)) {
1087: // can't tell, keep going
1088: } else {
1089: // mismatch
1090: log
1091: .debug(title
1092: + " Return FALSE: message IDs don't match id1["
1093: + id1 + "] != id2 ["
1094: + id2 + "] ");
1095: return false;
1096: }
1097:
1098: } else if ((mc1 == null) && (mc2 == null)) {
1099: // entries match
1100: } else {
1101: // mismatch
1102: log
1103: .debug(title
1104: + " Return FALSE: message context objects don't match ");
1105: return false;
1106: }
1107: }
1108:
1109: log
1110: .debug(title
1111: + " Return TRUE: message context tables match");
1112: return true;
1113:
1114: } else if (mcTable1.isEmpty() && mcTable2.isEmpty()) {
1115: log
1116: .debug(title
1117: + " Return TRUE: message context tables are both empty ");
1118: return true;
1119: } else {
1120: log
1121: .debug(title
1122: + " Return FALSE: message context tables mismatch");
1123: return false;
1124: }
1125: } else if ((mcTable1 == null) && (mcTable2 == null)) {
1126: log
1127: .debug(title
1128: + " Return TRUE: message context tables are null");
1129: return true;
1130: } else {
1131: log
1132: .debug(title
1133: + " Return FALSE: message context tables don't match");
1134: return false;
1135: }
1136: } else if ((oc1 == null) && (oc2 == null)) {
1137: log
1138: .debug(title
1139: + " Return TRUE: operation context objects are null ");
1140: return true;
1141: } else {
1142: log
1143: .debug(title
1144: + " Return FALSE: operation context objects don't match ");
1145: return false;
1146: }
1147:
1148: }
1149:
1150: private void showMCTable(OperationContext oc) {
1151: if (oc == null) {
1152: return;
1153: }
1154:
1155: HashMap mcTable = oc.getMessageContexts();
1156:
1157: if ((mcTable == null) || (mcTable.isEmpty())) {
1158: return;
1159: }
1160:
1161: Iterator it = mcTable.keySet().iterator();
1162:
1163: while (it.hasNext()) {
1164: String key = (String) it.next();
1165: MessageContext mc = (MessageContext) mcTable.get(key);
1166:
1167: if (mc != null) {
1168: String id = mc.getMessageID();
1169: log.debug("message context table entry: label ["
1170: + key + "] message ID [" + id + "] ");
1171: }
1172: }
1173:
1174: }
1175:
1176: /**
1177: * Gets the ID associated with the handler object.
1178: *
1179: * @param o The handler object
1180: * @return The ID associated with the handler,
1181: * -1 otherwise
1182: */
1183: private int getHandlerID(Object o) {
1184: int id = -1;
1185:
1186: if (o instanceof TempHandler) {
1187: id = ((TempHandler) o).getHandlerID();
1188: }
1189:
1190: return id;
1191: }
1192:
1193: //=========================================================================
1194: // Handler classes
1195: //=========================================================================
1196:
1197: /**
1198: * Pauses and saves the message context the message context
1199: */
1200: public class SaveHandler extends AbstractHandler {
1201: private Integer handlerID = null;
1202:
1203: private File theFile = null;
1204: private String theFilename = null;
1205:
1206: private boolean performSave = true;
1207:
1208: private boolean savedOk = false;
1209:
1210: //-----------------------------------------------------------------
1211: // constructors
1212: //-----------------------------------------------------------------
1213:
1214: public SaveHandler() {
1215: this .handlerID = new Integer(-5);
1216: }
1217:
1218: public SaveHandler(int index, File saveFile, boolean doIt) {
1219: this .handlerID = new Integer(index);
1220: init(new HandlerDescription(new String("handler" + index)));
1221: theFile = saveFile;
1222: performSave = doIt;
1223: }
1224:
1225: //-----------------------------------------------------------------
1226: // methods
1227: //-----------------------------------------------------------------
1228:
1229: public int getHandlerID() {
1230: if (handlerID != null) {
1231: return handlerID.intValue();
1232: }
1233:
1234: return -5;
1235: }
1236:
1237: public InvocationResponse invoke(MessageContext msgContext)
1238: throws AxisFault {
1239: String title = "SaveHandler[" + getHandlerID()
1240: + "]:invoke(): ";
1241: savedOk = false;
1242:
1243: if (performSave == false) {
1244: log.debug(title
1245: + "Configured for no action to be performed.");
1246: return InvocationResponse.CONTINUE;
1247: }
1248:
1249: log.debug(title + "msgContext.pause()");
1250: msgContext.pause();
1251:
1252: if (theFile != null) {
1253: try {
1254: log.debug(title + "Resetting the file to use.");
1255: theFile.delete();
1256: theFile.createNewFile();
1257: theFilename = theFile.getName();
1258: log.debug(title + "temp file = [" + theFilename
1259: + "]");
1260: } catch (Exception ex) {
1261: log.debug(title + "error creating new file = ["
1262: + ex.getMessage() + "]");
1263: }
1264:
1265: if (theFile.exists() == true) {
1266: // ---------------------------------------------------------
1267: // save to the temporary file
1268: // ---------------------------------------------------------
1269: try {
1270: // setup an output stream to a physical file
1271: FileOutputStream outStream = new FileOutputStream(
1272: theFile);
1273:
1274: // attach a stream capable of writing objects to the
1275: // stream connected to the file
1276: ObjectOutputStream outObjStream = new ObjectOutputStream(
1277: outStream);
1278:
1279: // try to save the message context
1280: log
1281: .debug(title
1282: + "saving message context.....");
1283: savedOk = false;
1284: outObjStream.writeObject(msgContext);
1285:
1286: // close out the streams
1287: outObjStream.flush();
1288: outObjStream.close();
1289: outStream.flush();
1290: outStream.close();
1291:
1292: savedOk = true;
1293: log.debug(title
1294: + "....saved message context.....");
1295:
1296: long filesize = theFile.length();
1297: log.debug(title + "file size after save ["
1298: + filesize + "] temp file = ["
1299: + theFilename + "]");
1300:
1301: } catch (Exception ex2) {
1302: log
1303: .debug(title
1304: + "error with saving message context = ["
1305: + ex2.getClass().getName()
1306: + " : " + ex2.getMessage()
1307: + "]");
1308: ex2.printStackTrace();
1309: }
1310:
1311: assertTrue(savedOk);
1312:
1313: }
1314: }
1315:
1316: log
1317: .debug(title + "executedHandlers.add(" + handlerID
1318: + ")");
1319: executedHandlers.add(handlerID);
1320:
1321: return InvocationResponse.SUSPEND;
1322:
1323: }
1324:
1325: }
1326:
1327: public class TempHandler extends AbstractHandler {
1328: private Integer handlerID = null;
1329: private int count = 0;
1330: private int numberProperties = 3;
1331: private String propertyKey = "Property";
1332: private String propertyValue = "ServiceLevelSetting";
1333:
1334: //-----------------------------------------------------------------
1335: // constructors
1336: //-----------------------------------------------------------------
1337:
1338: public TempHandler() {
1339: this .handlerID = new Integer(-5);
1340: }
1341:
1342: public TempHandler(int index) {
1343: this .handlerID = new Integer(index);
1344: init(new HandlerDescription(new String("handler" + index)));
1345: }
1346:
1347: public TempHandler(int index, int number) {
1348: this .handlerID = new Integer(index);
1349: init(new HandlerDescription(new String("handler" + index)));
1350: numberProperties = number;
1351: }
1352:
1353: //-----------------------------------------------------------------
1354: // methods
1355: //-----------------------------------------------------------------
1356:
1357: public int getHandlerID() {
1358: if (handlerID != null) {
1359: return handlerID.intValue();
1360: }
1361:
1362: return -5;
1363: }
1364:
1365: public InvocationResponse invoke(MessageContext msgContext)
1366: throws AxisFault {
1367: String title = "TempHandler[" + getHandlerID()
1368: + "]:invoke(): ";
1369:
1370: // get the service context from the message context
1371: ServiceContext serviceContext = msgContext
1372: .getServiceContext();
1373:
1374: if (serviceContext == null) {
1375: // get the service context from the operation context
1376: OperationContext operationContext = msgContext
1377: .getOperationContext();
1378: serviceContext = operationContext.getServiceContext();
1379: }
1380:
1381: if (serviceContext != null) {
1382: for (int j = 0; j < numberProperties; j++) {
1383: count++;
1384: String key = new String(propertyKey + ".ID["
1385: + getHandlerID() + "]." + count);
1386: String value = new String(propertyValue + "["
1387: + count + "]");
1388: serviceContext.setProperty(key, value);
1389: }
1390: }
1391:
1392: log
1393: .debug(title + "executedHandlers.add(" + handlerID
1394: + ")");
1395: executedHandlers.add(handlerID);
1396:
1397: return InvocationResponse.CONTINUE;
1398: }
1399:
1400: }
1401:
1402: }
|