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.ws.rm;
019:
020: import java.util.logging.Logger;
021:
022: import javax.xml.ws.Endpoint;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.BusFactory;
026: import org.apache.cxf.bus.spring.SpringBusFactory;
027: import org.apache.cxf.greeter_control.Greeter;
028: import org.apache.cxf.greeter_control.GreeterService;
029: import org.apache.cxf.interceptor.LoggingInInterceptor;
030: import org.apache.cxf.interceptor.LoggingOutInterceptor;
031: import org.apache.cxf.systest.ws.util.ConnectionHelper;
032: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
033: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
034: import org.junit.BeforeClass;
035: import org.junit.Test;
036:
037: /**
038: * Tests the addition of WS-RM properties to application messages and the
039: * exchange of WS-RM protocol messages.
040: */
041: public class DecoupledClientServerTest extends
042: AbstractBusClientServerTestBase {
043:
044: private static final Logger LOG = Logger
045: .getLogger(DecoupledClientServerTest.class.getName());
046: private Bus bus;
047:
048: public static class Server extends AbstractBusTestServerBase {
049:
050: protected void run() {
051: SpringBusFactory bf = new SpringBusFactory();
052: Bus bus = bf
053: .createBus("/org/apache/cxf/systest/ws/rm/decoupled.xml");
054: BusFactory.setDefaultBus(bus);
055: LoggingInInterceptor in = new LoggingInInterceptor();
056: bus.getInInterceptors().add(in);
057: bus.getInFaultInterceptors().add(in);
058: LoggingOutInterceptor out = new LoggingOutInterceptor();
059: bus.getOutInterceptors().add(out);
060: bus.getOutFaultInterceptors().add(out);
061:
062: GreeterImpl implementor = new GreeterImpl();
063: implementor.useLastOnewayArg(true);
064: implementor.setDelay(5000);
065: String address = "http://localhost:9020/SoapContext/GreeterPort";
066: Endpoint.publish(address, implementor);
067: LOG.info("Published greeter endpoint.");
068: }
069:
070: public static void main(String[] args) {
071: try {
072: Server s = new Server();
073: s.start();
074: } catch (Exception ex) {
075: ex.printStackTrace();
076: System.exit(-1);
077: } finally {
078: System.out.println("done!");
079: }
080: }
081: }
082:
083: @BeforeClass
084: public static void startServers() throws Exception {
085: assertTrue("server did not launch correctly",
086: launchServer(Server.class));
087: }
088:
089: @Test
090: public void testDecoupled() throws Exception {
091: SpringBusFactory bf = new SpringBusFactory();
092: bus = bf
093: .createBus("/org/apache/cxf/systest/ws/rm/decoupled.xml");
094: BusFactory.setDefaultBus(bus);
095: LoggingInInterceptor in = new LoggingInInterceptor();
096: bus.getInInterceptors().add(in);
097: bus.getInFaultInterceptors().add(in);
098: LoggingOutInterceptor out = new LoggingOutInterceptor();
099: bus.getOutInterceptors().add(out);
100: bus.getOutFaultInterceptors().add(out);
101:
102: GreeterService gs = new GreeterService();
103: final Greeter greeter = gs.getGreeterPort();
104: LOG.fine("Created greeter client.");
105:
106: ConnectionHelper.setKeepAliveConnection(greeter, true);
107:
108: class TwowayThread extends Thread {
109:
110: String response;
111:
112: @Override
113: public void run() {
114: response = greeter.greetMe("twoway");
115: }
116:
117: }
118:
119: TwowayThread t = new TwowayThread();
120: t.start();
121:
122: // allow for partial response to twoway request to arrive
123:
124: long wait = 3000;
125: while (wait > 0) {
126: long start = System.currentTimeMillis();
127: try {
128: Thread.sleep(wait);
129: } catch (InterruptedException ex) {
130: // ignore
131: }
132: wait -= System.currentTimeMillis() - start;
133: }
134:
135: greeter.greetMeOneWay("oneway");
136:
137: t.join();
138: assertEquals("Unexpected response to twoway request", "oneway",
139: t.response);
140:
141: }
142: }
|