Example usage for javax.xml.ws BindingProvider getBinding

List of usage examples for javax.xml.ws BindingProvider getBinding

Introduction

In this page you can find the example usage for javax.xml.ws BindingProvider getBinding.

Prototype

Binding getBinding();

Source Link

Document

Get the Binding for this binding provider.

Usage

From source file:test.integ.be.fedict.hsm.ws.WSS4JTest.java

@Test
public void testSecurity() throws Exception {
    QName serviceName = new QName("http://www.example.com/test", "TestService");
    Service service = Service.create(serviceName);
    QName portName = new QName("http://www.example.com/test", "TestPort");
    String endpointAddress = this.baseURL + "test";
    LOG.debug("endpoint address: " + endpointAddress);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    BindingProvider bindingProvider = (BindingProvider) dispatch;
    SOAPBinding soapBinding = (SOAPBinding) bindingProvider.getBinding();
    List handlerChain = soapBinding.getHandlerChain();
    handlerChain.add(new WSS4JTestSOAPHandler());
    soapBinding.setHandlerChain(handlerChain);
    MessageFactory messageFactory = soapBinding.getMessageFactory();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    QName payloadName = new QName("http://www.example.com/test", "Payload", "prefix");
    SOAPBodyElement soapBodyElement = soapBody.addBodyElement(payloadName);
    soapBodyElement.addTextNode("hello world");

    SOAPMessage replyMessage = dispatch.invoke(soapMessage);
}

From source file:com.tangfan.test.UserServiceTest.java

@Before
public void init() {
    try {/*  w w  w. ja v  a 2s  .  c  om*/
        URL url = new URL("http://localhost:8085/soap/us?wsdl");
        QName qName = new QName(ns, "UserService");
        ws = new UserService_Service(url, qName);
        //         port = ws.getUserServicePort(new MTOMFeature());
        port = ws.getUserServicePort();
        BindingProvider bp = (BindingProvider) port;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();
        binding.setMTOMEnabled(true);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:de.extra.extraClientLight.util.SendWebService.java

/**
 * //from w ww  . j a v  a  2  s. c  o m
 * @param extraRequest
 * @param url
 * @param mtomActive
 * @return
 */
public TransportResponseType sendRequest(TransportRequestType extraRequest, String url, boolean mtomActive) {
    TransportResponseType response = new TransportResponseType();

    Extra_Service extraService = new Extra_Service(null, SERVICE_NAME);

    Extra extraPort = extraService.getPort(Extra.class);
    BindingProvider bp = (BindingProvider) extraPort;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    SOAPBinding soapBinding = (SOAPBinding) bp.getBinding();
    soapBinding.setMTOMEnabled(mtomActive);

    try {
        LOGGER.debug("Versand gestartet...");
        response = extraPort.execute(extraRequest);
        LOGGER.debug("...Empfang Response");

        if (mtomActive) {
            Collection<Attachment> attachmentList = (Collection<Attachment>) bp.getResponseContext()
                    .get(Message.ATTACHMENTS);

            LOGGER.debug("Attachments: " + attachmentList.size());

        }
    } catch (SOAPFaultException e) {
        SOAPFault soapFault = e.getFault();

        LOGGER.error(soapFault.getTextContent(), e);

    } catch (ExtraFault e) {
        ExtraErrorHelper.printExtraError(e);
    }

    return response;

}

From source file:be.e_contract.mycarenet.consent.ConsentClient.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);
    binding.setHandlerChain(handlerChain);
}

From source file:ebay.dts.client.FileTransferCall.java

public FileTransferServicePort setFTSMessageContext(String callName) throws EbayConnectorException {

    logger.trace("FileTransferActions.setFTSMessageContext(String callName ) ...... ");

    FileTransferServicePort port = null;
    FileTransferService service = new FileTransferService();

    port = service.getFileTransferServiceSOAP();
    BindingProvider bp = (BindingProvider) port;

    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serverURL);
    List handlerList = bp.getBinding().getHandlerChain();
    if (handlerList == null) {
        handlerList = new ArrayList();
    }/*from   www. ja v a  2  s .c  om*/
    LoggingHandler loggingHandler = new LoggingHandler();
    handlerList.add(loggingHandler);
    // register the handerList
    bp.getBinding().setHandlerChain(handlerList);
    // initialize WS operation arguments here
    Map requestProperties = bp.getRequestContext();

    // set http address
    logger.trace("serverURL :" + this.serverURL);

    if (this.serverURL == null) {
        throw new EbayConnectorException(" serverURL can't be null ");
    }
    if (this.userToken == null) {
        throw new EbayConnectorException(" User Token can't be null ");
    }

    requestProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serverURL);
    Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
    httpHeaders.put("X-EBAY-SOA-MESSAGE-PROTOCOL", Collections.singletonList("SOAP12"));
    httpHeaders.put("X-EBAY-SOA-OPERATION-NAME", Collections.singletonList(callName));
    httpHeaders.put("X-EBAY-SOA-SECURITY-TOKEN", Collections.singletonList(this.userToken));
    requestProperties.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

    return port;

}

From source file:be.e_contract.mycarenet.xkms.XKMSClient.java

/**
 * Main constructor./* www. j  av a 2s  . c om*/
 * 
 * @param location
 *            the URL of the MyCareNet XKMS web service.
 */
public XKMSClient(String location) {
    XMLKeyManagementService service = XKMSServiceFactory.newInstance();
    this.port = service.getKeyServiceSoapPort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

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

    this.objectFactory = new ObjectFactory();
    this.xmldsigObjectFactory = new be.e_contract.mycarenet.jaxb.xmldsig.ObjectFactory();
}

From source file:ebay.dts.client.FileTransferCall.java

public FileTransferServicePort setFTSMessageContext() throws EbayConnectorException {
    FileTransferServicePort port = null;
    FileTransferService service = new FileTransferService();

    try {//from   w  ww .j a  v  a 2  s  .  co m

        port = service.getFileTransferServiceSOAP();
        BindingProvider bp = (BindingProvider) port;
        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.serverURL);
        List handlerList = bp.getBinding().getHandlerChain();
        if (handlerList == null) {
            handlerList = new ArrayList();
        }
        LoggingHandler loggingHandler = new LoggingHandler();
        handlerList.add(loggingHandler);
        // register the handerList
        bp.getBinding().setHandlerChain(handlerList);
        // initialize WS operation arguments here
        Map requestProperties = bp.getRequestContext();
        // set http address
        if (this.serverURL == null) {
            throw new Exception(" serverURL can't be null ");

        }
        int timeout = 100;
        requestProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serverURL);
        requestProperties.put(JAXWSProperties.CONNECT_TIMEOUT, timeout);

        Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
        httpHeaders.put("X-EBAY-SOA-MESSAGE-PROTOCOL", Collections.singletonList("SOAP12"));
        httpHeaders.put("X-EBAY-SOA-OPERATION-NAME", Collections.singletonList(this.callName));
        httpHeaders.put("X-EBAY-SOA-SECURITY-TOKEN", Collections.singletonList(this.userToken));

        requestProperties.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

    } catch (Exception e) {
        throw new EbayConnectorException("Errore nel setup uplink: " + e.getMessage(), e);
    }

    return port;

}

From source file:be.e_contract.mycarenet.ehbox.EHealthBoxPublicationClient.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(new LoggingHandler());
    handlerChain.add(this.payloadLogicalHandler);
    binding.setHandlerChain(handlerChain);
}

From source file:be.fedict.eid.idp.sp.protocol.ws_federation.sts.SecurityTokenServiceClient.java

/**
 * Main constructor.//  ww w .ja  v a  2  s  .  c  om
 * 
 * @param location
 *            the location of the STS service.
 */
public SecurityTokenServiceClient(String location) {
    SecurityTokenService securityTokenService = SecurityTokenServiceFactory.getInstance();

    this.port = securityTokenService.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

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

    this.objectFactory = new ObjectFactory();
    this.policyObjectFactory = new be.fedict.eid.idp.wstrust.jaxb.wspolicy.ObjectFactory();
    this.addrObjectFactory = new be.fedict.eid.idp.wstrust.jaxb.wsaddr.ObjectFactory();
    this.wsseObjectFactory = new be.fedict.eid.idp.wstrust.jaxb.wsse.ObjectFactory();
}

From source file:be.e_contract.mycarenet.certra.CertRAClient.java

public CertRAClient(String location) {
    CertRaService certRaService = CertRaServiceFactory.newInstance();
    this.port = certRaService.getCertRaPort();

    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new LoggingHandler());
    // LoggingHandler makes CXF fail on the attachments.
    // https://issues.apache.org/jira/browse/CXF-5496
    binding.setHandlerChain(handlerChain);

    this.protocolObjectFactory = new be.e_contract.mycarenet.certra.jaxb.protocol.ObjectFactory();
}