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.xmlhttp.clientTests.dispatch.jaxb;
20:
21: import java.io.ByteArrayInputStream;
22:
23: import javax.xml.bind.JAXBContext;
24: import javax.xml.bind.JAXBException;
25: import javax.xml.namespace.QName;
26: import javax.xml.stream.XMLInputFactory;
27: import javax.xml.stream.XMLStreamReader;
28: import javax.xml.transform.Source;
29: import javax.xml.transform.stream.StreamSource;
30: import javax.xml.ws.Dispatch;
31: import javax.xml.ws.Service;
32: import javax.xml.ws.http.HTTPBinding;
33:
34: import org.apache.axis2.jaxws.message.util.Reader2Writer;
35: import org.apache.axis2.jaxws.TestLogger;
36:
37: import test.EchoString;
38: import test.EchoStringResponse;
39: import test.ObjectFactory;
40:
41: import junit.framework.TestCase;
42:
43: public class DispatchXPayloadJAXB extends TestCase {
44:
45: private static XMLInputFactory inputFactory = XMLInputFactory
46: .newInstance();
47:
48: public String HOSTPORT = "http://localhost:8080";
49:
50: private String ENDPOINT_URL = HOSTPORT
51: + "/axis2/services/XPayloadSourceProvider";
52: private QName SERVICE_NAME = new QName(
53: "http://ws.apache.org/axis2", "XPayloadSourceProvider");
54: private QName PORT_NAME = new QName("http://ws.apache.org/axis2",
55: "XPayloadSourceProviderPort");
56:
57: String XML_TEXT = "<p:echo xmlns:p=\"http://sample\">hello world</p:echo>";
58:
59: public Dispatch<Object> getDispatch() throws JAXBException {
60: Service service = Service.create(SERVICE_NAME);
61: service.addPort(PORT_NAME, HTTPBinding.HTTP_BINDING,
62: ENDPOINT_URL);
63: JAXBContext jbc = JAXBContext.newInstance("test");
64: Dispatch<Object> dispatch = service.createDispatch(PORT_NAME,
65: jbc, Service.Mode.PAYLOAD);
66: return dispatch;
67: }
68:
69: /**
70: * Simple XML/HTTP Message Test
71: * @throws Exception
72: */
73: public void testSimple() throws Exception {
74: Dispatch<Object> dispatch = getDispatch();
75: ObjectFactory factory = new ObjectFactory();
76: EchoString request = factory.createEchoString();
77: request.setInput("SYNC JAXB XML PAYLOAD TEST");
78:
79: // Invoke the Dispatch<Object>
80: TestLogger.logger
81: .debug(">> Invoking sync Dispatch with JAX-B Parameter");
82: EchoString response = (EchoString) dispatch.invoke(request);
83:
84: assertNotNull(response);
85:
86: TestLogger.logger.debug(">> Response content: "
87: + response.getInput());
88:
89: assertTrue("[ERROR] - Response object was null",
90: response != null);
91: assertTrue("[ERROR] - No content in response object", response
92: .getInput() != null);
93: assertTrue("[ERROR] - Zero length content in response",
94: response.getInput().length() > 0);
95: assertTrue(response.getInput().equals(request.getInput()));
96:
97: }
98: }
|