KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > HandlerFailureTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.axis2.engine;
18
19 //todo
20

21 import junit.framework.TestCase;
22 import org.apache.axis2.Constants;
23 import org.apache.axis2.addressing.AddressingConstants;
24 import org.apache.axis2.addressing.EndpointReference;
25 import org.apache.axis2.context.MessageContext;
26 import org.apache.axis2.description.Flow;
27 import org.apache.axis2.description.FlowImpl;
28 import org.apache.axis2.description.ServiceDescription;
29 import org.apache.axis2.handlers.AbstractHandler;
30 import org.apache.axis2.integration.UtilServer;
31 import org.apache.axis2.om.OMAbstractFactory;
32 import org.apache.axis2.om.OMElement;
33 import org.apache.axis2.om.OMNamespace;
34 import org.apache.axis2.om.OMOutput;
35 import org.apache.axis2.phaseresolver.PhaseMetadata;
36 import org.apache.axis2.soap.SOAPFactory;
37 import org.apache.axis2.transport.http.SimpleHTTPServer;
38 import org.apache.axis2.util.Utils;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42 import javax.xml.namespace.QName JavaDoc;
43 import javax.xml.stream.XMLOutputFactory;
44
45
46 public class HandlerFailureTest extends TestCase {
47     private Log log = LogFactory.getLog(getClass());
48     private static final String JavaDoc SERVICE_NAME = "EchoXMLService";
49     private static final String JavaDoc OPERATION_NAME = "echoOMElement";
50     
51     
52     private static final String JavaDoc ADDRESS = "http://127.0.0.1:" + (UtilServer.TESTING_PORT) +
53             "/axis/services/" + SERVICE_NAME + "/" +OPERATION_NAME;
54 // private static final String ADDRESS = "http://127.0.0.1:8080/axis/services/" + SERVICE_NAME;
55
private EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO, ADDRESS);
56     private QName JavaDoc serviceName = new QName JavaDoc("", SERVICE_NAME);
57     //private QName serviceName = new QName("", targetEPR.getValue());
58

59     private QName JavaDoc operationName = new QName JavaDoc(OPERATION_NAME);
60
61
62     private MessageContext mc;
63     private Thread JavaDoc thisThread;
64     private SimpleHTTPServer sas;
65
66     public HandlerFailureTest() {
67         super(HandlerFailureTest.class.getName());
68     }
69
70     public HandlerFailureTest(String JavaDoc testName) {
71         super(testName);
72     }
73
74     protected void setUp() throws Exception JavaDoc {
75     }
76
77
78     public void testFailureAtServerRequestFlow() throws Exception JavaDoc {
79         Flow flow = new FlowImpl();
80         Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
81         Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
82         Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
83         Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
84         Utils.addHandler(flow, culprit,PhaseMetadata.PHASE_POLICY_DETERMINATION);
85         Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
86         
87         ServiceDescription service = Utils.createSimpleService(serviceName,Echo.class.getName(),operationName);
88         service.setInFlow(flow);
89         
90         UtilServer.start();
91         UtilServer.deployService(service);
92         try {
93             callTheService();
94         } finally {
95             UtilServer.unDeployService(serviceName);
96             UtilServer.stop();
97         }
98     }
99
100 // public void testFailureAtServerResponseFlow() throws Exception {
101
// ServiceDescription service = Utils.createSimpleService(serviceName,org.apache.axis2.engine.Echo.class.getName(),operationName);
102
//
103
//
104
// Flow flow = new FlowImpl();
105
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
106
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
107
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
108
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
109
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
110
// service.setInFlow(flow);
111
//
112
//
113
// flow = new FlowImpl();
114
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
115
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
116
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
117
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
118
// Utils.addHandler(flow, culprit,PhaseMetadata.PHASE_POLICY_DETERMINATION);
119
// Utils.addHandler(flow, new SpeakingHandler(),PhaseMetadata.PHASE_POLICY_DETERMINATION);
120
// service.setInFlow(flow);
121
//
122
// OperationDescription operation = new OperationDescription(operationName);
123
// service.addOperation(operation);
124
//
125
// UtilServer.start();
126
// UtilServer.deployService(service);
127
// try {
128
// callTheService();
129
// } finally {
130
// UtilServer.unDeployService(serviceName);
131
// UtilServer.stop();
132
// }
133
// }
134

135
136     protected void tearDown() throws Exception JavaDoc {
137
138     }
139
140
141     private void callTheService() throws Exception JavaDoc {
142         try {
143             SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
144                             
145             OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
146             OMElement method = fac.createOMElement("echoOMElement", omNs);
147             OMElement value = fac.createOMElement("myValue", omNs);
148             value.setText("Isaac Assimov, the foundation Sega");
149             method.addChild(value);
150
151             org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
152             //EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO, "http://127.0.0.1:" + Utils.TESTING_PORT + "/axis/services/EchoXMLService");
153

154             call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false);
155             call.setTo(targetEPR);
156             OMElement result = call.invokeBlocking(operationName.getLocalPart(),method);
157             OMOutput omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out));
158             result.serialize(omOutput);
159            omOutput.flush();
160             fail("the test must fail due to bad service Name");
161         } catch (AxisFault e) {
162             e.printStackTrace();
163             assertTrue((e.getMessage().indexOf(UtilServer.FAILURE_MESSAGE)) > 0);
164             return;
165         }
166
167     }
168
169     private Handler culprit = new AbstractHandler() {
170         public void invoke(MessageContext msgContext) throws AxisFault {
171             throw new AxisFault(UtilServer.FAILURE_MESSAGE);
172         }
173     };
174 }
175
176
Popular Tags