Search in sources :

Example 1 with ScopesType

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

the class WSDiscoveryClient method register.

/**
 * Sends the "Hello" to broadcast the availability of a service
 * @param ert The endpoint reference of the Service itself
 * @return the Hello that was used to broadcast the availability.
 */
public HelloType register(EndpointReference ert) {
    HelloType hello = new HelloType();
    hello.setScopes(new ScopesType());
    hello.setMetadataVersion(1);
    EndpointReferenceType ref = ProviderImpl.convertToInternal(ert);
    proccessEndpointReference(ref, hello.getScopes(), hello.getTypes(), hello.getXAddrs());
    hello.setEndpointReference(generateW3CEndpointReference());
    return register(hello);
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType)

Example 2 with ScopesType

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

the class WSDiscoveryServiceImpl method serverStarted.

public void serverStarted(Server server) {
    Object o = getProperty(server, "ws-discovery-disable");
    if (o == Boolean.TRUE || Boolean.valueOf((String) o)) {
        return;
    }
    if (!startup(true)) {
        return;
    }
    HelloType ht = new HelloType();
    ht.setScopes(new ScopesType());
    ht.setMetadataVersion(1);
    o = getProperty(server, "ws-discovery-types");
    if (o instanceof QName) {
        ht.getTypes().add((QName) o);
    } else if (o instanceof List) {
        for (Object o2 : (List<?>) o) {
            if (o2 instanceof QName) {
                ht.getTypes().add((QName) o2);
            } else if (o2 instanceof String) {
                ht.getTypes().add(QName.valueOf((String) o2));
            }
        }
    } else if (o instanceof String) {
        ht.getTypes().add(QName.valueOf((String) o));
    }
    if (ht.getTypes().isEmpty()) {
        QName sn = ServiceModelUtil.getServiceQName(server.getEndpoint().getEndpointInfo());
        ht.getTypes().add(sn);
    }
    o = getProperty(server, "ws-discovery-scopes");
    if (o != null) {
        setScopes(ht, o);
    }
    setXAddrs(ht, server);
    String uuid = (String) getProperty(server, "ws-discovery-uuid");
    if (uuid != null) {
        // persistent uuid
        W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
        builder.address(uuid);
        ht.setEndpointReference(builder.build());
    }
    ht = client.register(ht);
    registered.add(ht);
    server.getEndpoint().put(HelloType.class.getName(), ht);
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) QName(javax.xml.namespace.QName) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LinkedList(java.util.LinkedList)

Example 3 with ScopesType

use of org.apache.cxf.ws.discovery.wsdl.ScopesType 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 4 with ScopesType

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

the class WSDiscoveryClientTest method testMultiResponses.

@Test
public void testMultiResponses() throws Exception {
    // Disable the test on Redhat Enterprise Linux which doesn't enable the UDP broadcast by default
    if (System.getProperties().getProperty("os.name").equals("Linux") && System.getProperties().getProperty("os.version").indexOf("el") > 0) {
        System.out.println("Skipping MultiResponse test for REL");
        return;
    }
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    int count = 0;
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (!networkInterface.isUp() || networkInterface.isLoopback()) {
            continue;
        }
        count++;
    }
    if (count == 0) {
        // no non-loopbacks, cannot do broadcasts
        System.out.println("Skipping MultiResponse test");
        return;
    }
    new Thread(new Runnable() {

        public void run() {
            try {
                // fake a discovery server to send back some canned messages.
                InetAddress address = InetAddress.getByName("239.255.255.250");
                MulticastSocket s = new MulticastSocket(Integer.parseInt(PORT));
                s.setBroadcast(true);
                s.setNetworkInterface(findIpv4Interface());
                s.setLoopbackMode(false);
                s.setReuseAddress(true);
                s.joinGroup(address);
                s.setReceiveBufferSize(64 * 1024);
                s.setSoTimeout(5000);
                byte[] bytes = new byte[64 * 1024];
                DatagramPacket p = new DatagramPacket(bytes, bytes.length, address, Integer.parseInt(PORT));
                s.receive(p);
                SocketAddress sa = p.getSocketAddress();
                String incoming = new String(p.getData(), 0, p.getLength(), StandardCharsets.UTF_8);
                int idx = incoming.indexOf("MessageID");
                idx = incoming.indexOf('>', idx);
                incoming = incoming.substring(idx + 1);
                idx = incoming.indexOf("</");
                incoming = incoming.substring(0, idx);
                for (int x = 1; x < 4; x++) {
                    InputStream ins = WSDiscoveryClientTest.class.getResourceAsStream("msg" + x + ".xml");
                    String msg = IOUtils.readStringFromStream(ins);
                    msg = msg.replace("urn:uuid:883d0d53-92aa-4066-9b6f-9eadb1832366", incoming);
                    byte[] out = msg.getBytes(StandardCharsets.UTF_8);
                    DatagramPacket outp = new DatagramPacket(out, 0, out.length, sa);
                    s.send(outp);
                }
                s.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }).start();
    Bus bus = BusFactory.newInstance().createBus();
    WSDiscoveryClient c = new WSDiscoveryClient(bus);
    c.setVersion10();
    c.setAddress("soap.udp://239.255.255.250:" + PORT);
    ProbeType pt = new ProbeType();
    ScopesType scopes = new ScopesType();
    pt.setScopes(scopes);
    ProbeMatchesType pmts = c.probe(pt, 1000);
    Assert.assertEquals(2, pmts.getProbeMatch().size());
    c.close();
    bus.shutdown(true);
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) MulticastSocket(java.net.MulticastSocket) Bus(org.apache.cxf.Bus) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) InputStream(java.io.InputStream) NetworkInterface(java.net.NetworkInterface) Endpoint(javax.xml.ws.Endpoint) DatagramPacket(java.net.DatagramPacket) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType) SocketAddress(java.net.SocketAddress) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 5 with ScopesType

use of org.apache.cxf.ws.discovery.wsdl.ScopesType 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)

Aggregations

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