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.jbi;
019:
020: import java.net.URL;
021: import java.util.logging.Logger;
022:
023: import javax.jbi.messaging.DeliveryChannel;
024: import javax.jbi.messaging.MessagingException;
025: import javax.xml.namespace.QName;
026: import javax.xml.ws.Endpoint;
027:
028: import org.apache.cxf.interceptor.LoggingInInterceptor;
029: import org.apache.cxf.interceptor.LoggingOutInterceptor;
030: import org.apache.cxf.jaxws.EndpointImpl;
031: import org.apache.cxf.jbi.se.CXFServiceEngine;
032: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
033: import org.apache.cxf.transport.ConduitInitiatorManager;
034: import org.apache.cxf.transport.jbi.JBITransportFactory;
035: import org.apache.hello_world.jbi.Greeter;
036: import org.apache.hello_world.jbi.GreeterImpl;
037: import org.apache.hello_world.jbi.HelloWorldService;
038: import org.apache.hello_world.jbi.PingMeFault;
039: import org.apache.servicemix.components.util.ComponentSupport;
040: import org.apache.servicemix.jbi.container.ActivationSpec;
041: import org.apache.servicemix.jbi.container.JBIContainer;
042: import org.junit.After;
043: import org.junit.Before;
044: import org.junit.BeforeClass;
045: import org.junit.Test;
046:
047: public class ClientServerTest extends AbstractBusClientServerTestBase {
048:
049: static final Logger LOG = Logger.getLogger(ClientServerTest.class
050: .getName());
051: private final QName serviceName = new QName(
052: "http://apache.org/hello_world/jbi", "HelloWorldService");
053: private JBIContainer container;
054:
055: @BeforeClass
056: public static void startServers() throws Exception {
057: //assertTrue("server did not launch correctly", launchServer(Server.class));
058: }
059:
060: @Before
061: public void setUp() throws Exception {
062: container = new JBIContainer();
063: container.setEmbedded(true);
064: container.init();
065: container.start();
066:
067: }
068:
069: @After
070: public void tearDown() throws Exception {
071: container.shutDown();
072: }
073:
074: @Test
075: public void testJBI() throws Exception {
076: URL wsdl = getClass().getResource("/wsdl/hello_world_jbi.wsdl");
077: assertNotNull(wsdl);
078: //Bus bus = BusFactory.getDefaultBus();
079: createBus();
080: assert bus != null;
081: TestComponent component = new TestComponent(new QName(
082: "http://apache.org/hello_world/jbi",
083: "HelloWorldService"), "endpoint");
084:
085: container.activateComponent(new ActivationSpec("component",
086: component));
087:
088: DeliveryChannel channel = component.getChannel();
089: JBITransportFactory jbiTransportFactory = (JBITransportFactory) bus
090: .getExtension(ConduitInitiatorManager.class)
091: .getConduitInitiator(CXFServiceEngine.JBI_TRANSPORT_ID);
092: jbiTransportFactory.setBus(bus);
093:
094: jbiTransportFactory.setDeliveryChannel(channel);
095: HelloWorldService ss = new HelloWorldService(wsdl, serviceName);
096:
097: Greeter port = ss.getSoapPort();
098: Object implementor = new GreeterImpl();
099: String address = "http://foo/bar/baz";
100: EndpointImpl e = (EndpointImpl) Endpoint.publish(address,
101: implementor);
102: e.getServer().getEndpoint().getInInterceptors().add(
103: new LoggingInInterceptor());
104: e.getServer().getEndpoint().getOutInterceptors().add(
105: new LoggingOutInterceptor());
106:
107: port.greetMeOneWay("test");
108: String rep = port.greetMe("ffang");
109: assertEquals(rep, "Hello ffang");
110: rep = port.sayHi();
111: assertEquals(rep, "Bonjour");
112: try {
113: port.pingMe();
114: fail();
115: } catch (PingMeFault ex) {
116: assertEquals(ex.getFaultInfo().getMajor(), (short) 2);
117: assertEquals(ex.getFaultInfo().getMinor(), (short) 1);
118: }
119: }
120:
121: public static class TestComponent extends ComponentSupport {
122: public TestComponent(QName service, String endpoint) {
123: super (service, endpoint);
124: }
125:
126: public DeliveryChannel getChannel() throws MessagingException {
127: return getContext().getDeliveryChannel();
128: }
129: }
130:
131: }
|