messagecontextsavebtest.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 918 行 · 第 1/3 页
JAVA
918 行
transportIn3 = new TransportInDescription("thebest");
transportIn.setReceiver(new SimpleHTTPServer());
transportIn2.setReceiver(new SimpleHTTPServer());
transportIn3.setReceiver(new SimpleHTTPServer());
axisConfiguration.addTransportIn(transportIn2);
axisConfiguration.addTransportIn(transportIn);
axisConfiguration.addTransportIn(transportIn3);
//----------------------------
// phase-related objects
//----------------------------
phase1 = new Phase("Phase1");
phase1.addHandler(new TempHandler(1, 2));
phase1.addHandler(new HandlerMCS(2, true));
phase1.addHandler(new TempHandler(3, 2));
ArrayList phases = new ArrayList();
phases.add(phase1);
axisConfiguration.setInPhasesUptoAndIncludingPostDispatch(phases);
//-----------------------------------------------------------------
// setup the axis side of the hierachy
//-----------------------------------------------------------------
// ABC group
//----------------------------
axisSrvGrp_ABC = new AxisServiceGroup(axisConfiguration);
axisSrvGrp_ABC.setServiceGroupName(serviceGroupName_ABC);
axisSrv_A = new AxisService(service_QName_A.getLocalPart());
axisSrv_B = new AxisService(service_QName_B.getLocalPart());
axisSrv_C = new AxisService(service_QName_C.getLocalPart());
axisSrvGrp_ABC.addService(axisSrv_A);
axisSrvGrp_ABC.addService(axisSrv_B);
axisSrvGrp_ABC.addService(axisSrv_C);
axisOp_A1 = new InOutAxisOperation(operation_QName_A1);
axisOp_A2 = new InOutAxisOperation(operation_QName_A2);
axisOp_A1.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisOp_A2.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisSrv_A.addOperation(axisOp_A1);
axisSrv_A.mapActionToOperation(operation_QName_A1.getLocalPart(), axisOp_A1);
axisSrv_A.addOperation(axisOp_A2);
axisSrv_A.mapActionToOperation(operation_QName_A2.getLocalPart(), axisOp_A2);
axisConfiguration.addService(axisSrv_A);
axisConfiguration.addService(axisSrv_B);
axisConfiguration.addService(axisSrv_C);
axisOp_A1.getRemainingPhasesInFlow().add(phase1);
axisOp_A2.getRemainingPhasesInFlow().add(phase1);
//----------------------------
// 123 group
//----------------------------
axisSrvGrp_123 = new AxisServiceGroup(axisConfiguration);
axisSrvGrp_123.setServiceGroupName(serviceGroupName_123);
axisSrv_1 = new AxisService(service_QName_1.getLocalPart());
axisSrv_2 = new AxisService(service_QName_2.getLocalPart());
axisSrv_3 = new AxisService(service_QName_3.getLocalPart());
axisSrv_4 = new AxisService(service_QName_4.getLocalPart());
axisSrvGrp_123.addService(axisSrv_1);
axisSrvGrp_123.addService(axisSrv_2);
axisSrvGrp_123.addService(axisSrv_3);
axisSrvGrp_123.addService(axisSrv_4);
axisOp_1_1 = new InOutAxisOperation(operation_QName_1_1);
axisOp_1_2 = new InOutAxisOperation(operation_QName_1_2);
axisOp_1_1.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisOp_1_2.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisSrv_1.addOperation(axisOp_1_1);
axisSrv_1.mapActionToOperation(operation_QName_1_1.getLocalPart(), axisOp_1_1);
axisSrv_1.addOperation(axisOp_1_2);
axisSrv_1.mapActionToOperation(operation_QName_1_2.getLocalPart(), axisOp_1_2);
axisConfiguration.addService(axisSrv_1);
axisConfiguration.addService(axisSrv_2);
axisConfiguration.addService(axisSrv_3);
axisConfiguration.addService(axisSrv_4);
axisOp_1_1.getRemainingPhasesInFlow().add(phase1);
axisOp_1_2.getRemainingPhasesInFlow().add(phase1);
//----------------------------
// DAY group
//----------------------------
axisSrvGrp_DAY = new AxisServiceGroup(axisConfiguration);
axisSrvGrp_DAY.setServiceGroupName(serviceGroupName_DAY);
axisSrv_Mon = new AxisService(service_QName_Mon.getLocalPart());
axisSrv_Tue = new AxisService(service_QName_Tue.getLocalPart());
axisSrv_Wed = new AxisService(service_QName_Wed.getLocalPart());
axisSrv_Thu = new AxisService(service_QName_Thu.getLocalPart());
axisSrv_Fri = new AxisService(service_QName_Fri.getLocalPart());
axisSrvGrp_DAY.addService(axisSrv_Mon);
axisSrvGrp_DAY.addService(axisSrv_Tue);
axisSrvGrp_DAY.addService(axisSrv_Wed);
axisSrvGrp_DAY.addService(axisSrv_Thu);
axisSrvGrp_DAY.addService(axisSrv_Fri);
axisOp_Mon_1 = new InOutAxisOperation(operation_QName_Mon_1);
axisOp_Mon_2 = new InOutAxisOperation(operation_QName_Mon_2);
axisOp_Mon_1.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisOp_Mon_2.setMessageReceiver(new MessageReceiver() {
public void receive(MessageContext messageCtx) {
}
});
axisSrv_Mon.addOperation(axisOp_Mon_1);
axisSrv_Mon.mapActionToOperation(operation_QName_Mon_1.getLocalPart(), axisOp_Mon_1);
axisSrv_Mon.addOperation(axisOp_Mon_2);
axisSrv_Mon.mapActionToOperation(operation_QName_Mon_2.getLocalPart(), axisOp_Mon_2);
axisConfiguration.addService(axisSrv_Mon);
axisConfiguration.addService(axisSrv_Tue);
axisConfiguration.addService(axisSrv_Wed);
axisConfiguration.addService(axisSrv_Thu);
axisConfiguration.addService(axisSrv_Fri);
axisOp_Mon_1.getRemainingPhasesInFlow().add(phase1);
axisOp_Mon_2.getRemainingPhasesInFlow().add(phase1);
//-----------------------------------------------------------------
// setup the context objects
//-----------------------------------------------------------------
srvGrpCtx_ABC = configurationContext.createServiceGroupContext(axisSrvGrp_ABC);
srvGrpCtx_ABC.setId(serviceGroupName_ABC);
srvGrpCtx_123 = configurationContext.createServiceGroupContext(axisSrvGrp_123);
srvGrpCtx_123.setId(serviceGroupName_ABC);
srvGrpCtx_DAY = configurationContext.createServiceGroupContext(axisSrvGrp_DAY);
srvGrpCtx_DAY.setId(serviceGroupName_DAY);
srvCtx_A = srvGrpCtx_ABC.getServiceContext(axisSrv_A);
srvCtx_B = srvGrpCtx_ABC.getServiceContext(axisSrv_B);
srvCtx_C = srvGrpCtx_ABC.getServiceContext(axisSrv_C);
srvCtx_1 = srvGrpCtx_123.getServiceContext(axisSrv_1);
srvCtx_2 = srvGrpCtx_123.getServiceContext(axisSrv_2);
srvCtx_3 = srvGrpCtx_123.getServiceContext(axisSrv_3);
srvCtx_4 = srvGrpCtx_123.getServiceContext(axisSrv_4);
srvCtx_Mon = srvGrpCtx_DAY.getServiceContext(axisSrv_Mon);
srvCtx_Tue = srvGrpCtx_DAY.getServiceContext(axisSrv_Tue);
srvCtx_Wed = srvGrpCtx_DAY.getServiceContext(axisSrv_Wed);
srvCtx_Thu = srvGrpCtx_DAY.getServiceContext(axisSrv_Thu);
srvCtx_Fri = srvGrpCtx_DAY.getServiceContext(axisSrv_Fri);
opCtx_A1 = srvCtx_A.createOperationContext(operation_QName_A1);
opCtx_A2 = srvCtx_A.createOperationContext(operation_QName_A2);
opCtx_1_1 = srvCtx_1.createOperationContext(operation_QName_1_1);
opCtx_1_2 = srvCtx_1.createOperationContext(operation_QName_1_2);
opCtx_Mon_1 = srvCtx_Mon.createOperationContext(operation_QName_Mon_1);
opCtx_Mon_2 = srvCtx_Mon.createOperationContext(operation_QName_Mon_2);
//----------------------------------------
// message context objects
//----------------------------------------
msgCtx_A1 = createMessageContext(opCtx_A1);
msgCtx_A2 = createMessageContext(opCtx_A2);
msgCtx_1_1 = createMessageContext(opCtx_1_1);
msgCtx_1_2 = createMessageContext(opCtx_1_2);
msgCtx_Mon_1 = createMessageContext(opCtx_Mon_1);
msgCtx_Mon_2 = createMessageContext(opCtx_Mon_2);
//-----------------------------------------------------------------
// other objects
//-----------------------------------------------------------------
executedHandlers = new ArrayList();
}
private MessageContext createMessageContext(OperationContext oc) throws Exception {
MessageContext mc = configurationContext.createMessageContext();
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 testServiceProperties() throws Exception {
String title = "MessageContextSaveBTest: testServiceProperties(): ";
AxisEngine engine = new AxisEngine(configurationContext);
MessageContext mc = msgCtx_1_1;
// add some service-level properties
String suffix = "_before";
addServiceProperties(mc, suffix);
// get the service level properties into a separate table
Map properties_original = new HashMap(getServiceProperties(mc));
showProperties(properties_original, "original properties");
log.debug(title + "start - - engine.receive(mc) - - - - - - - - - - - - - - - -");
engine.receive(mc);
// get the service level properties into a separate table
Map properties2 = new HashMap(getServiceProperties(restoredMessageContext));
showProperties(properties2, "restored properties");
// add some more properties
suffix = "_postReceive";
addServiceProperties(restoredMessageContext, suffix);
// resume the paused message context
log.debug(title + "resume - - engine.resume(mc) - - - - - - - - - - - - - - - -");
engine.resume(restoredMessageContext);
// get the service level properties into a separate table
Map properties3 = new HashMap(getServiceProperties(restoredMessageContext));
showProperties(properties3, "restored service properties post-resume");
// get the service level properties from the other message context
// in the same service
Map properties4 = getServiceProperties(msgCtx_1_2);
showProperties(properties4, "service properties from other active MsgCtx");
// the service level properties should be the same
boolean isOk = ObjectStateUtils.isEquivalent(properties3, properties4, true);
assertTrue(isOk);
}
private Map getServiceProperties(MessageContext mc) {
Map properties = null;
// get the service context from the message context
ServiceContext serviceContext = mc.getServiceContext();
if (serviceContext == null) {
// get the service context from the operation context
OperationContext operationContext = mc.getOperationContext();
serviceContext = operationContext.getServiceContext();
}
if (serviceContext != null) {
properties = serviceContext.getProperties();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?