messagecontextsavectest.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,277 行 · 第 1/4 页

JAVA
1,277
字号
        phases_Restore.add(phaseRestore);

        restoreAxisConfiguration.setInPhasesUptoAndIncludingPostDispatch(phases_Restore);

        phaseEquiv = new Phase("PhaseTest");
        phaseEquiv.addHandler(new TempHandler(1, 1));
        phaseEquiv.addHandler(new SaveHandler(2, persistentStore, true));
        phaseEquiv.addHandler(new TempHandler(3, 1));

        ArrayList phases_Equiv = new ArrayList();
        phases_Equiv.add(phaseEquiv);

        equivAxisConfiguration.setInPhasesUptoAndIncludingPostDispatch(phases_Equiv);

        //-----------------------------------------------------------------
        // setup the axis side of the hierachy
        //-----------------------------------------------------------------
        // ABC group
        //----------------------------

        axisSrvGrp_ABC_save = new AxisServiceGroup(saveAxisConfiguration);
        axisSrvGrp_ABC_save.setServiceGroupName(serviceGroupName_ABC);

        axisSrv_A_save = new AxisService(service_QName_A.getLocalPart());
        axisSrv_B_save = new AxisService(service_QName_B.getLocalPart());
        axisSrv_C_save = new AxisService(service_QName_C.getLocalPart());

        axisSrvGrp_ABC_save.addService(axisSrv_A_save);
        axisSrvGrp_ABC_save.addService(axisSrv_B_save);
        axisSrvGrp_ABC_save.addService(axisSrv_C_save);

        axisOp_A1_save = new InOutAxisOperation(operation_QName_A1);
        axisOp_A2_save = new InOutAxisOperation(operation_QName_A2);

        axisOp_A1_save.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisOp_A2_save.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisSrv_A_save.addOperation(axisOp_A1_save);
        axisSrv_A_save.mapActionToOperation(operation_QName_A1.getLocalPart(), axisOp_A1_save);

        axisSrv_A_save.addOperation(axisOp_A2_save);
        axisSrv_A_save.mapActionToOperation(operation_QName_A2.getLocalPart(), axisOp_A2_save);

        saveAxisConfiguration.addService(axisSrv_A_save);
        saveAxisConfiguration.addService(axisSrv_B_save);
        saveAxisConfiguration.addService(axisSrv_C_save);

        //---------------------

        axisSrvGrp_ABC_restore = new AxisServiceGroup(restoreAxisConfiguration);
        axisSrvGrp_ABC_restore.setServiceGroupName(serviceGroupName_ABC);

        axisSrv_A_restore = new AxisService(service_QName_A.getLocalPart());
        axisSrv_B_restore = new AxisService(service_QName_B.getLocalPart());
        axisSrv_C_restore = new AxisService(service_QName_C.getLocalPart());

        axisSrvGrp_ABC_restore.addService(axisSrv_A_restore);
        axisSrvGrp_ABC_restore.addService(axisSrv_B_restore);
        axisSrvGrp_ABC_restore.addService(axisSrv_C_restore);

        axisOp_A1_restore = new InOutAxisOperation(operation_QName_A1);
        axisOp_A2_restore = new InOutAxisOperation(operation_QName_A2);

        axisOp_A1_restore.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisOp_A2_restore.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisSrv_A_restore.addOperation(axisOp_A1_restore);
        axisSrv_A_restore
                .mapActionToOperation(operation_QName_A1.getLocalPart(), axisOp_A1_restore);

        axisSrv_A_restore.addOperation(axisOp_A2_restore);
        axisSrv_A_restore
                .mapActionToOperation(operation_QName_A2.getLocalPart(), axisOp_A2_restore);


        restoreAxisConfiguration.addService(axisSrv_A_restore);
        restoreAxisConfiguration.addService(axisSrv_B_restore);
        restoreAxisConfiguration.addService(axisSrv_C_restore);


        axisOp_A1_save.getRemainingPhasesInFlow().add(phaseSave);
        axisOp_A2_save.getRemainingPhasesInFlow().add(phaseSave);

        axisOp_A1_restore.getRemainingPhasesInFlow().add(phaseRestore);
        axisOp_A2_restore.getRemainingPhasesInFlow().add(phaseRestore);

        //-------------------------------

        axisSrvGrp_ABC_equiv = new AxisServiceGroup(equivAxisConfiguration);
        axisSrvGrp_ABC_equiv.setServiceGroupName(serviceGroupName_ABC);

        axisSrv_A_equiv = new AxisService(service_QName_A.getLocalPart());
        axisSrv_B_equiv = new AxisService(service_QName_B.getLocalPart());
        axisSrv_C_equiv = new AxisService(service_QName_C.getLocalPart());

        axisSrvGrp_ABC_equiv.addService(axisSrv_A_equiv);
        axisSrvGrp_ABC_equiv.addService(axisSrv_B_equiv);
        axisSrvGrp_ABC_equiv.addService(axisSrv_C_equiv);

        axisOp_A1_equiv = new InOutAxisOperation(operation_QName_A1);
        axisOp_A2_equiv = new InOutAxisOperation(operation_QName_A2);

        axisOp_A1_equiv.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisOp_A2_equiv.setMessageReceiver(new MessageReceiver() {
            public void receive(MessageContext messageCtx) {
            }
        });

        axisSrv_A_equiv.addOperation(axisOp_A1_equiv);
        axisSrv_A_equiv.mapActionToOperation(operation_QName_A1.getLocalPart(), axisOp_A1_equiv);

        axisSrv_A_equiv.addOperation(axisOp_A2_equiv);
        axisSrv_A_equiv.mapActionToOperation(operation_QName_A2.getLocalPart(), axisOp_A2_equiv);

        equivAxisConfiguration.addService(axisSrv_A_equiv);
        equivAxisConfiguration.addService(axisSrv_B_equiv);
        equivAxisConfiguration.addService(axisSrv_C_equiv);

        //-----------------------------------------------------------------
        // setup the context objects
        //-----------------------------------------------------------------
        srvGrpCtx_ABC_save = saveConfigurationContext.createServiceGroupContext(axisSrvGrp_ABC_save);
        srvGrpCtx_ABC_save.setId(serviceGroupName_ABC);

        srvCtx_A_save = srvGrpCtx_ABC_save.getServiceContext(axisSrv_A_save);
        srvCtx_B_save = srvGrpCtx_ABC_save.getServiceContext(axisSrv_B_save);
        srvCtx_C_save = srvGrpCtx_ABC_save.getServiceContext(axisSrv_C_save);

        opCtx_A1_save = srvCtx_A_save.createOperationContext(operation_QName_A1);
        opCtx_A2_save = srvCtx_A_save.createOperationContext(operation_QName_A2);

        //----------------------------------------

        srvGrpCtx_ABC_equiv =
                equivConfigurationContext.createServiceGroupContext(axisSrvGrp_ABC_equiv);
        srvGrpCtx_ABC_equiv.setId(serviceGroupName_ABC);

        srvCtx_A_equiv = srvGrpCtx_ABC_equiv.getServiceContext(axisSrv_A_equiv);
        srvCtx_B_equiv = srvGrpCtx_ABC_equiv.getServiceContext(axisSrv_B_equiv);
        srvCtx_C_equiv = srvGrpCtx_ABC_equiv.getServiceContext(axisSrv_C_equiv);

        opCtx_A1_equiv = srvCtx_A_equiv.createOperationContext(operation_QName_A1);
        opCtx_A2_equiv = srvCtx_A_equiv.createOperationContext(operation_QName_A2);

        //----------------------------------------
        // message context objects
        //----------------------------------------
        msgCtx_A1_1_save = createMessageContext(opCtx_A1_save, saveConfigurationContext,
                                                MessageContext.IN_FLOW);
        msgCtx_A1_2_save = createMessageContext(opCtx_A1_save, saveConfigurationContext,
                                                MessageContext.OUT_FLOW);
        msgCtx_A2_save = createMessageContext(opCtx_A2_save, saveConfigurationContext,
                                              MessageContext.IN_FLOW);

        msgCtx_A1_1_equiv = createMessageContext(opCtx_A1_equiv, equivConfigurationContext,
                                                 MessageContext.IN_FLOW);
        msgCtx_A1_2_equiv = createMessageContext(opCtx_A1_equiv, equivConfigurationContext,
                                                 MessageContext.OUT_FLOW);
        msgCtx_A2_equiv = createMessageContext(opCtx_A2_equiv, equivConfigurationContext,
                                               MessageContext.IN_FLOW);

        //-----------------------------------------------------------------
        // other objects
        //-----------------------------------------------------------------
        executedHandlers = new ArrayList();
    }


    private MessageContext createMessageContext(OperationContext oc, ConfigurationContext cc,
                                                int flowType) throws Exception {
        MessageContext mc = cc.createMessageContext();

        mc.setFLOW(flowType);
        mc.setTransportIn(transportIn);
        mc.setTransportOut(transportOut);

        mc.setServerSide(true);
//        mc.setProperty(MessageContext.TRANSPORT_OUT, System.out);

        SOAPFactory omFac = OMAbstractFactory.getSOAP11Factory();
        mc.setEnvelope(omFac.getDefaultEnvelope());

        AxisOperation axisOperation = oc.getAxisOperation();
        String action = axisOperation.getName().getLocalPart();
        mc.setSoapAction(action);
//        System.out.flush();

        mc.setMessageID(UUIDGenerator.getUUID());

        axisOperation.registerOperationContext(mc, oc);
        mc.setOperationContext(oc);

        ServiceContext sc = oc.getServiceContext();
        mc.setServiceContext(sc);

        mc.setTo(new EndpointReference("axis2/services/NullService"));
        mc.setWSAAction("DummyOp");

        AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        mc.setAxisMessage(axisMessage);

        return mc;
    }

    protected void setUp() throws Exception {
        //org.apache.log4j.BasicConfigurator.configure();
    }

    public void testHierarchyNewContext() throws Exception {
        String title = "MessageContextSaveCTest:testHierarchyNewContext(): ";

        AxisEngine engineSave = new AxisEngine(saveConfigurationContext);

        MessageContext mc = msgCtx_A1_2_save;
        OperationContext oc = mc.getOperationContext();
        log.debug(title + "*** Original OperationContext message context table ****");
        showMCTable(oc);

        // run the message through the message processing
        // this causes the message context to get saved 
        log.debug(title + "- - - Save the message context from the engine - - - -");
        engineSave.receive(mc);

        LinkedHashMap original_object_graph = getObjectGraphInfo(mc);
        log.debug(title + "*** Originial object graph ****");
        showObjectGraphInfo(original_object_graph);

        log.debug(title +
                "- - - Restore the message context on a separate engine  - - - - - - - - - - - - - - - -");
        AxisEngine engineRestore = new AxisEngine(restoreConfigurationContext);
        MessageContext mc2 = restoreMessageContext(persistentStore, restoreConfigurationContext);

        LinkedHashMap restored_object_graph = getObjectGraphInfo(mc2);
        log.debug(title + "*** Restored object graph ****");
        showObjectGraphInfo(restored_object_graph);

        OperationContext oc2 = mc2.getOperationContext();
        log.debug(title + "*** Restored OperationContext message context table ****");
        showMCTable(oc2);

        boolean mcTableMatch = compareMCTable(oc, oc2);
        assertTrue(mcTableMatch);

        // resume the restored paused message context on an engine that has the 
        // same setup as the engine where the save occurred
        // but doesn't have the Context objects
        log.debug(title +
                "- - - Resume the restored message context - - - - - - - - - - - - - - - -");
        engineRestore.resume(mc2);

        LinkedHashMap resumed_object_graph = getObjectGraphInfo(mc2);
        log.debug(title + "*** Post Resumed object graph ****");
        showObjectGraphInfo(resumed_object_graph);

        // compare object hashcodes - expect differences
        boolean expectFalse =
                compareObjectGraphInfo(original_object_graph, restored_object_graph, true);
        assertFalse(expectFalse);

        boolean expectSameObjectIds =
                compareObjectGraphInfo(original_object_graph, restored_object_graph, false);
        assertTrue(expectSameObjectIds);

        boolean isSame = compareObjectGraphInfo(restored_object_graph, resumed_object_graph, false);
        assertTrue(isSame);

    }

    public void testHierarchyReuse() throws Exception {
        String title = "MessageContextSaveCTest:testHierarchyReuse(): ";

        AxisEngine engineSave = new AxisEngine(saveConfigurationContext);

        MessageContext mc = msgCtx_A1_1_save;

        // run the message through the message processing
        // this causes the message context to get saved 
        log.debug(title + "- - - Save the message context from the engine - - - -");
        engineSave.receive(mc);

        LinkedHashMap original_object_graph = getObjectGraphInfo(mc);
        log.debug(title + "*** Originial object graph ****");
        showObjectGraphInfo(original_object_graph);

        log.debug(title +
                "- - - Restore the message context on a separate engine  - - - - - - - - - - - - - - - -");
        AxisEngine engineEquiv = new AxisEngine(equivConfigurationContext);
        MessageContext mc2 = restoreMessageContext(persistentStore, equivConfigurationContext);

        LinkedHashMap restored_object_graph = getObjectGraphInfo(mc2);
        log.debug(title + "*** Restored object graph ****");
        showObjectGraphInfo(restored_object_graph);

        // we don't use strict checking here since the engine where the 
        // restoration takes place is a "copy", ie, there are new objects
        // for the same names/identifications
        boolean hasEquivalence =
                compareObjectGraphInfo(original_object_graph, restored_object_graph, false);
        assertTrue(hasEquivalence);

        // get an object graph from an equivalent message context on the separate engine
        // we would expect a strict match of the object graphs between the 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?