handlerexecutiontest.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 428 行 · 第 1/2 页
JAVA
428 行
//This odd pattern of CIn FCCIn CIn FCCIn is caused by the InOutAxisOperation always executing the inflow phases, even if there was a fault (and then executing the infaulflow)
List expectedExecutionState = Arrays.asList(new String[] { "COut1", "COut2", "COut3", "In1",
"In2", "In3", "In4", "In5", "In6", "FCIn6", "FCIn5", "FCIn4", "FCIn3", "FCIn2",
"FCIn1", "FCCOut3", "FCCOut2", "FCCOut1", "CIn1", "CIn2", "CIn3", "FCCIn3",
"FCCIn2", "FCCIn1", "CIn1", "CIn2", "CIn3", "FCCIn3", "FCCIn2", "FCCIn1" });
//TODO : Need to fix the this test case
// assertEquals(expectedExecutionState, testResults);
}
public void testServersideHandlerFailureInInboundOperationSpecificPhase() throws Exception {
System.out.println("Starting testServersideHandlerFailureInInboundOperationSpecificPhase");
middleOperationInHandler.shouldFail(true);
try {
executeClient();
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] { "In1", "In2", "In3", "In4",
"kaboom", "FCIn4", "FCIn3", "FCIn2", "FCIn1" });
assertEquals(expectedExecutionState, testResults);
middleOperationInHandler.shouldFail(false);
}
public void testServersideHandlerFailureInInboundOperationSpecificPhaseWithFirstHandler()
throws Exception {
System.out.println("Starting testServersideHandlerFailureInOutboundPhaseWithFirstHandler");
firstOperationInHandler.shouldFail(true);
try {
executeClient();
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(
new String[] { "In1", "In2", "In3", "kaboom", "FCIn3", "FCIn2", "FCIn1" });
assertEquals(expectedExecutionState, testResults);
firstOperationInHandler.shouldFail(false);
}
public void testServersideHandlerFailureInInboundGlobalPhase() throws Exception {
System.out.println("Starting testServersideHandlerFailureInGlobalPhase");
middleGlobalInHandler.shouldFail(true);
try {
executeClient();
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] {"In1", "kaboom","FCIn1"});
assertEquals(expectedExecutionState, testResults);
middleGlobalInHandler.shouldFail(false);
}
public void testServersideHandlerFailureInOutboundPhase() throws Exception {
System.out.println("Starting testServersideHandlerFailureInOutboundPhase");
middleOperationOutHandler.shouldFail(true);
try {
executeClient();
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] { "In1", "In2", "In3", "In4",
"In5", "In6", "Out1", "kaboom", "FCOut1", "FCIn6", "FCIn5", "FCIn4", "FCIn3",
"FCIn2", "FCIn1" });
assertEquals(expectedExecutionState, testResults);
middleOperationOutHandler.shouldFail(false);
}
public void testClientsideHandlerFailureInOutboundPhaseWithFirstHandler() throws Exception {
System.out.println("Starting testClientsideHandlerFailureInOutboundPhaseWithFirstHandler");
OMElement payload = TestingUtils.createDummyOMElement();
ServiceClient sender = createClient();
AxisOperation operation =
sender.getAxisService().getOperation(ServiceClient.ANON_OUT_IN_OP);
ArrayList operationSpecificPhases = new ArrayList();
operationSpecificPhases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
operation.setPhasesOutFlow(operationSpecificPhases);
ArrayList phaseList = operation.getPhasesOutFlow();
for (int i = 0; i < phaseList.size(); i++) {
Phase operationSpecificPhase = (Phase)phaseList.get(i);
if (PhaseMetadata.PHASE_POLICY_DETERMINATION
.equals(operationSpecificPhase.getPhaseName())) {
//phase1.addHandler(new TestHandler("COut1"));
TestHandler clientOutboundHandler = new TestHandler("COut1");
clientOutboundHandler.shouldFail(true);
operationSpecificPhase.addHandler(clientOutboundHandler);
//phase1.addHandler(clientOutboundHandler);
}
}
try {
OMElement result = sender.sendReceive(payload);
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] { "kaboom" });
assertEquals(expectedExecutionState, testResults);
}
public void testClientsideHandlerFailureInOutboundPhase() throws Exception {
System.out.println("Starting testClientsideHandlerFailureInOutboundPhase");
OMElement payload = TestingUtils.createDummyOMElement();
ServiceClient sender = createClient();
AxisOperation operation =
sender.getAxisService().getOperation(ServiceClient.ANON_OUT_IN_OP);
ArrayList operationSpecificPhases = new ArrayList();
operationSpecificPhases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
operation.setPhasesOutFlow(operationSpecificPhases);
ArrayList phaseList = operation.getPhasesOutFlow();
for (int i = 0; i < phaseList.size(); i++) {
Phase operationSpecificPhase = (Phase)phaseList.get(i);
if (PhaseMetadata.PHASE_POLICY_DETERMINATION
.equals(operationSpecificPhase.getPhaseName())) {
operationSpecificPhase.addHandler(new TestHandler("COut1"));
TestHandler clientOutboundHandler = new TestHandler("COut2");
clientOutboundHandler.shouldFail(true);
operationSpecificPhase.addHandler(clientOutboundHandler);
operationSpecificPhase.addHandler(new TestHandler("COut3"));
}
}
try {
OMElement result = sender.sendReceive(payload);
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] { "COut1", "kaboom", "FCCOut1" });
assertEquals(expectedExecutionState, testResults);
}
public void testClientsideHandlerFailureInInboundOperationSpecificPhase() throws Exception {
System.out.println("Starting testClientsideHandlerFailureInInboundOperationSpecific");
OMElement payload = TestingUtils.createDummyOMElement();
ServiceClient sender = createClient();
AxisOperation operation =
sender.getAxisService().getOperation(ServiceClient.ANON_OUT_IN_OP);
ArrayList operationSpecificPhases = new ArrayList();
operationSpecificPhases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
operation.setRemainingPhasesInFlow(operationSpecificPhases);
ArrayList phaseList = operation.getRemainingPhasesInFlow();
for (int i = 0; i < phaseList.size(); i++) {
Phase operationSpecificPhase = (Phase)phaseList.get(i);
if (PhaseMetadata.PHASE_POLICY_DETERMINATION
.equals(operationSpecificPhase.getPhaseName())) {
operationSpecificPhase.addHandler(new TestHandler("CIn1"));
TestHandler clientOutboundHandler = new TestHandler("CIn2");
clientOutboundHandler.shouldFail(true);
operationSpecificPhase.addHandler(clientOutboundHandler);
operationSpecificPhase.addHandler(new TestHandler("CIn3"));
}
}
try {
OMElement result = sender.sendReceive(payload);
fail("An expected handler failure did not occur");
}
catch (AxisFault e) {
}
List expectedExecutionState = Arrays.asList(new String[] { "In1", "In2", "In3", "In4",
"In5", "In6", "Out1", "Out2", "Out3", "FCOut3", "FCOut2", "FCOut1", "FCIn6",
"FCIn5", "FCIn4", "FCIn3", "FCIn2", "FCIn1", "CIn1", "kaboom", "FCCIn1" });
assertEquals(expectedExecutionState, testResults);
}
private class TestHandler extends AbstractHandler {
private String handlerName;
private boolean shouldFail;
private boolean shouldPause;
public TestHandler(String handlerName) {
this.handlerName = handlerName;
}
public void shouldFail(boolean fail) {
this.shouldFail = fail;
}
public void shouldPause(boolean pause) {
this.shouldPause = pause;
}
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
System.out.println("TestHandler " + handlerName + " invoked");
if (shouldFail) {
testResults.add("kaboom");
System.out.println("Handler went kaboom");
throw new AxisFault("Handler failed");
}
testResults.add(handlerName);
return InvocationResponse.CONTINUE;
}
public void flowComplete(MessageContext msgContext) {
System.out.println("TestHandler " + handlerName + " called for flowComplete()");
testResults.add("FC" + handlerName);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?