001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxws.header;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021: import java.net.URL;
022: import javax.xml.namespace.QName;
023: import javax.xml.ws.Endpoint;
024: import javax.xml.ws.Holder;
025:
026: import org.apache.cxf.BusFactory;
027: import org.apache.cxf.interceptor.LoggingInInterceptor;
028: import org.apache.cxf.interceptor.LoggingOutInterceptor;
029: import org.apache.cxf.jaxws.AbstractJaxWsTest;
030: import org.apache.cxf.jaxws.EndpointImpl;
031: import org.apache.header_test.SOAPHeaderService;
032: import org.apache.header_test.TestHeader;
033: import org.apache.header_test.TestHeaderImpl;
034: import org.apache.header_test.rpc.SOAPRPCHeaderService;
035: import org.apache.header_test.rpc.TestRPCHeader;
036: import org.apache.header_test.rpc.TestRPCHeaderImpl;
037: import org.apache.header_test.rpc.types.HeaderMessage;
038: import org.apache.header_test.types.TestHeader1;
039: import org.apache.header_test.types.TestHeader1Response;
040: import org.apache.header_test.types.TestHeader2;
041: import org.apache.header_test.types.TestHeader2Response;
042: import org.apache.header_test.types.TestHeader3;
043: import org.apache.header_test.types.TestHeader3Response;
044: import org.apache.header_test.types.TestHeader5;
045: import org.apache.header_test.types.TestHeader5ResponseBody;
046: import org.apache.header_test.types.TestHeader6;
047: import org.apache.header_test.types.TestHeader6Response;
048: import org.apache.tests.type_test.all.SimpleAll;
049: import org.apache.tests.type_test.choice.SimpleChoice;
050: import org.apache.tests.type_test.sequence.SimpleStruct;
051: import org.junit.Before;
052: import org.junit.Test;
053:
054: public class HeaderClientServerTest extends AbstractJaxWsTest {
055: private final QName serviceName = new QName(
056: "http://apache.org/header_test", "SOAPHeaderService");
057: private final QName portName = new QName(
058: "http://apache.org/header_test", "SoapHeaderPort");
059:
060: @Before
061: public void setUp() throws Exception {
062: BusFactory.setDefaultBus(getBus());
063:
064: Object implementor = new TestHeaderImpl();
065: String address = "http://localhost:9104/SoapHeaderContext/SoapHeaderPort";
066: EndpointImpl e = (EndpointImpl) Endpoint.publish(address,
067: implementor);
068: e.getServer().getEndpoint().getInInterceptors().add(
069: new LoggingInInterceptor());
070: e.getServer().getEndpoint().getOutInterceptors().add(
071: new LoggingOutInterceptor());
072:
073: implementor = new TestRPCHeaderImpl();
074: address = "http://localhost:9104/SoapHeaderRPCContext/SoapHeaderRPCPort";
075: e = (EndpointImpl) Endpoint.publish(address, implementor);
076: e.getServer().getEndpoint().getInInterceptors().add(
077: new LoggingInInterceptor());
078: e.getServer().getEndpoint().getOutInterceptors().add(
079: new LoggingOutInterceptor());
080: }
081:
082: @Test
083: public void testInHeader() throws Exception {
084: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
085: assertNotNull(wsdl);
086:
087: SOAPHeaderService service = new SOAPHeaderService(wsdl,
088: serviceName);
089: assertNotNull(service);
090: TestHeader proxy = service.getPort(portName, TestHeader.class);
091: try {
092: TestHeader1 val = new TestHeader1();
093: for (int idx = 0; idx < 2; idx++) {
094: TestHeader1Response returnVal = proxy.testHeader1(val,
095: val);
096: assertNotNull(returnVal);
097: assertEquals(TestHeader1.class.getSimpleName(),
098: returnVal.getResponseType());
099: }
100: } catch (UndeclaredThrowableException ex) {
101: throw (Exception) ex.getCause();
102: }
103: }
104:
105: @Test
106: public void testOutHeader() throws Exception {
107: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
108: assertNotNull(wsdl);
109:
110: SOAPHeaderService service = new SOAPHeaderService(wsdl,
111: serviceName);
112: assertNotNull(service);
113: TestHeader proxy = service.getPort(portName, TestHeader.class);
114: try {
115: TestHeader2 in = new TestHeader2();
116: String val = new String(TestHeader2Response.class
117: .getSimpleName());
118: Holder<TestHeader2Response> out = new Holder<TestHeader2Response>();
119: Holder<TestHeader2Response> outHeader = new Holder<TestHeader2Response>();
120: for (int idx = 0; idx < 2; idx++) {
121: val += idx;
122: in.setRequestType(val);
123: proxy.testHeader2(in, out, outHeader);
124:
125: assertEquals(val, out.value.getResponseType());
126: assertEquals(val, outHeader.value.getResponseType());
127: }
128: } catch (UndeclaredThrowableException ex) {
129: ex.printStackTrace();
130: throw (Exception) ex.getCause();
131: }
132: }
133:
134: @Test
135: public void testInOutHeader() throws Exception {
136: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
137: assertNotNull(wsdl);
138:
139: SOAPHeaderService service = new SOAPHeaderService(wsdl,
140: serviceName);
141: assertNotNull(service);
142: TestHeader proxy = service.getPort(portName, TestHeader.class);
143:
144: try {
145: TestHeader3 in = new TestHeader3();
146: String val = new String(TestHeader3.class.getSimpleName());
147: Holder<TestHeader3> inoutHeader = new Holder<TestHeader3>();
148: for (int idx = 0; idx < 2; idx++) {
149: val += idx;
150: in.setRequestType(val);
151: inoutHeader.value = new TestHeader3();
152: TestHeader3Response returnVal = proxy.testHeader3(in,
153: inoutHeader);
154: //inoutHeader copied to return
155: //in copied to inoutHeader
156: assertNotNull(returnVal);
157: assertNull(returnVal.getResponseType());
158: assertEquals(val, inoutHeader.value.getRequestType());
159:
160: in.setRequestType(null);
161: inoutHeader.value.setRequestType(val);
162: returnVal = proxy.testHeader3(in, inoutHeader);
163: assertNotNull(returnVal);
164: assertEquals(val, returnVal.getResponseType());
165: assertNull(inoutHeader.value.getRequestType());
166: }
167: } catch (UndeclaredThrowableException ex) {
168: throw (Exception) ex.getCause();
169: }
170: }
171:
172: @Test
173: public void testReturnHeader() throws Exception {
174: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
175: assertNotNull(wsdl);
176:
177: SOAPHeaderService service = new SOAPHeaderService(wsdl,
178: serviceName);
179: assertNotNull(service);
180: TestHeader proxy = service.getPort(portName, TestHeader.class);
181: try {
182: Holder<TestHeader5ResponseBody> out = new Holder<TestHeader5ResponseBody>();
183: Holder<TestHeader5> outHeader = new Holder<TestHeader5>();
184: TestHeader5 in = new TestHeader5();
185: String val = new String(TestHeader5.class.getSimpleName());
186: for (int idx = 0; idx < 2; idx++) {
187: val += idx;
188: in.setRequestType(val);
189: proxy.testHeader5(out, outHeader, in);
190: assertEquals(1000, out.value.getResponseType());
191: assertEquals(val, outHeader.value.getRequestType());
192: }
193: } catch (UndeclaredThrowableException ex) {
194: throw (Exception) ex.getCause();
195: }
196: }
197:
198: @Test
199: public void testHeaderPartBeforeBodyPart() throws Exception {
200: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
201: assertNotNull(wsdl);
202:
203: SOAPHeaderService service = new SOAPHeaderService(wsdl,
204: serviceName);
205: assertNotNull(service);
206: TestHeader proxy = service.getPort(portName, TestHeader.class);
207:
208: TestHeader6 in = new TestHeader6();
209: String val = new String(TestHeader6.class.getSimpleName());
210: Holder<TestHeader3> inoutHeader = new Holder<TestHeader3>();
211: for (int idx = 0; idx < 1; idx++) {
212: val += idx;
213: in.setRequestType(val);
214: inoutHeader.value = new TestHeader3();
215: TestHeader6Response returnVal = proxy
216: .testHeaderPartBeforeBodyPart(inoutHeader, in);
217: //inoutHeader copied to return
218: //in copied to inoutHeader
219: assertNotNull(returnVal);
220: assertNull(returnVal.getResponseType());
221: assertEquals(val, inoutHeader.value.getRequestType());
222:
223: in.setRequestType(null);
224: inoutHeader.value.setRequestType(val);
225: returnVal = proxy.testHeaderPartBeforeBodyPart(inoutHeader,
226: in);
227: assertNotNull(returnVal);
228: assertEquals(val, returnVal.getResponseType());
229: assertNull(inoutHeader.value.getRequestType());
230: }
231: }
232:
233: @Test
234: public void testHeader4() {
235: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
236: assertNotNull(wsdl);
237:
238: SOAPHeaderService service = new SOAPHeaderService(wsdl,
239: serviceName);
240: assertNotNull(service);
241: TestHeader proxy = service.getPort(portName, TestHeader.class);
242: try {
243: proxy.testHeader4("cxf");
244: } catch (Exception e) {
245: // REVISIT
246: // fail("No exception should happen in testHeader4");
247: }
248: }
249:
250: @Test
251: public void testRPCInHeader() throws Exception {
252: URL wsdl = getClass().getResource("/wsdl/soapheader_rpc.wsdl");
253: assertNotNull(wsdl);
254:
255: SOAPRPCHeaderService service = new SOAPRPCHeaderService(wsdl,
256: new QName("http://apache.org/header_test/rpc",
257: "SOAPRPCHeaderService"));
258: assertNotNull(service);
259: TestRPCHeader proxy = service.getSoapRPCHeaderPort();
260: try {
261: HeaderMessage header = new HeaderMessage();
262: header.setHeaderVal("header");
263:
264: for (int idx = 0; idx < 2; idx++) {
265: String returnVal = proxy.testHeader1("part", header);
266: assertNotNull(returnVal);
267: assertEquals("part/header", returnVal);
268: }
269: } catch (UndeclaredThrowableException ex) {
270: throw (Exception) ex.getCause();
271: }
272: }
273:
274: @Test
275: public void testRPCInOutHeader() throws Exception {
276: URL wsdl = getClass().getResource("/wsdl/soapheader_rpc.wsdl");
277: assertNotNull(wsdl);
278:
279: SOAPRPCHeaderService service = new SOAPRPCHeaderService(wsdl,
280: new QName("http://apache.org/header_test/rpc",
281: "SOAPRPCHeaderService"));
282: assertNotNull(service);
283: TestRPCHeader proxy = service.getSoapRPCHeaderPort();
284: try {
285: HeaderMessage header = new HeaderMessage();
286: Holder<HeaderMessage> holder = new Holder<HeaderMessage>(
287: header);
288:
289: for (int idx = 0; idx < 2; idx++) {
290: holder.value.setHeaderVal("header" + idx);
291: String returnVal = proxy.testInOutHeader("part" + idx,
292: holder);
293:
294: assertNotNull(returnVal);
295: assertEquals("header" + idx, returnVal);
296: assertEquals("part" + idx, holder.value.getHeaderVal());
297: }
298: } catch (UndeclaredThrowableException ex) {
299: throw (Exception) ex.getCause();
300: }
301: }
302:
303: @Test
304: public void testHolderOutIsTheFirstMessagePart() throws Exception {
305: URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
306: assertNotNull(wsdl);
307: SOAPHeaderService service = new SOAPHeaderService(wsdl,
308: serviceName);
309: assertNotNull(service);
310: TestHeader proxy = service.getPort(portName, TestHeader.class);
311: Holder<SimpleAll> simpleAll = new Holder<SimpleAll>();
312: SimpleAll sa = new SimpleAll();
313: sa.setVarAttrString("varAttrString");
314: sa.setVarInt(100);
315: sa.setVarString("varString");
316: simpleAll.value = sa;
317: SimpleChoice sc = new SimpleChoice();
318: sc.setVarString("scVarString");
319: SimpleStruct ss = proxy.sendReceiveAnyType(simpleAll, sc);
320: assertEquals(simpleAll.value.getVarString(), "scVarString");
321: assertEquals(ss.getVarInt(), 200);
322: assertEquals(ss.getVarAttrString(), "varAttrStringRet");
323: }
324:
325: }
|