001: /*
002: * Copyright 2004,2005 The Apache Software Foundation.
003: * Copyright 2007 International Business Machines Corp.
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.axis2.jaxws.provider;
018:
019: import javax.xml.ws.Service;
020: import javax.xml.namespace.QName;
021: import javax.xml.ws.soap.SOAPBinding;
022: import javax.xml.ws.BindingProvider;
023: import javax.xml.soap.SOAPMessage;
024: import junit.framework.TestCase;
025:
026: /**
027: * Tests Dispatch<SOAPMessage> client and a Provider<SOAPMessage> service
028: * with mustUnderstand attribute header.
029: */
030: public class SoapMessageMUProviderTests extends TestCase {
031: public static final QName serviceName = new QName(
032: "http://ws.apache.org/axis2",
033: "SoapMessageMUProviderService");
034: public static final QName portName = new QName(
035: "http://ws.apache.org/axis2",
036: "SimpleProviderServiceSOAP11port0");
037: public static final String endpointUrl = "http://localhost:8080/axis2/services/SoapMessageMUProviderService";
038:
039: public static final String bindingID = SOAPBinding.SOAP11HTTP_BINDING;
040: public static final Service.Mode mode = Service.Mode.MESSAGE;
041:
042: protected void setUp() throws Exception {
043: super .setUp();
044: }
045:
046: protected void tearDown() throws Exception {
047: super .tearDown();
048: }
049:
050: public SoapMessageMUProviderTests(String name) {
051: super (name);
052: }
053:
054: /**
055: * Test soap message with no MU headers
056: */
057: public void testNoMustUnderstandHeaders() {
058: System.out.println("testNoMustUnderstandHeaders");
059: // create a service
060: Service svc = Service.create(serviceName);
061: svc.addPort(portName, bindingID, endpointUrl);
062:
063: javax.xml.ws.Dispatch<SOAPMessage> dispatch = null;
064: dispatch = svc
065: .createDispatch(portName, SOAPMessage.class, mode);
066:
067: ((BindingProvider) dispatch).getRequestContext().put(
068: BindingProvider.SOAPACTION_USE_PROPERTY, true);
069: ((BindingProvider) dispatch).getRequestContext().put(
070: BindingProvider.SOAPACTION_URI_PROPERTY, "echoString");
071:
072: SOAPMessage message = AttachmentUtil
073: .toSOAPMessage(AttachmentUtil.msgEnvPlain);
074:
075: try {
076: SOAPMessage response = dispatch.invoke(message);
077:
078: String string = AttachmentUtil.toString(response);
079: assertTrue(string
080: .equalsIgnoreCase(AttachmentUtil.XML_HEADER
081: + AttachmentUtil.msgEnvPlain));
082: } catch (Exception e) {
083: fail("Unexpected Exception: " + e.getMessage());
084: }
085: }
086:
087: /**
088: * Test the mustUnderstand soap header attribute on the client's
089: * outbound soap message for headers that are not understood. Should cause an
090: * exception.
091: */
092: public void testClientRequestNotUnderstoodHeaders() {
093: System.out.println("testClientRequestNotUnderstoodHeaders");
094: // create a service
095: Service svc = Service.create(serviceName);
096: svc.addPort(portName, bindingID, endpointUrl);
097:
098: javax.xml.ws.Dispatch<SOAPMessage> dispatch = null;
099: dispatch = svc
100: .createDispatch(portName, SOAPMessage.class, mode);
101:
102: //force SOAPAction to match with wsdl action
103: ((BindingProvider) dispatch).getRequestContext().put(
104: BindingProvider.SOAPACTION_USE_PROPERTY, true);
105: ((BindingProvider) dispatch).getRequestContext().put(
106: BindingProvider.SOAPACTION_URI_PROPERTY, "echoString");
107:
108: SOAPMessage message = AttachmentUtil
109: .toSOAPMessage(AttachmentUtil.msgEnvMU);
110:
111: try {
112: dispatch.invoke(message);
113: fail("Should have received fault for not understood headers on request");
114: } catch (Exception e) {
115: // Expected path
116: }
117: }
118:
119: /**
120: * Test the mustUnderstand soap header attribute on the server's
121: * outbound soap message (i.e. the inbound response to the client) for headers that
122: * are not understood. Should cause an exception.
123: */
124: public void testClientResponseNotUnderstoodHeaders() {
125: System.out.println("testClientResponseNotUnderstoodHeaders");
126: // create a service
127: Service svc = Service.create(serviceName);
128: svc.addPort(portName, bindingID, endpointUrl);
129:
130: javax.xml.ws.Dispatch<SOAPMessage> dispatch = null;
131: dispatch = svc
132: .createDispatch(portName, SOAPMessage.class, mode);
133:
134: //force SOAPAction to match with wsdl action
135: ((BindingProvider) dispatch).getRequestContext().put(
136: BindingProvider.SOAPACTION_USE_PROPERTY, true);
137: ((BindingProvider) dispatch).getRequestContext().put(
138: BindingProvider.SOAPACTION_URI_PROPERTY, "echoString");
139:
140: SOAPMessage message = AttachmentUtil
141: .toSOAPMessage(AttachmentUtil.msgEnv);
142:
143: try {
144: dispatch.invoke(message);
145: fail("Should have received fault for not understood headers on response");
146: } catch (Exception e) {
147: // Expected path
148: }
149: }
150:
151: /**
152: * Test the mustUnderstand soap header attribute on the client's
153: * outbound soap message for headers that should be understood. Should not cause an
154: * exception.
155: */
156: public void testClientRequestUnderstoodHeaders() {
157: System.out.println("testClientRequestUnderstoodHeaders");
158: // create a service
159: Service svc = Service.create(serviceName);
160: svc.addPort(portName, bindingID, endpointUrl);
161:
162: javax.xml.ws.Dispatch<SOAPMessage> dispatch = null;
163: dispatch = svc
164: .createDispatch(portName, SOAPMessage.class, mode);
165:
166: //force SOAPAction to match with wsdl action
167: ((BindingProvider) dispatch).getRequestContext().put(
168: BindingProvider.SOAPACTION_USE_PROPERTY, true);
169: ((BindingProvider) dispatch).getRequestContext().put(
170: BindingProvider.SOAPACTION_URI_PROPERTY, "echoString");
171:
172: SOAPMessage message = AttachmentUtil
173: .toSOAPMessage(AttachmentUtil.msgEnvMU_understood);
174:
175: try {
176: dispatch.invoke(message);
177: } catch (Exception e) {
178: fail("Should not have received fault for headers that were understood. "
179: + e.getMessage());
180: }
181: }
182:
183: /**
184: * Test the mustUnderstand soap header attribute on the server's
185: * outbound soap message (i.e. the inbound response to the client) for headers that
186: * are understood. Should not cause an exception.
187: */
188: public void testClientResponseUnderstoodHeaders() {
189: System.out.println("testClientResponseUnderstoodHeaders");
190: // create a service
191: Service svc = Service.create(serviceName);
192: svc.addPort(portName, bindingID, endpointUrl);
193:
194: javax.xml.ws.Dispatch<SOAPMessage> dispatch = null;
195: dispatch = svc
196: .createDispatch(portName, SOAPMessage.class, mode);
197:
198: //force SOAPAction to match with wsdl action
199: ((BindingProvider) dispatch).getRequestContext().put(
200: BindingProvider.SOAPACTION_USE_PROPERTY, true);
201: ((BindingProvider) dispatch).getRequestContext().put(
202: BindingProvider.SOAPACTION_URI_PROPERTY, "echoString");
203:
204: SOAPMessage message = AttachmentUtil
205: .toSOAPMessage(AttachmentUtil.msgEnv_understood);
206:
207: try {
208: dispatch.invoke(message);
209: } catch (Exception e) {
210: fail("Should not have received fault for headers that were understood. "
211: + e.getMessage());
212: }
213: }
214: }
|