Example usage for javax.xml.ws Binding setHandlerChain

List of usage examples for javax.xml.ws Binding setHandlerChain

Introduction

In this page you can find the example usage for javax.xml.ws Binding setHandlerChain.

Prototype

public void setHandlerChain(java.util.List<javax.xml.ws.handler.Handler> chain);

Source Link

Document

Sets the handler chain for the protocol binding instance.

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);//from  w  w  w  . ja  v a 2s .  c o m
    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));
}

From source file:be.agiv.security.client.RSTSClient.java

/**
 * Main constructor./*from   w ww .ja v  a  2s  .c  om*/
 * 
 * @param location
 *            the location of the R-STS WS-Trust web service.
 */
public RSTSClient(String location) {
    this.location = location;
    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.policyObjectFactory = new be.agiv.security.jaxb.wspolicy.ObjectFactory();
    this.addrObjectFactory = new be.agiv.security.jaxb.wsaddr.ObjectFactory();

}

From source file:be.e_contract.mycarenet.ehbox.EHealthBoxConsultationClient.java

@SuppressWarnings("unchecked")
private void configureBindingProvider(BindingProvider bindingProvider, String location) {
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List handlerChain = binding.getHandlerChain();
    handlerChain.add(this.wsSecuritySOAPHandler);
    handlerChain.add(this.inboundAttachmentsSOAPHandler);
    // handlerChain.add(new LoggingHandler());
    // LoggingHandler makes CXF fail on the attachments.
    // https://issues.apache.org/jira/browse/CXF-5496
    binding.setHandlerChain(handlerChain);
}

From source file:be.agiv.security.client.SecureConversationClient.java

/**
 * Main constructor. The given location is the same as where the actual
 * business web service is running./*from   w  ww  . j a v  a  2 s.  c o m*/
 * 
 * @param location
 *            the location of the WS-SecureConversation enabled web service.
 */
public SecureConversationClient(String location) {
    this.location = location;
    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.wssObjectFactory = new be.agiv.security.jaxb.wsse.ObjectFactory();

    this.secureRandom = new SecureRandom();
    this.secureRandom.setSeed(System.currentTimeMillis());
}

From source file:be.fedict.trust.client.XKMS2Client.java

/**
 * Registers the logging SOAP handler on the given JAX-WS port component.
 *///from   w ww .  j  a v a 2s  .  c  om
private void registerLoggerHandler(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;
    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new LoggingSoapHandler());
    binding.setHandlerChain(handlerChain);
}

From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java

/**
 * Registers the logging SOAP handler on the given JAX-WS port component.
 * /*from   w w  w .  j  a  va  2s.  co  m*/
 * @param logToFile
 *            log to file or not
 */
protected void registerLoggerHandler(boolean logToFile) {

    BindingProvider bindingProvider = (BindingProvider) this.port;

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new LoggingSoapHandler(logToFile));
    binding.setHandlerChain(handlerChain);
}

From source file:be.e_contract.mycarenet.xkms2.XKMS2Client.java

/**
 * Main constructor./* w  w  w. j  ava  2 s.  c  o  m*/
 * 
 * @param location
 *            the URL of the MyCareNet XKMS 2.0 web service.
 */
public XKMS2Client(String location) {
    XMLKeyManagementService service = XKMS2ServiceFactory.newInstance();
    this.keyServicePort = service.getKeyServiceSoapPort();
    BindingProvider bindingProvider = (BindingProvider) this.keyServicePort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = binding.getHandlerChain();
    this.proofOfPossessionSignatureSOAPHandler = new ProofOfPossessionSignatureSOAPHandler();
    handlerChain.add(new LoggingHandler());
    handlerChain.add(this.proofOfPossessionSignatureSOAPHandler);
    this.keyBindingAuthenticationSignatureSOAPHandler = new KeyBindingAuthenticationSignatureSOAPHandler();
    handlerChain.add(this.keyBindingAuthenticationSignatureSOAPHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.xmldsigObjectFactory = new be.e_contract.mycarenet.jaxb.xmldsig.ObjectFactory();
    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("DatatypeFactory error: " + e.getMessage(), e);
    }

}

From source file:be.fedict.trust.client.XKMS2Client.java

private void registeredWSSecurityHandler(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;
    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsSecurityClientHandler = new WSSecurityClientHandler();
    handlerChain.add(this.wsSecurityClientHandler);
    binding.setHandlerChain(handlerChain);
}

From source file:be.agiv.security.client.IPSTSClient.java

/**
 * Main constructor./*from   w  ww  . j  a  v a2 s .  c om*/
 * 
 * @param location
 *            the location of the IP-STS WS-Trust web service.
 * @param realm
 *            the AGIV R-STS realm.
 * @param secondaryParametersNodeList
 *            the DOM node list that will be used as SecondaryParameters for
 *            RST requests.
 */
public IPSTSClient(String location, String realm, NodeList secondaryParametersNodeList) {
    this.location = location;
    this.realm = realm;

    Provider jaxwsProvider = Provider.provider();
    LOG.debug("JAX-WS provider: " + jaxwsProvider.getClass().getName());

    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    this.wsTrustHandler.setSecondaryParameters(secondaryParametersNodeList);
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.policyObjectFactory = new be.agiv.security.jaxb.wspolicy.ObjectFactory();
    this.addrObjectFactory = new be.agiv.security.jaxb.wsaddr.ObjectFactory();
    this.wssObjectFactory = new be.agiv.security.jaxb.wsse.ObjectFactory();

    this.secureRandom = new SecureRandom();
    this.secureRandom.setSeed(System.currentTimeMillis());
}

From source file:be.fedict.trust.client.XKMS2Client.java

/**
 * Unregister possible logging SOAP handlers on the given JAX-WS port
 * component./*from   w w w  .  ja v  a2s . c o  m*/
 */
private void removeLoggerHandler(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;
    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    Iterator<Handler> iter = handlerChain.iterator();
    while (iter.hasNext()) {
        Handler handler = iter.next();
        if (handler instanceof LoggingSoapHandler) {
            iter.remove();
        }
    }
    binding.setHandlerChain(handlerChain);
}