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.systest.multitransport;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021: import java.net.URL;
022: import java.util.HashMap;
023: import java.util.Map;
024: import java.util.logging.Logger;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.ws.Endpoint;
028:
029: import org.apache.cxf.systest.jms.EmbeddedJMSBrokerLauncher;
030: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
031: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
032: import org.apache.hello_world_doc_lit.Greeter;
033: import org.apache.hello_world_doc_lit.HTTPGreeterImpl;
034: import org.apache.hello_world_doc_lit.JMSGreeterImpl;
035: import org.apache.hello_world_doc_lit.MultiTransportService;
036: import org.apache.hello_world_doc_lit.PingMeFault;
037: import org.junit.BeforeClass;
038: import org.junit.Test;
039:
040: public class MultiTransportClientServerTest extends
041: AbstractBusClientServerTestBase {
042: static final Logger LOG = Logger
043: .getLogger(MultiTransportClientServerTest.class.getName());
044: private final QName serviceName = new QName(
045: "http://apache.org/hello_world_doc_lit",
046: "MultiTransportService");
047:
048: public static class MyServer extends AbstractBusTestServerBase {
049:
050: protected void run() {
051: Object implementor = new HTTPGreeterImpl();
052: String address = "http://localhost:9001/SOAPDocLitService/SoapPort";
053: Endpoint.publish(address, implementor);
054: implementor = new JMSGreeterImpl();
055: Endpoint.publish(null, implementor);
056: }
057:
058: public static void main(String[] args) {
059: try {
060: MyServer s = new MyServer();
061: s.start();
062: } catch (Exception ex) {
063: ex.printStackTrace();
064: System.exit(-1);
065: } finally {
066: LOG.info("done!");
067: }
068: }
069: }
070:
071: @BeforeClass
072: public static void startServers() throws Exception {
073: Map<String, String> props = new HashMap<String, String>();
074: if (System.getProperty("activemq.store.dir") != null) {
075: props.put("activemq.store.dir", System
076: .getProperty("activemq.store.dir"));
077: }
078: props.put("java.util.logging.config.file", System
079: .getProperty("java.util.logging.config.file"));
080:
081: assertTrue("server did not launch correctly", launchServer(
082: EmbeddedJMSBrokerLauncher.class, props, null));
083:
084: assertTrue("server did not launch correctly",
085: launchServer(MyServer.class));
086:
087: }
088:
089: // the purpose of this test shows how one service include two ports with different
090: // transport work
091: @Test
092: public void testMultiTransportInOneService() throws Exception {
093:
094: QName portName1 = new QName(
095: "http://apache.org/hello_world_doc_lit", "HttpPort");
096: QName portName2 = new QName(
097: "http://apache.org/hello_world_doc_lit", "JMSPort");
098: URL wsdl = getClass().getResource(
099: "/wsdl/hello_world_doc_lit.wsdl");
100: assertNotNull(wsdl);
101:
102: MultiTransportService service = new MultiTransportService(wsdl,
103: serviceName);
104: assertNotNull(service);
105:
106: String response1 = new String("Hello Milestone-");
107: String response2 = new String("Bonjour");
108: try {
109: Greeter greeter = service.getPort(portName1, Greeter.class);
110: for (int idx = 0; idx < 5; idx++) {
111: String greeting = greeter.greetMe("Milestone-" + idx);
112: assertNotNull("no response received from service",
113: greeting);
114: String exResponse = response1 + idx;
115: assertEquals(exResponse, greeting);
116:
117: String reply = greeter.sayHi();
118: assertNotNull("no response received from service",
119: reply);
120: assertEquals(response2, reply);
121:
122: try {
123: greeter.pingMe();
124: fail("Should have thrown FaultException");
125: } catch (PingMeFault ex) {
126: assertNotNull(ex.getFaultInfo());
127: }
128:
129: }
130:
131: greeter = service.getPort(portName2, Greeter.class);
132: for (int idx = 0; idx < 5; idx++) {
133: String greeting = greeter.greetMe("Milestone-" + idx);
134: assertNotNull("no response received from service",
135: greeting);
136: String exResponse = response1 + idx;
137: assertEquals(exResponse, greeting);
138:
139: String reply = greeter.sayHi();
140: assertNotNull("no response received from service",
141: reply);
142: assertEquals(response2, reply);
143:
144: try {
145: greeter.pingMe();
146: fail("Should have thrown FaultException");
147: } catch (PingMeFault ex) {
148: assertNotNull(ex.getFaultInfo());
149: }
150:
151: }
152:
153: } catch (UndeclaredThrowableException ex) {
154: throw (Exception) ex.getCause();
155: }
156: }
157:
158: }
|