Search in sources :

Example 1 with ResolveMatchType

use of org.apache.cxf.ws.discovery.wsdl.ResolveMatchType in project jbossws-cxf by jbossws.

the class WSDiscoveryTestCase method testProbeAndResolve.

@Test
@RunAsClient
public void testProbeAndResolve() throws Exception {
    Bus bus = null;
    try {
        bus = BusFactory.newInstance().createBus();
        WSDiscoveryClient client = new WSDiscoveryClient(bus);
        ProbeType pt = new ProbeType();
        ScopesType scopes = new ScopesType();
        pt.setScopes(scopes);
        final String serverHost = getServerHost().replace("127.0.0.1", "localhost");
        final int serverPort = getServerPort();
        List<ProbeMatchType> pmts = client.probe(pt, TIMEOUT).getProbeMatch();
        assertFalse("There must be some services discovered, check that you have allowed UDP broadcast on port 3072", pmts.isEmpty());
        List<ProbeMatchType> pmtsForHost = filterProbeMatchesForHost(pmts, serverHost);
        assertFalse("There must be some services discovered for current host " + serverHost + ", found only " + dbgProbeMatchTypeList(pmts), pmtsForHost.isEmpty());
        List<ResolveMatchType> rmts = new LinkedList<ResolveMatchType>();
        for (ProbeMatchType pmt : pmtsForHost) {
            W3CEndpointReference epr = pmt.getEndpointReference();
            ResolveMatchType rmt = client.resolve(epr, TIMEOUT);
            assertNotNull("Could not resolve (timeout = " + TIMEOUT + " ms) reference: " + epr, rmt);
            rmts.add(rmt);
        }
        final QName typeName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsdd", "ServiceIface");
        checkResolveMatches(rmts, "http://" + serverHost + ":" + serverPort + "/jaxws-samples-wsdd/WSDDService", typeName);
        checkResolveMatches(rmts, "http://" + serverHost + ":" + serverPort + "/jaxws-samples-wsdd2/WSDDService", typeName);
        checkResolveMatches(rmts, "http://" + serverHost + ":" + serverPort + "/jaxws-samples-wsdd2/AnotherWSDDService", typeName);
        client.close();
    } finally {
        bus.shutdown(true);
    }
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) Bus(org.apache.cxf.Bus) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) QName(javax.xml.namespace.QName) LinkedList(java.util.LinkedList) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType) ResolveMatchType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchType) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) WSDiscoveryClient(org.apache.cxf.ws.discovery.WSDiscoveryClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 2 with ResolveMatchType

use of org.apache.cxf.ws.discovery.wsdl.ResolveMatchType in project cxf by apache.

the class WSDiscoveryClientTest method main.

// this is a standalone test
public static void main(String[] arg) throws Exception {
    try {
        Bus bus = BusFactory.getDefaultBus();
        Endpoint ep = Endpoint.publish("http://localhost:51919/Foo/Snarf", new FooImpl());
        WSDiscoveryServiceImpl service = new WSDiscoveryServiceImpl(bus);
        service.startup();
        // this service will just generate an error.  However, the probes should still
        // work to probe the above stuff.
        WSDiscoveryServiceImpl s2 = new WSDiscoveryServiceImpl() {

            public ProbeMatchesType handleProbe(ProbeType pt) {
                throw new RuntimeException("Error!!!");
            }
        };
        s2.startup();
        HelloType h = service.register(ep.getEndpointReference());
        bus = BusFactory.newInstance().createBus();
        WSDiscoveryClient c = new WSDiscoveryClient(bus);
        c.setVersion10();
        System.out.println("1");
        ProbeType pt = new ProbeType();
        ScopesType scopes = new ScopesType();
        pt.setScopes(scopes);
        ProbeMatchesType pmts = c.probe(pt, 1000);
        System.out.println("2");
        if (pmts != null) {
            for (ProbeMatchType pmt : pmts.getProbeMatch()) {
                System.out.println("Found " + pmt.getEndpointReference());
                System.out.println(pmt.getTypes());
                System.out.println(pmt.getXAddrs());
            }
        }
        if (pmts.getProbeMatch().isEmpty()) {
            System.exit(0);
        }
        pmts = c.probe(pt);
        System.out.println("Size:" + pmts.getProbeMatch().size());
        System.out.println("3");
        W3CEndpointReference ref = null;
        if (pmts != null) {
            for (ProbeMatchType pmt : pmts.getProbeMatch()) {
                ref = pmt.getEndpointReference();
                System.out.println("Found " + pmt.getEndpointReference());
                System.out.println(pmt.getTypes());
                System.out.println(pmt.getXAddrs());
            }
        }
        ResolveMatchType rmt = c.resolve(ref);
        System.out.println("Resolved " + rmt.getEndpointReference());
        System.out.println(rmt.getTypes());
        System.out.println(rmt.getXAddrs());
        service.unregister(h);
        System.out.println("4");
        c.close();
        System.exit(0);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) Bus(org.apache.cxf.Bus) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) WSDiscoveryServiceImpl(org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType) ResolveMatchType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchType) Endpoint(javax.xml.ws.Endpoint) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType)

Example 3 with ResolveMatchType

use of org.apache.cxf.ws.discovery.wsdl.ResolveMatchType in project jbossws-cxf by jbossws.

the class WSDiscoveryTestCase method testInvocation.

@Test
@RunAsClient
public void testInvocation() throws Exception {
    Bus bus = null;
    try {
        bus = BusFactory.newInstance().createBus();
        WSDiscoveryClient client = new WSDiscoveryClient(bus);
        ProbeType pt = new ProbeType();
        ScopesType scopes = new ScopesType();
        pt.setScopes(scopes);
        final String serverHost = getServerHost().replace("127.0.0.1", "localhost");
        List<ProbeMatchType> pmts = client.probe(pt, TIMEOUT).getProbeMatch();
        assertFalse("There must be some services discovered, check that you have allowed UDP broadcast on port 3072", pmts.isEmpty());
        List<ProbeMatchType> pmtsForHost = filterProbeMatchesForHost(pmts, serverHost.replace("127.0.0.1", "localhost"));
        assertFalse("There must be some services discovered for current host " + serverHost, pmtsForHost.isEmpty());
        List<ResolveMatchType> rmts = new LinkedList<ResolveMatchType>();
        for (ProbeMatchType pmt : pmtsForHost) {
            W3CEndpointReference epr = pmt.getEndpointReference();
            ResolveMatchType rmt = client.resolve(epr, TIMEOUT);
            assertNotNull("Could not resolve (timeout = " + TIMEOUT + " ms) reference: " + epr, rmt);
            rmts.add(rmt);
        }
        int i = 0;
        for (ResolveMatchType rmt : rmts) {
            i++;
            ServiceIface port = rmt.getEndpointReference().getPort(ServiceIface.class);
            String address = rmt.getXAddrs().iterator().next();
            ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
            String expected = address.contains("AnotherWSDDService") ? "Hi " : "Greetings ";
            assertEquals(expected + "Alice" + i, port.greet("Alice" + i));
        }
        client.close();
    } finally {
        bus.shutdown(true);
    }
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) Bus(org.apache.cxf.Bus) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) LinkedList(java.util.LinkedList) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType) ResolveMatchType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchType) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) WSDiscoveryClient(org.apache.cxf.ws.discovery.WSDiscoveryClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 4 with ResolveMatchType

use of org.apache.cxf.ws.discovery.wsdl.ResolveMatchType in project jbossws-cxf by jbossws.

the class WSDiscoveryTestCase method dbgDumpList.

// tmp method for debugging jenkins runs.
// report uuid of the endpoint
private String dbgDumpList(List<ResolveMatchType> rmtList) {
    StringBuilder dbgStr = new StringBuilder().append("\n");
    for (ResolveMatchType rmt : rmtList) {
        String tmpStr = rmt.getEndpointReference().toString();
        int start = tmpStr.indexOf("<Address>");
        int end = tmpStr.indexOf("</Address>");
        if (start > -1 && end > -1) {
            String uuidStr = tmpStr.substring(start + 9, end);
            dbgStr.append(rmt.getXAddrs().get(0) + "  " + uuidStr + "\n");
        }
    }
    return dbgStr.toString();
}
Also used : ResolveMatchType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchType)

Aggregations

ResolveMatchType (org.apache.cxf.ws.discovery.wsdl.ResolveMatchType)4 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)3 Bus (org.apache.cxf.Bus)3 ProbeMatchType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchType)3 ProbeType (org.apache.cxf.ws.discovery.wsdl.ProbeType)3 ScopesType (org.apache.cxf.ws.discovery.wsdl.ScopesType)3 LinkedList (java.util.LinkedList)2 WSDiscoveryClient (org.apache.cxf.ws.discovery.WSDiscoveryClient)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 JBossWSTest (org.jboss.wsf.test.JBossWSTest)2 Test (org.junit.Test)2 QName (javax.xml.namespace.QName)1 Endpoint (javax.xml.ws.Endpoint)1 WSDiscoveryServiceImpl (org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl)1 HelloType (org.apache.cxf.ws.discovery.wsdl.HelloType)1 ProbeMatchesType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType)1