01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.provider;
20:
21: import javax.xml.namespace.QName;
22: import javax.xml.ws.BindingProvider;
23: import javax.xml.ws.Dispatch;
24: import javax.xml.ws.Service;
25: import javax.xml.ws.soap.SOAPBinding;
26:
27: import junit.framework.TestCase;
28:
29: /**
30: *
31: */
32: public class SOAPFaultProviderTests extends TestCase {
33: public QName portName = new QName("http://ws.apache.org/axis2",
34: "SimpleProviderServiceSOAP11port0");
35: private QName serviceName = new QName("http://ws.apache.org/axis2",
36: "StringProviderService");
37:
38: String endpointUrl = "http://localhost:8080/axis2/services/StringProviderService";
39:
40: private static final String sampleSoapEnvelopeHeader = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
41: + "<soap:Body>";
42:
43: private static final String sampleSoapEnvelopeFooter = "</soap:Body>"
44: + "</soap:Envelope>";
45:
46: private static final String soapFaultBodyContent = "<soap:Fault>"
47: + "<faultcode>soap:SOAPFaultProviderTests</faultcode>"
48: + "<faultstring>WSA-CP2-GENERATED-FAULT: FAULT01</faultstring>"
49: + "</soap:Fault>";
50:
51: public SOAPFaultProviderTests(String name) {
52: super (name);
53: }
54:
55: private Dispatch<String> getDispatch() {
56: Service svc = Service.create(serviceName);
57: svc.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
58: endpointUrl);
59:
60: // Use Message mode so we can build up the entire SOAP envelope containing the fault
61: Dispatch<String> dispatch = svc.createDispatch(portName,
62: String.class, Service.Mode.MESSAGE);
63:
64: // Force soap action because we are passing junk over the wire
65: dispatch.getRequestContext().put(
66: BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
67: dispatch.getRequestContext().put(
68: BindingProvider.SOAPACTION_URI_PROPERTY,
69: "http://stringprovider.sample.test.org/echoString");
70:
71: return dispatch;
72: }
73:
74: public void testFault() {
75: System.out.println("---------------------------------------");
76: System.out.println("test: " + getName());
77:
78: Dispatch<String> dispatch = getDispatch();
79: String request = sampleSoapEnvelopeHeader
80: + soapFaultBodyContent + sampleSoapEnvelopeFooter;
81: // Test that a Provider receives the full fault. If not, it will throw an exception
82: try {
83: String response = dispatch.invoke(request);
84: } catch (Exception e) {
85: fail("Caught unexpected exception " + e.toString());
86: }
87: }
88:
89: }
|