Example usage for javax.xml.ws Endpoint publish

List of usage examples for javax.xml.ws Endpoint publish

Introduction

In this page you can find the example usage for javax.xml.ws Endpoint publish.

Prototype

public void publish(HttpContext serverContext) 

Source Link

Document

Publishes this endpoint at the provided server context.

Usage

From source file:com.movilizer.mds.onlinesync.sample.OnlineSyncApplication.java

@Bean
@Autowired//  w w  w . j av a 2s.com
public Endpoint helloEndpoint(Bus bus, HelloMoveletWebservice helloMoveletWebservice) {
    Endpoint endpoint = new EndpointImpl(bus, helloMoveletWebservice);
    endpoint.publish("/helloMoveletWebservice");
    return endpoint;
}

From source file:com.clustercontrol.plugin.impl.WebServicePlugin.java

/**
 * ???WebService?Agent????????/* www .jav  a 2s.c  o m*/
 * @param addressPrefix ? http://x.x.x.x:xxxx? ?
 * @param addressBody ??? addressPrefix ??
 * @param endpointInstance
 * @param threadPool ?
 */
protected void publish(String addressPrefix, String addressBody, Object endpointInstance,
        ThreadPoolExecutor threadPool) {

    try {
        final URL urlPrefix = new URL(addressPrefix);
        final String fulladdress = addressPrefix + addressBody;
        HttpsServer httpsServer = null;
        // ? HTTPS???????HttpsService???endpoit.publish?????
        // URL??????????HttpsService?????Hashmap???????HashMap?
        // HTTPSServer???????????
        if ("https".equals(urlPrefix.getProtocol())) {
            httpsServer = httpsServerMap.get(addressPrefix);
            if (httpsServer == null) {
                // HTTPS Server??HTTPS?????????????????????
                String protocol = HinemosPropertyUtil.getHinemosPropertyStr("ws.https.protocol", "TLS");
                String keystorePath = HinemosPropertyUtil.getHinemosPropertyStr("ws.https.keystore.path",
                        HinemosPropertyDefault
                                .getString(HinemosPropertyDefault.StringKey.WS_HTTPS_KEYSTORE_PATH));
                String keystorePassword = HinemosPropertyUtil
                        .getHinemosPropertyStr("ws.https.keystore.password", "hinemos");
                String keystoreType = HinemosPropertyUtil.getHinemosPropertyStr("ws.https.keystore.type",
                        "PKCS12");
                log.info("Starting HTTPS Server...");
                log.info("SSLContext: " + protocol + ", KeyStore: " + keystoreType);
                SSLContext ssl = SSLContext.getInstance(protocol);
                KeyManagerFactory keyFactory = KeyManagerFactory
                        .getInstance(KeyManagerFactory.getDefaultAlgorithm());
                KeyStore store = KeyStore.getInstance(keystoreType);
                try (InputStream in = new FileInputStream(keystorePath)) {
                    store.load(in, keystorePassword.toCharArray());
                }
                keyFactory.init(store, keystorePassword.toCharArray());
                TrustManagerFactory trustFactory = TrustManagerFactory
                        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
                trustFactory.init(store);
                ssl.init(keyFactory.getKeyManagers(), trustFactory.getTrustManagers(), new SecureRandom());
                HttpsConfigurator configurator = new HttpsConfigurator(ssl);

                // ??HTTPSSever???Hashmap??
                httpsServer = HttpsServer
                        .create(new InetSocketAddress(urlPrefix.getHost(), urlPrefix.getPort()), 0);
                httpsServer.setHttpsConfigurator(configurator);
                httpsServerMap.put(addressPrefix, httpsServer);
            }
        }

        // ?????endpoint??
        log.info("publish " + fulladdress);
        final Endpoint endpoint = Endpoint.create(endpointInstance);
        endpoint.setExecutor(threadPool);
        if (httpsServer != null) {
            endpoint.publish(httpsServer.createContext(addressBody));
        } else {
            endpoint.publish(fulladdress);
        }
        endpointList.add(endpoint);
    } catch (NoSuchAlgorithmException | UnrecoverableKeyException | KeyStoreException | KeyManagementException
            | IOException | CertificateException | RuntimeException e) {
        log.warn("failed to publish : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
    } finally {

    }
}

From source file:io.hummer.util.ws.AbstractNode.java

@SuppressWarnings("all")
public static void deploy(final Object service, String url, Handler<?>... handler)
        throws AbstractNodeException {

    long t1 = System.currentTimeMillis();

    try {/*ww w  .  ja v a 2 s.c om*/

        URL u = new URL(url);

        if (strUtil.isEmpty(System.getProperty(SYSPROP_HTTP_SERVER_PROVIDER_CLASS))) {
            System.setProperty(SYSPROP_HTTP_SERVER_PROVIDER_CLASS, JettyHttpServerProvider.class.getName());
        }

        ContextHandlerCollection chc = new ContextHandlerCollection();

        // disable log output from Metro and Jetty
        java.util.logging.Logger.getAnonymousLogger().getParent().setLevel(Level.WARNING);
        Class<?> cls3 = org.eclipse.jetty.server.Server.class;
        Class<?> cls4 = org.eclipse.jetty.server.AbstractConnector.class;
        org.apache.log4j.Level lev3 = Logger.getLogger(cls3).getLevel();
        org.apache.log4j.Level lev4 = Logger.getLogger(cls4).getLevel();
        Logger.getLogger(cls3).setLevel(org.apache.log4j.Level.WARN);
        Logger.getLogger(cls4).setLevel(org.apache.log4j.Level.WARN);

        JettyHttpServer httpServer = httpServers.get(u.getPort());
        Server server = servers.get(u.getPort());
        if (httpServer == null) {
            org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
            server = new Server(u.getPort());

            SelectChannelConnector connector = new SelectChannelConnector();
            connector.setPort(u.getPort());
            connector.setAcceptQueueSize(1000);
            connector.setThreadPool(new ExecutorThreadPool(GlobalThreadPool.getExecutorService()));
            server.setConnectors(new Connector[] { connector });

            server.setHandler(chc);

            httpServer = new JettyHttpServer(server, true);

            httpServers.put(u.getPort(), httpServer);
            servers.put(u.getPort(), server);

            if (!server.isStarted())
                server.start();
        }

        JettyHttpContext wsContext1 = (JettyHttpContext) httpServer.createContext(u.getPath());
        Endpoint endpoint = Endpoint.create(service);
        if (service instanceof AbstractNode) {
            if (((AbstractNode) service).endpoint != null)
                logger.warn("AbstractNode " + service + " has apparently been double-deployed, "
                        + "because there already exists an endpoint for this instance.");
            ((AbstractNode) service).endpoint = endpoint;
        }

        // add JAX-WS handlers (e.g., needed for TeCoS invocation intercepting...)
        List<Handler> handlers = endpoint.getBinding().getHandlerChain();
        handlers.addAll(Arrays.asList(handler));
        endpoint.getBinding().setHandlerChain(handlers);
        if (service instanceof AbstractNode) {
            AbstractNode a = (AbstractNode) service;
            for (Handler h : handlers)
                if (!a.activeHandlers.contains(h))
                    a.activeHandlers.add(h);
        }

        Class<?> cls1 = org.eclipse.jetty.util.component.AbstractLifeCycle.class;
        Class<?> cls2 = org.eclipse.jetty.server.handler.ContextHandler.class;
        org.apache.log4j.Level lev1 = Logger.getLogger(cls1).getLevel();
        org.apache.log4j.Level lev2 = Logger.getLogger(cls2).getLevel();
        try {
            String bindUrl = u.getProtocol() + "://0.0.0.0:" + u.getPort() + u.getPath();
            if (u.getQuery() != null) {
                bindUrl += "?" + u.getQuery();
            }
            Logger.getLogger(cls1).setLevel(org.apache.log4j.Level.OFF);
            Logger.getLogger(cls2).setLevel(org.apache.log4j.Level.WARN);
            logger.info("Binding service to " + bindUrl);
            endpoint.publish(bindUrl);
        } catch (Exception e) {
            if (e instanceof BindException || (e.getCause() != null && e.getCause() instanceof BindException)
                    || (e.getCause() != null && e.getCause().getCause() != null
                            && e.getCause().getCause() instanceof BindException)) {
                /** we expect a BindException here, just swallow */
            } else {
                logger.warn("Unexpected error.", e);
            }
        } finally {
            Logger.getLogger(cls1).setLevel(lev1);
            Logger.getLogger(cls2).setLevel(lev2);
            Logger.getLogger(cls3).setLevel(lev3);
            Logger.getLogger(cls4).setLevel(lev4);
        }

        Field f = endpoint.getClass().getDeclaredField("actualEndpoint");
        f.setAccessible(true);

        // DO NOT do this (the two lines below), because HttpEndpoint creates some nasty 
        // compile-time dependencies with respect to JAXWS-RT. At runtime, we can (hopefully) 
        // assume that this class is present, in all newer Sun JVM implementations..
        //HttpEndpoint httpEndpoint = (HttpEndpoint)f.get(e1);
        //httpEndpoint.publish(wsContext1);
        Object httpEndpoint = f.get(endpoint);
        httpEndpoint.getClass().getMethod("publish", Object.class).invoke(httpEndpoint, wsContext1);

        Endpoint e2 = Endpoint.create(new CrossdomainXML());
        JettyHttpContext wsContext2 = (JettyHttpContext) httpServer.createContext("/crossdomain.xml");
        e2.publish(wsContext2);

        // Also deploy as RESTful service..
        if (service instanceof AbstractNode) {
            AbstractNode node = (AbstractNode) service;
            if (node.isRESTfulService()) {
                String path = u.getPath();
                if (!path.contains("/"))
                    path = "/";
                path = "/rest";
                String wadlURL = netUtil.getUrlBeforePath(u) + path + "/application.wadl";
                if (logger.isDebugEnabled())
                    logger.debug("Deploying node as RESTful service: " + wadlURL);
                JettyHttpContext wsContext3 = (JettyHttpContext) httpServer.createContext(path);

                ResourceConfig rc = new PackagesResourceConfig(service.getClass().getPackage().getName(),
                        AbstractNode.class.getPackage().getName());
                HttpHandler h = RuntimeDelegate.getInstance().createEndpoint(rc, HttpHandler.class);
                wsContext3.setHandler(h);
                node.setWadlURL(wadlURL);
            }
            deployedNodes.put(url, node);
        }

        final HttpHandler h = wsContext1.getHandler();
        wsContext1.setHandler(new HttpHandler() {
            public void handle(com.sun.net.httpserver.HttpExchange ex) throws IOException {

                if (!ex.getRequestMethod().equals("OPTIONS")) {
                    addCORSHeaders(ex);
                    h.handle(ex);
                    //System.out.println(ex.getRequestMethod() + ": " + ex.getResponseHeaders() + " - " + new HashMap<>(ex.getResponseHeaders()));
                    return;
                }

                if (ex.getRequestMethod().equals("OPTIONS")) {
                    addCORSHeaders(ex);
                    ex.sendResponseHeaders(200, -1);
                    ex.getResponseBody().close();
                    return;
                }
                //System.out.println(new HashMap<>(ex.getResponseHeaders()));
            }
        });

        // add shutdown task for this node
        if (service instanceof AbstractNode) {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    try {
                        Runnable r = ((AbstractNode) service).getTerminateTask(null);
                        if (r != null)
                            r.run();
                    } catch (Exception e) {
                    }
                }
            });
        }

    } catch (Exception e) {
        throw new AbstractNodeException(e);
    }

    long diff = System.currentTimeMillis() - t1;
    logger.info("Deployment took " + diff + "ms");

}

From source file:org.apache.axis2.jaxws.spi.Provider.java

public Endpoint createAndPublishEndpoint(String s, Object obj, WebServiceFeature... features) {
    Endpoint ep = new EndpointImpl(obj);
    ep.publish(s);
    return ep;/*  w ww . j  ava  2  s.com*/
}

From source file:org.apache.juddi.example.wsdl2uddi.Publish.java

public static void main(String args[]) {

    System.out.println("1. Bring up the hello world endpoint at port 18080");
    Endpoint helloWorldEndPoint = Endpoint.create(new HelloWorldImpl());
    helloWorldEndPoint.publish("http://localhost:18080/services/helloworld");

    System.out.println("2. Programmatically publish the endpoint to UDDI");
    Publish sp = new Publish();
    try {//ww w.j  a  v a 2  s  .c  o m
        uddiClient = new UDDIClient("META-INF/wsdl2uddi-uddi.xml");
        UDDIClerk clerk = uddiClient.getClerk("joe");

        System.out.println("setting up the publisher");
        sp.setupJoePublisher(clerk);
        System.out.println("publish the business");
        sp.publishBusiness(clerk);
        System.out.println("and the wsdl");
        sp.publishWSDL(clerk);

        System.out.println("waiting for calls into the HelloWorldImpl...");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.smila.webservice.WebservicePublisher.java

/**
 * publish a webservice for a tracked service.
 * /*w  w w.  j a  v a  2s .com*/
 * @param reference
 *          service reference for added service.
 * @param implementor
 *          service implementor.
 */
public void publishWebservice(final ServiceReference reference, final Object implementor) {
    final String name = reference.getProperty(PROP_WEBSERVICENAME).toString();
    if (_endpoints.containsKey(name)) {
        _log.warn(
                "Already have registered a Webservice endpoint with name " + name + ", ignoring new service.");
    } else {
        final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(implementor.getClass().getClassLoader());
        try {
            _log.debug("Creating endpoint for webservice " + name);
            final Endpoint ep = Endpoint.create(implementor);
            if (ep != null) {
                final String url = _properties.getBaseURL() + name;
                _log.debug("Publishing webservice " + name + " at " + url);
                ep.publish(url);
                _endpoints.put(name, ep);
                _references.put(name, reference);
                _log.info("Webservice successfully published: " + url);
            }
        } catch (final Throwable ex) {
            _log.error("Error publishing webservice " + name, ex);
        } finally {
            Thread.currentThread().setContextClassLoader(tccl);
        }
    }
}

From source file:org.nuxeo.ecm.platform.ws.WSEndpointManagerImpl.java

@Override
public void publishEndpoints() {
    for (WSEndpointDescriptor desc : regitry.getContributions()) {
        try {//from www  .j a  v a2s .com
            stopIfExists(desc.name);

            Endpoint ep = desc.toEndpoint();

            ep.publish(desc.address);
            desc.configurePostPublishing(ep);

            if (ep.isPublished()) {
                endpoints.put(desc.name, ep);
            } else {
                log.warn("Endpoint publishing is failing: " + desc.name);
            }
        } catch (IOException | IllegalAccessException | InstantiationException e) {
            log.warn("Unable to register endpoint: " + desc.name, e);
        }
    }
}

From source file:org.rifidi.edge.core.utilities.JaxWsServiceExporter.java

/**
 * The start method. Should be called after properties have been set. Will
 * deploy the webservice./*from   www . j  a  v  a 2s. com*/
 */
public void start() {
    if (deploy) {
        WebService annotation = service.getClass().getAnnotation(WebService.class);

        if (endpoint != null) {
            stop();
        }

        Endpoint endpoint = Endpoint.create(service);
        if (this.endpointProperties != null) {
            endpoint.setProperties(this.endpointProperties);
        }
        if (this.executor != null) {
            endpoint.setExecutor(this.executor);
        }
        if (this.host == null) {
            this.host = defaultHost;
        }
        if (this.port == null) {
            this.port = defaultPort;
        }
        fullAddress = host + ":" + port + "/" + annotation.serviceName();
        endpoint.publish(fullAddress);
        logger.info("Web Service published: " + fullAddress);
        this.endpoint = endpoint;

    }
}

From source file:org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter.java

@Override
protected void publishEndpoint(Endpoint endpoint, WebService annotation) {
    endpoint.publish(buildHttpContext(endpoint, annotation.serviceName()));
}

From source file:org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter.java

@Override
protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) {
    endpoint.publish(buildHttpContext(endpoint, annotation.serviceName()));
}