Java Code Examples for javax.xml.ws.Endpoint#publish()

The following examples show how to use javax.xml.ws.Endpoint#publish() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Server.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run() {
    Object implementor;
    String address;

    implementor = new GreeterImpl();
    address = "ws://localhost:" + PORT + "/SoapContext/SoapPort";
    Endpoint ep = Endpoint.publish(address, implementor);
    eps.add(ep);

    //publish port with soap12 binding
    address = "ws://localhost:" + PORT + "/SoapContext/SoapPort";
    EndpointImpl e = (EndpointImpl) Endpoint.create(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING,
                                                    new Greeter12Impl());
    e.publish(address);
    eps.add(e);
}
 
Example 2
Source File: UDDI_170_ValueSetValidationIntegrationTest.java    From juddi with Apache License 2.0 6 votes vote down vote up
private void reset() throws Exception {
        messagesReceived = 0;
        if (ep == null || !ep.isPublished()) {
                int httpPort = 9600 + new Random().nextInt(99);
                String hostname = TckPublisher.getProperties().getProperty("bindaddress");
                if (hostname == null) {
                        hostname = InetAddress.getLocalHost().getHostName();
                }
                url = "http://" + hostname + ":" + httpPort + "/" + UUID.randomUUID().toString();
                logger.info("Firing up embedded endpoint at " + url);
                do {
                        try {

                                ep = Endpoint.publish(url, this);
                                httpPort = 9600 + new Random().nextInt(99);
                        } catch (Exception ex) {
                                logger.warn(ex.getMessage());
                        }
                } while (ep != null && !ep.isPublished());

        }

}
 
Example 3
Source File: AddressingPolicy0705Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run()  {

            System.setProperty("temp.location", tmpDir);
            SpringBusFactory bf = new SpringBusFactory();
            Bus bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr0705.xml");
            BusFactory.setDefaultBus(bus);
            setBus(bus);
            LoggingInInterceptor in = new LoggingInInterceptor();
            bus.getInInterceptors().add(in);
            bus.getInFaultInterceptors().add(in);
            LoggingOutInterceptor out = new LoggingOutInterceptor();
            bus.getOutInterceptors().add(out);
            bus.getOutFaultInterceptors().add(out);

            GreeterImpl implementor = new GreeterImpl();
            String address = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
            ep = Endpoint.publish(address, implementor);
            LOG.info("Published greeter endpoint.");
        }
 
Example 4
Source File: WSTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        // find a free port
        ServerSocket ss = new ServerSocket(0);
        int port = ss.getLocalPort();
        ss.close();

        Endpoint endPoint1 = null;
        Endpoint endPoint2 = null;
        try {
            endPoint1 = Endpoint.publish("http://0.0.0.0:" + port + "/method1",
                    new Method1());
            endPoint2 = Endpoint.publish("http://0.0.0.0:" + port + "/method2",
                    new Method2());

            System.out.println("Sleep 3 secs...");

            Thread.sleep(3000);
        } finally {
            stop(endPoint2);
            stop(endPoint1);
        }
    }
 
Example 5
Source File: CXFWSNHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Endpoint publish(String address, Object o, Class<?> ... extraClasses) {
    Endpoint endpoint = Endpoint.create(SOAPBinding.SOAP12HTTP_BINDING, o);
    if (extraClasses != null && extraClasses.length > 0) {
        Map<String, Object> props = new HashMap<>();
        props.put("jaxb.additionalContextClasses", extraClasses);
        endpoint.setProperties(props);
    }
    URL wsdlLocation = WSNWSDLLocator.getWSDLUrl();
    if (wsdlLocation != null) {
        try {
            if (endpoint.getProperties() == null) {
                endpoint.setProperties(new HashMap<String, Object>());
            }
            endpoint.getProperties().put("javax.xml.ws.wsdl.description", wsdlLocation.toExternalForm());
            List<Source> mt = new ArrayList<>();
            StreamSource src = new StreamSource(wsdlLocation.openStream(), wsdlLocation.toExternalForm());
            mt.add(src);
            endpoint.setMetadata(mt);
        } catch (IOException e) {
            //ignore, no wsdl really needed
        }
    }
    endpoint.publish(address);
    return endpoint;
}
 
Example 6
Source File: NetSuiteWebServiceMockTestFixture.java    From components with Apache License 2.0 5 votes vote down vote up
protected void publish() throws Exception {
    int portNumber = FreePortFinder.findFreePort(28080, FreePortFinder.MAX_PORT_NUMBER);
    URL endpointAddress = new URL("http://localhost:" + portNumber + "/services/" + portName);

    logger.info("Endpoint address: {}", endpointAddress);

    portMockAdapter = portAdapterClass.newInstance();
    portMockAdapter.setEndpointAddress(endpointAddress);

    // Publish the SOAP Web Service
    endpoint = Endpoint.publish(endpointAddress.toString(), portMockAdapter);
    assertTrue(endpoint.isPublished());
    assertEquals("http://schemas.xmlsoap.org/wsdl/soap/http", endpoint.getBinding().getBindingID());
}
 
Example 7
Source File: ProviderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Endpoint createAndPublishEndpoint(String address,
                                         Object implementor) {
    Endpoint endpoint = new EndpointImpl(
        BindingID.parse(implementor.getClass()),
        implementor);
    endpoint.publish(address);
    return endpoint;
}
 
Example 8
Source File: Server.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run()  {
    Object implementor = new GreeterImpl();
    String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    ep = Endpoint.publish(address, implementor);

    implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/Soap11Port";
    ep11 = Endpoint.publish(address, implementor);
}
 
Example 9
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    try {
        // Find vacant port number
        ServerSocket ss = new ServerSocket(0);
        port = ss.getLocalPort();
        ss.close();

        // Publish WebService
        System.out.println("Publishing WebService on " + port + " port");
        Endpoint ep = Endpoint.publish("http://localhost:" + port + "/ws/hello", new HelloWorldImpl());

        // Notify main thread that WS endpoint is published
        initSignal.countDown();

        // Wait for main thread to complete testing
        System.out.println("Waiting for done signal from test client.");
        doneSignal.await();

        // Terminate WS endpoint
        System.out.println("Got done signal from the client. Stopping WS endpoint.");
        ep.stop();
    } catch (IOException ioe) {
        System.out.println("Failed to get vacant port number:" + ioe);
    } catch (InterruptedException ie) {
        System.out.println("Failed to wait for test completion:" + ie);
    }
}
 
Example 10
Source File: SEIWithJAXBAnnoTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLList() throws Exception {

    AddNumbersImpl serviceImpl = new AddNumbersImpl();
    Endpoint.publish("local://localhost:9000/Hello", serviceImpl);

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(BusFactory.getDefaultBus());
    factory.setServiceClass(AddNumbers.class);

    factory.setAddress(address);
    AddNumbers proxy = (AddNumbers)factory.create();
    StringWriter strWriter = new StringWriter();
    LoggingOutInterceptor log = new LoggingOutInterceptor(new PrintWriter(strWriter));
    ClientProxy.getClient(proxy).getOutInterceptors().add(log);

    List<String> args = new ArrayList<>();
    args.add("str1");
    args.add("str2");
    args.add("str3");
    List<Integer> result = proxy.addNumbers(args);
    String expected = "<arg0>str1 str2 str3</arg0>";
    assertTrue("Client does not use the generated wrapper class to marshal request parameters",
                 strWriter.toString().indexOf(expected) > -1);
    assertEquals("Get the wrong result", 100, (int)result.get(0));

}
 
Example 11
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run()  {
    String configurationFile = "jettyDigestServer.xml";
    URL configure =
        JettyBasicAuthServer.class.getResource(configurationFile);
    Bus bus = new SpringBusFactory().createBus(configure, true);
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());
    BusFactory.setDefaultBus(bus);
    setBus(bus);

    GreeterImpl implementor = new GreeterImpl();
    ep = Endpoint.publish(ADDRESS, implementor);
}
 
Example 12
Source File: Cxf6319TestCase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeclarationsInEnvelope() throws Exception {
    Endpoint ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort", new ServiceImpl());

    try {
        HttpURLConnection httpConnection =
                getHttpConnection("http://localhost:" + PORT + "/SoapContext/SoapPort/echo");
        httpConnection.setDoOutput(true);

        InputStream reqin = getClass().getResourceAsStream("request.xml");
        assertNotNull("could not load test data", reqin);

        httpConnection.setRequestMethod("POST");
        httpConnection.addRequestProperty("Content-Type", "text/xml");
        OutputStream reqout = httpConnection.getOutputStream();
        IOUtils.copy(reqin, reqout);
        reqout.close();

        int responseCode = httpConnection.getResponseCode();
        InputStream errorStream = httpConnection.getErrorStream();
        String error = null;
        if (errorStream != null) {
            error = IOUtils.readStringFromStream(errorStream);
        }
        assertEquals(error, 200, responseCode);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        ep.stop();
    }
}
 
Example 13
Source File: Main.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    try {
        // Find vacant port number
        ServerSocket ss = new ServerSocket(0);
        port = ss.getLocalPort();
        ss.close();

        // Publish WebService
        System.out.println("Publishing WebService on " + port + " port");
        Endpoint ep = Endpoint.publish("http://localhost:" + port + "/ws/hello", new HelloWorldImpl());

        // Notify main thread that WS endpoint is published
        initSignal.countDown();

        // Wait for main thread to complete testing
        System.out.println("Waiting for done signal from test client.");
        doneSignal.await();

        // Terminate WS endpoint
        System.out.println("Got done signal from the client. Stopping WS endpoint.");
        ep.stop();
    } catch (IOException ioe) {
        System.out.println("Failed to get vacant port number:" + ioe);
    } catch (InterruptedException ie) {
        System.out.println("Failed to wait for test completion:" + ie);
    }
}
 
Example 14
Source File: TrivialSOAPHandlerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run()  {
    Object implementor = new TrivialSOAPHandlerAnnotatedGreeterImpl();
    Endpoint.publish(address, implementor);
}
 
Example 15
Source File: EndpointAPITest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSingleEndpoint() throws Exception {

    String contextPath = "/ctxt";
    String path = "/echo";
    String address = "http://localhost:" + currentPort + contextPath + path;

    HttpContext context = GrizzlyHttpContextFactory.createHttpContext(server, contextPath, path);

    Endpoint endpoint = Endpoint.create(new EndpointBean());
    endpoint.publish(context); // Use grizzly HTTP context for publishing

    server.start();

    invokeEndpoint(address);

    endpoint.stop();
}
 
Example 16
Source File: Server.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run() {
    Object implementor = new ServerImpl();
    String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    Endpoint.publish(address, implementor);

}
 
Example 17
Source File: Server.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run()  {
    Object implementor = new HelloImpl();
    String address = "http://localhost:" + PORT + "/jaxws-mtom/hello";
    Endpoint.publish(address, implementor);
}
 
Example 18
Source File: AbstractProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void publish(String url) {
    Endpoint ep = Endpoint.create(HTTPBinding.HTTP_BINDING, this);
    ep.publish(url);
}
 
Example 19
Source File: AsyncHTTPConduitTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    b.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS", 501);

    BusFactory.setThreadDefaultBus(b);

    AsyncHTTPConduitFactory hcf = (AsyncHTTPConduitFactory)b.getExtension(HTTPConduitFactory.class);
    assertEquals(501, hcf.maxConnections);

    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
                          new org.apache.hello_world_soap_http.GreeterImpl() {
            public String greetMeLater(long cnt) {
                //use the continuations so the async client can
                //have a ton of connections, use less threads
                //
                //mimic a slow server by delaying somewhere between
                //1 and 2 seconds, with a preference of delaying the earlier
                //requests longer to create a sort of backlog/contention
                //with the later requests
                ContinuationProvider p = (ContinuationProvider)
                    getContext().getMessageContext().get(ContinuationProvider.class.getName());
                Continuation c = p.getContinuation();
                if (c.isNew()) {
                    if (cnt < 0) {
                        c.suspend(-cnt);
                    } else {
                        c.suspend(2000 - (cnt % 1000));
                    }
                    return null;
                }
                return "Hello, finally! " + cnt;
            }
            public String greetMe(String me) {
                if (me.equals(FILL_BUFFER)) {
                    return String.join("", Collections.nCopies(16093, " "));
                } else {
                    return "Hello " + me;
                }
            }
        });

    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();

    URL wsdl = AsyncHTTPConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);

    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);

    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
 
Example 20
Source File: Server.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run()  {
    Object implementor = new GenericsEchoImpl();
    String address = "http://localhost:" + PORT + "/generic";
    Endpoint.publish(address, implementor);
}