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(String bindingId, Object implementor) 

Source Link

Document

Creates an endpoint with the specified binding type and implementor object.

Usage

From source file:com.mirth.connect.connectors.ws.WebServiceReceiver.java

@Override
public void onStart() throws ConnectorTaskException {
    String channelId = getChannelId();
    String channelName = getChannel().getName();
    String host = replacer.replaceValues(connectorProperties.getListenerConnectorProperties().getHost(),
            channelId, channelName);//  w ww . ja  va 2s. c  om
    int port = NumberUtils.toInt(replacer.replaceValues(
            connectorProperties.getListenerConnectorProperties().getPort(), channelId, channelName));

    logger.debug("starting Web Service HTTP server on port: " + port);

    java.util.logging.Logger.getLogger("javax.enterprise.resource.webservices.jaxws.server")
            .setLevel(java.util.logging.Level.OFF);

    try {
        configuration.configureReceiver(this);
        server.bind(new InetSocketAddress(host, port), DEFAULT_BACKLOG);
    } catch (Exception e) {
        throw new ConnectorTaskException("Error creating HTTP Server.", e);
    }

    // TODO: Make a max connections property for this
    int processingThreads = connectorProperties.getSourceConnectorProperties().getProcessingThreads();
    if (processingThreads < 1) {
        processingThreads = 1;
    }

    // Allow more than the channel processing threads so WDSL requests can be accepted even if all processing threads are busy
    executor = Executors.newFixedThreadPool(processingThreads + 4);
    server.setExecutor(executor);
    server.start();

    AcceptMessage acceptMessageWebService = null;

    try {
        MirthContextFactory contextFactory = contextFactoryController.getContextFactory(getResourceIds());
        Class<?> clazz = Class.forName(
                replacer.replaceValues(connectorProperties.getClassName(), channelId, channelName), true,
                contextFactory.getApplicationClassLoader());

        if (clazz.getSuperclass().equals(AcceptMessage.class)) {
            Constructor<?>[] constructors = clazz.getDeclaredConstructors();
            for (int i = 0; i < constructors.length; i++) {
                Class<?>[] parameters = constructors[i].getParameterTypes();
                if ((parameters.length == 1) && parameters[0].equals(this.getClass())) {
                    acceptMessageWebService = (AcceptMessage) constructors[i]
                            .newInstance(new Object[] { this });
                }
            }

            if (acceptMessageWebService == null) {
                logger.error(
                        "Custom web service class must implement the constructor: public AcceptMessage(WebServiceReceiver webServiceReceiver)");
            }
        } else {
            logger.error("Custom web service class must extend com.mirth.connect.connectors.ws.AcceptMessage");
        }
    } catch (Exception e) {
        logger.error("Custom web service class initialization failed", e);
    }

    if (acceptMessageWebService == null) {
        logger.error("Custom web service class initialization failed, using DefaultAcceptMessage");
        acceptMessageWebService = new DefaultAcceptMessage(this);
    }

    webServiceEndpoint = Endpoint.create(connectorProperties.getSoapBinding().getValue(),
            acceptMessageWebService);
    Binding binding = webServiceEndpoint.getBinding();
    List<Handler> handlerChain = new LinkedList<Handler>();
    handlerChain.add(new LoggingSOAPHandler(this));
    binding.setHandlerChain(handlerChain);

    String serviceName = replacer.replaceValues(connectorProperties.getServiceName(), channelId, channelName);
    HttpContext context = server.createContext("/services/" + serviceName);

    // Set a security authenticator if needed
    if (authenticatorProvider != null) {
        context.setAuthenticator(createAuthenticator());
    }

    webServiceEndpoint.publish(context);

    eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(),
            ConnectionStatusEventType.IDLE));
}