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.source;
20:
21: import java.io.ByteArrayInputStream;
22: import java.io.InputStream;
23:
24: import javax.xml.namespace.QName;
25: import javax.xml.stream.XMLInputFactory;
26: import javax.xml.stream.XMLStreamReader;
27: import javax.xml.transform.Source;
28: import javax.xml.transform.stream.StreamSource;
29: import javax.xml.ws.Dispatch;
30: import javax.xml.ws.Service;
31: import javax.xml.ws.http.HTTPBinding;
32:
33: import org.apache.axis2.jaxws.message.util.Reader2Writer;
34:
35: import junit.framework.TestCase;
36:
37: public class DispatchXMessageSource extends TestCase {
38:
39: private static XMLInputFactory inputFactory = XMLInputFactory
40: .newInstance();
41:
42: public String HOSTPORT = "http://localhost:8080";
43:
44: private String ENDPOINT_URL = HOSTPORT
45: + "/axis2/services/XMessageSourceProvider";
46: private QName SERVICE_NAME = new QName(
47: "http://ws.apache.org/axis2", "XMessageSourceProvider");
48: private QName PORT_NAME = new QName("http://ws.apache.org/axis2",
49: "XMessageSourceProviderPort");
50:
51: private static String XML_TEXT = "<p:echo xmlns:p=\"http://sample\">hello world</p:echo>";
52: private static String XML_TEXT_NPE = "<p:echo xmlns:p=\"http://sample\">NPE</p:echo>";
53:
54: public Dispatch<Source> getDispatch() {
55: Service service = Service.create(SERVICE_NAME);
56: service.addPort(PORT_NAME, HTTPBinding.HTTP_BINDING,
57: ENDPOINT_URL);
58: Dispatch<Source> dispatch = service.createDispatch(PORT_NAME,
59: Source.class, Service.Mode.MESSAGE);
60: return dispatch;
61: }
62:
63: /**
64: * Simple XML/HTTP Message Test
65: * @throws Exception
66: */
67: public void testSimple() throws Exception {
68: Dispatch<Source> dispatch = getDispatch();
69: String request = XML_TEXT;
70: ByteArrayInputStream stream = new ByteArrayInputStream(request
71: .getBytes());
72: Source inSource = new StreamSource((InputStream) stream);
73:
74: Source outSource = dispatch.invoke(inSource);
75:
76: // Prepare the response content for checking
77: XMLStreamReader reader = inputFactory
78: .createXMLStreamReader(outSource);
79: Reader2Writer r2w = new Reader2Writer(reader);
80: String response = r2w.getAsString();
81:
82: assertTrue(response != null);
83: assertTrue(request.equals(response));
84: }
85:
86: }
|