Example usage for javax.xml.ws BindingProvider getResponseContext

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

Introduction

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

Prototype

Map<String, Object> getResponseContext();

Source Link

Document

Get the context that resulted from processing a response message.

Usage

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

/**
 * //  w  ww .  jav  a 2s .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:ebay.dts.client.BulkDataExchangeCall.java

private Map<String, Object> retrieveHttpHeaders(BindingProvider bp, String headerType) {

    logger.trace("headerType " + headerType);

    Map<String, Object> headerM = null;
    Map<String, Object> contextMap = null;
    String headerTypeName = null;
    if (headerType.equalsIgnoreCase("request")) {
        headerTypeName = "javax.xml.ws.http.request.headers";
        contextMap = bp.getRequestContext();
    } else {/*from w w  w . j  a  v  a 2s  . com*/
        headerTypeName = "javax.xml.ws.http.response.headers";
        contextMap = bp.getResponseContext();
    }

    if (contextMap != null) {
        dumpMap(headerType + " context", contextMap);
        Map requestHeaders = (Map<String, List<String>>) contextMap.get(headerTypeName);
        if (requestHeaders != null) {
            headerM = insertHttpsHeadersMap(headerType, requestHeaders);
        }

    }
    return headerM;
}

From source file:org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsProducer.java

@Override
public void process(Exchange exchange) throws Exception {
    // prepare//from   ww w  .ja va2 s. c o m
    InType body = exchange.getIn().getMandatoryBody(requestClass);
    Object client = getClient();
    configureClient(client);
    BindingProvider bindingProvider = (BindingProvider) client;
    WrappedMessageContext requestContext = (WrappedMessageContext) bindingProvider.getRequestContext();
    cleanRequestContext(requestContext);

    enrichRequestContext(exchange, requestContext);
    processUserDefinedOutgoingHeaders(requestContext, exchange.getIn(), true);

    // set request encoding based on Camel exchange property
    String requestEncoding = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
    if (requestEncoding != null) {
        requestContext.put(org.apache.cxf.message.Message.ENCODING, requestEncoding);
    }

    // get and analyse WS-Addressing asynchrony configuration
    String replyToUri = getWsTransactionConfiguration().isAllowAsynchrony()
            ? exchange.getIn().getHeader(AbstractWsEndpoint.WSA_REPLYTO_HEADER_NAME, String.class)
            : null;
    if ((replyToUri != null) && replyToUri.trim().isEmpty()) {
        replyToUri = null;
    }

    // for asynchronous interaction: configure WSA headers and store correlation data
    if ((replyToUri != null)
            || Boolean.TRUE.equals(requestContext.get(AsynchronyCorrelator.FORCE_CORRELATION))) {
        String messageId = "urn:uuid:" + UUID.randomUUID().toString();
        configureWSAHeaders(messageId, replyToUri, requestContext);

        AbstractWsEndpoint endpoint = (AbstractWsEndpoint) getEndpoint();
        AsynchronyCorrelator correlator = endpoint.getCorrelator();
        correlator.storeServiceEndpointUri(messageId, endpoint.getEndpointUri());

        String correlationKey = exchange.getIn().getHeader(AbstractWsEndpoint.CORRELATION_KEY_HEADER_NAME,
                String.class);
        if (correlationKey != null) {
            correlator.storeCorrelationKey(messageId, correlationKey);
        }

        String[] alternativeKeys = getAlternativeRequestKeys(exchange);
        if (alternativeKeys != null) {
            correlator.storeAlternativeKeys(messageId, alternativeKeys);
        }
    }

    // invoke
    exchange.setPattern((replyToUri == null) ? ExchangePattern.InOut : ExchangePattern.InOnly);
    OutType result = null;
    try {
        // normalize response type when called via reflection or similar non-type-safe mechanisms
        result = responseClass.cast(callService(client, body));
    } catch (SOAPFaultException fault) {
        // handle http://www.w3.org/TR/2006/NOTE-soap11-ror-httpbinding-20060321/
        // see also: https://issues.apache.org/jira/browse/CXF-3768
        if ((replyToUri == null) || (fault.getCause() == null)
                || !fault.getCause().getClass().getName().equals("com.ctc.wstx.exc.WstxEOFException")) {
            throw fault;
        }
    }

    // for synchronous interaction (replyToUri == null): handle response.
    // (async responses are handled in the service instance derived from 
    // org.openehealth.ipf.platform.camel.ihe.ws.AbstractAsyncResponseWebService)
    if (replyToUri == null) {
        Message responseMessage = Exchanges.resultMessage(exchange);
        responseMessage.getHeaders().putAll(exchange.getIn().getHeaders());
        WrappedMessageContext responseContext = (WrappedMessageContext) bindingProvider.getResponseContext();
        processIncomingHeaders(responseContext, responseMessage);
        enrichResponseMessage(responseMessage, responseContext);

        // set Camel exchange property based on response encoding
        exchange.setProperty(Exchange.CHARSET_NAME,
                responseContext.get(org.apache.cxf.message.Message.ENCODING));
        responseMessage.setBody(result, responseClass);
    }
}