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.jca;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021: import java.net.URL;
022: import javax.resource.spi.ManagedConnection;
023: import javax.security.auth.Subject;
024: import javax.xml.namespace.QName;
025: import javax.xml.ws.Endpoint;
026: import javax.xml.ws.WebServiceException;
027:
028: import org.apache.cxf.connector.Connection;
029: import org.apache.cxf.jca.cxf.CXFConnectionRequestInfo;
030: import org.apache.cxf.jca.cxf.ManagedConnectionFactoryImpl;
031: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
032: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
033: import org.apache.hello_world_soap_http.Greeter;
034: import org.apache.hello_world_soap_http.GreeterImpl;
035: import org.apache.hello_world_soap_http.SOAPService;
036: import org.junit.BeforeClass;
037: import org.junit.Test;
038:
039: public class OutBoundConnectionTest extends
040: AbstractBusClientServerTestBase {
041: private final QName serviceName = new QName(
042: "http://apache.org/hello_world_soap_http", "SOAPService");
043:
044: private final QName portName = new QName(
045: "http://apache.org/hello_world_soap_http", "SoapPort");
046:
047: public static class Server extends AbstractBusTestServerBase {
048:
049: protected void run() {
050: Object implementor = new GreeterImpl();
051: String address = "http://localhost:9000/SoapContext/SoapPort";
052: Endpoint.publish(address, implementor);
053:
054: }
055:
056: public static void main(String[] args) {
057: try {
058: Server s = new Server();
059: s.start();
060: } catch (Exception ex) {
061: ex.printStackTrace();
062: System.exit(-1);
063: } finally {
064: System.out.println("done!");
065: }
066: }
067: }
068:
069: @BeforeClass
070: public static void startServers() throws Exception {
071: assertTrue("server did not launch correctly",
072: launchServer(Server.class));
073: }
074:
075: @Test
076: public void testBasicConnection() throws Exception {
077: URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
078: assertNotNull(wsdl);
079:
080: SOAPService service = new SOAPService(wsdl, serviceName);
081: assertNotNull(service);
082:
083: CXFConnectionRequestInfo cri = new CXFConnectionRequestInfo(
084: Greeter.class, wsdl, service.getServiceName(), portName);
085: ManagedConnectionFactoryImpl managedFactory = new ManagedConnectionFactoryImpl();
086: Subject subject = new Subject();
087: ManagedConnection mc = managedFactory.createManagedConnection(
088: subject, cri);
089: Object o = mc.getConnection(subject, cri);
090:
091: // test for the Object hash()
092: try {
093: o.hashCode();
094: o.toString();
095: } catch (WebServiceException ex) {
096: fail("The connection object should support Object method");
097: }
098:
099: assertTrue(
100: "returned connect does not implement Connection interface",
101: o instanceof Connection);
102: assertTrue(
103: "returned connect does not implement Connection interface",
104: o instanceof Greeter);
105:
106: Greeter greeter = (Greeter) o;
107:
108: String response = new String("Bonjour");
109: try {
110: for (int idx = 0; idx < 5; idx++) {
111: String reply = greeter.sayHi();
112: assertNotNull("no response received from service",
113: reply);
114: assertEquals(response, reply);
115: }
116: } catch (UndeclaredThrowableException ex) {
117: throw (Exception) ex.getCause();
118: }
119: }
120: }
|