Example usage for javax.xml.ws Endpoint create

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

Introduction

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

Prototype

public static Endpoint create(Object implementor) 

Source Link

Document

Creates an endpoint with the specified implementor object.

Usage

From source file:de.cwclan.cwsa.serverendpoint.main.ServerEndpoint.java

public ServerEndpoint(Properties properties) {
    try {//from  w w  w .  ja  v  a 2 s.  co  m
        this.properties = properties;
        service = AbstractServiceFactory.createService(properties.getProperty("endpoint.implementation"),
                new ServerCommand(properties));
        endpoint = Endpoint.create(endpointImpl);

    } catch (ServerException ex) {
        log.error("Failed to start Endpoint", ex);
    }

}

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

/**
 * ???WebService?Agent????????//from   w w  w . ja  v a2  s . 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 {/*from w  w  w . j  a 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.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 {//from ww  w .j  av a2 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.apache.juddi.v3.client.mapping.UDDIServiceCache.java

public void publishAndRegisterHttpCallbackEndpoint() throws BindException {
    if (clerk != null && listenerEndpoint == null) {
        try {//  w  w  w .j ava 2s. com
            listenerServiceUrl = new URL(urlLocalizer.rewrite(new URL(DEFAULT_SUBSCRIPTION_LISTENER_URL)));
            WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(clerk, urlLocalizer, properties);
            Definition wsdlDefinition = new ReadWSDL()
                    .readWSDL("org/apache/juddi/v3/client/mapping/UDDIClientSubscriptionListener.wsdl");

            String bindingKey = wsdl2UDDI
                    .registerBusinessService(SUBSCRIPTION_LISTENER_SERVICE_NAME,
                            SUBSCRIPTION_LISTENER_PORT_NAME, listenerServiceUrl, wsdlDefinition)
                    .getBindingKey();
            UDDISubscriptionListenerPortType subscriptionListener = new UDDIClientSubscriptionListenerImpl(
                    bindingKey, this);
            log.info("Bringing up a UDDIClientSubscriptionListenerImpl on Endpoint "
                    + listenerServiceUrl.toExternalForm());
            listenerEndpoint = Endpoint.create(subscriptionListener);
            listenerEndpoint.publish(listenerServiceUrl.toExternalForm());

            log.info("Registering a CallbackSubscription to this endpoint using bindingKey " + bindingKey);
            registerSubscription(bindingKey);

        } catch (RuntimeException t) {
            listenerEndpoint = null;
            if (t.getCause() instanceof BindException) {
                throw new BindException(t.getCause().getMessage());
            } else {
                throw t;
            }
        } catch (Exception e) {
            log.error("Cannot publish or register the CallbackEndpoint " + e.getMessage(), e);
        }
    }
}

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

/**
 * publish a webservice for a tracked service.
 * /* ww w . j  a va 2  s .  c  o  m*/
 * @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.kie.remote.services.ws.command.CommandServiceTest.java

public static Endpoint setupCommandServiceEndpoint(String address, CommandWebService webServiceImpl) {
    EndpointImpl ep = (EndpointImpl) Endpoint.create(webServiceImpl);
    ep.setAddress(address);/*from w  w  w .  j  a v a 2s .  co  m*/
    ep.getProperties().put(SecurityConstants.CALLBACK_HANDLER, new TestServerPasswordCallback());

    ep.publish();
    return ep;
}

From source file:org.nuxeo.ecm.platform.api.ws.WSEndpointDescriptor.java

public Endpoint toEndpoint() throws IOException, IllegalAccessException, InstantiationException {
    Endpoint ep = Endpoint.create(getImplementorInstance());
    List<Source> metadata = new ArrayList<>();
    Map<String, Object> properties = new HashMap<>();

    if (!isBlank(port)) {
        properties.put(WSDL_PORT, new QName(namespace, port));
    }//ww  w.  ja  va  2s  . c o  m
    if (!isBlank(port)) {
        properties.put(WSDL_SERVICE, new QName(namespace, service));
    }

    if (!isBlank(wsdl)) {
        URL wsdlURL = WSEndpointManagerImpl.class.getClassLoader().getResource(wsdl);
        if (wsdlURL == null) {
            throw new FileNotFoundException("WSDL: " + wsdl);
        }
        Source src = new StreamSource(wsdlURL.openStream());
        src.setSystemId(wsdlURL.toExternalForm());
        metadata.add(src);
    }

    if (isBlank(publishedEndpointUrl)) {
        publishedEndpointUrl = String.format("%s%s%s", Framework.getProperty(NUXEO_URL),
                WSEndpointManager.WS_SERVLET, address);
    }
    properties.put("publishedEndpointUrl", publishedEndpointUrl);

    ep.setMetadata(metadata);
    ep.setProperties(properties);
    return ep;
}

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./* ww w  .  j  av  a 2 s. c  o m*/
 */
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:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceClientTest.java

@Before
public void setUp() throws Exception {
    this.testPort = new DigitalSignatureServiceTestPort();
    this.endpoint = Endpoint.create(this.testPort);
    String address = "http://localhost:" + getFreePort() + "/dss";
    this.endpoint.publish(address);

    this.client = new DigitalSignatureServiceClient(address);
}