Example usage for javax.xml.ws Dispatch getRequestContext

List of usage examples for javax.xml.ws Dispatch getRequestContext

Introduction

In this page you can find the example usage for javax.xml.ws Dispatch getRequestContext.

Prototype

Map<String, Object> getRequestContext();

Source Link

Document

Get the context that is used to initialize the message context for request messages.

Usage

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

@SuppressWarnings("unchecked")
private static <T extends Object> T getResponse(QName serviceQName, QName portQName, String endpointAddress,
        HTTPRequestMethod method, T postSource, BindingProperties bindingProperties, Class<T> type,
        Map<String, Object> headerParams) throws WebServiceException {

    Service service = Service.create(serviceQName);
    URI endpointURI;//  w w w . j ava 2s.co m
    try {
        if (bindingProperties != null) {
            // if BindingProperties had endpointAddress defined, then use
            // it instead of the endpointAddress passed in from arguments.
            String endAddress = bindingProperties.getEndpointAddress();
            if (endAddress != null) {
                endpointAddress = endAddress;
            }
        }
        endpointURI = new URI(endpointAddress);
    } catch (URISyntaxException e) {
        throw new WebServiceException(e);
    }

    String endpointPath = null;
    String endpointQueryString = null;
    if (endpointURI != null) {
        endpointPath = endpointURI.getRawPath();
        endpointQueryString = endpointURI.getRawQuery();
    }

    service.addPort(portQName, HTTPBinding.HTTP_BINDING, endpointAddress);

    Dispatch<T> d = service.createDispatch(portQName, type, Service.Mode.MESSAGE);

    Map<String, Object> requestContext = d.getRequestContext();
    requestContext.put(MessageContext.HTTP_REQUEST_METHOD, method.toString());
    requestContext.put(MessageContext.QUERY_STRING, endpointQueryString);
    requestContext.put(MessageContext.PATH_INFO, endpointPath);

    Map<String, List<String>> reqHeaders = null;
    if (bindingProperties != null) {
        String httpBasicAuthUsername = bindingProperties.getHttpBasicAuthUsername();
        if (httpBasicAuthUsername != null) {
            requestContext.put(BindingProvider.USERNAME_PROPERTY, httpBasicAuthUsername);
            String httpBasicAuthPassword = bindingProperties.getHttpBasicAuthPassword();
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, httpBasicAuthPassword);
        }

        int connectionTimeout = bindingProperties.getConnectionTimeout();
        requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, Integer.valueOf(connectionTimeout));

        int requestTimeout = bindingProperties.getRequestTimeout();
        requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, Integer.valueOf(requestTimeout));

        Map<String, List<String>> httpHeaders = bindingProperties.getHttpHeaders();
        if (httpHeaders != null && !httpHeaders.isEmpty()) {
            reqHeaders = (Map<String, List<String>>) requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
            if (reqHeaders == null) {
                reqHeaders = new HashMap<String, List<String>>();
                requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
            }
            for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
                reqHeaders.put(entry.getKey(), entry.getValue());
            }
        }
    }

    // Parameters to pass in http header
    if (headerParams != null && headerParams.size() > 0) {
        if (null == reqHeaders) {
            reqHeaders = new HashMap<String, List<String>>();
        }
        Set<Entry<String, Object>> entries = headerParams.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            List<String> valList = new ArrayList<String>();
            valList.add((String) entry.getValue());
            reqHeaders.put(entry.getKey(), valList);
            requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
        }
    }

    logger.info("Invoking HTTP '" + method + "' request with URL: " + endpointAddress);

    T result = d.invoke(postSource);
    return result;
}

From source file:eu.domibus.ebms3.sender.MSHDispatcher.java

public SOAPMessage dispatch(final SOAPMessage soapMessage, final String pModeKey) throws EbMS3Exception {

    final QName serviceName = new QName("http://domibus.eu", "msh-dispatch-service");
    final QName portName = new QName("http://domibus.eu", "msh-dispatch");
    final javax.xml.ws.Service service = javax.xml.ws.Service.create(serviceName);
    final String endpoint = pModeProvider.getReceiverParty(pModeKey).getEndpoint();
    service.addPort(portName, SOAPBinding.SOAP12HTTP_BINDING, endpoint);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
            javax.xml.ws.Service.Mode.MESSAGE);

    Policy policy = policyFactory
            .parsePolicy(pModeProvider.getLegConfiguration(pModeKey).getSecurity().getPolicy());
    LegConfiguration legConfiguration = pModeProvider.getLegConfiguration(pModeKey);
    dispatch.getRequestContext().put(PolicyConstants.POLICY_OVERRIDE, policy);
    dispatch.getRequestContext().put(ASYMMETRIC_SIG_ALGO_PROPERTY,
            legConfiguration.getSecurity().getSignatureMethod().getAlgorithm());
    dispatch.getRequestContext().put(PMODE_KEY_CONTEXT_PROPERTY, pModeKey);

    TLSClientParameters params = tlsReader.getTlsClientParameters();
    if (params != null && endpoint.startsWith("https://")) {
        Client client = ((DispatchImpl<SOAPMessage>) dispatch).getClient();
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        httpConduit.setTlsClientParameters(params);
    }//  w  ww  . j a v a 2 s. c  o m
    SOAPMessage result;
    try {
        result = dispatch.invoke(soapMessage);
    } catch (WebServiceException e) {
        throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0005, null,
                "error dispatching message to " + endpoint, e, MSHRole.SENDING);
    }
    return result;
}

From source file:com.snaplogic.snaps.checkfree.CheckfreeExecute.java

private void configureDispatch(Dispatch<? extends SOAPMessage> dispatch, String action) {
    if (action == null) {
        return;//from  w  w w  .  ja va2  s  .  c o m
    }
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
    // Some services such as MS, do require the action to be set on the request context.
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, action);
}

From source file:com.snaplogic.snaps.checkfree.CheckfreeExecute.java

@Override
@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument")
protected void process(final Document document, final String inputViewName) {
    String envelope = null;/* w  w  w  .  j av  a  2 s  .  co  m*/
    String strippedEnvelope = null;
    Object documentData = document != null ? document.get() : null;
    List<Header> headerList = soapUtils.buildHeaderList(document, documentData, httpHeaders);
    Header[] headers = headerList.toArray(new Header[0]);
    // remove all previous created ones, its a static registry
    List<Interceptor<? extends Message>> outInterceptors = bus.getOutInterceptors();
    soapUtils.resetInterceptors(outInterceptors, SoapMessageSenderInterceptor.class);

    SoapMessageSenderInterceptor soapMessageSenderInterceptor = new SoapMessageSenderInterceptor(headers,
            trustAllCerts, null, null);
    outInterceptors.add(soapMessageSenderInterceptor);

    try {
        envelope = editorProperty.eval(document);
        if (!useDefaultValueChecked) {
            strippedEnvelope = xmlUtils.stripElementsAndAttributesExceptSOAPHeader(envelope,
                    documentBuilderFactory);
            envelope = strippedEnvelope;
        }

        LOGGER.info(DISPATCHING_SOAP_REQUEST, envelope);
        SOAPMessage soapResponse = invocationService.call(clientBuilder, envelope);
        if (soapResponse == null) {
            return;
        }
        Object data = invocationService.serialize(soapResponse);
        if (data != null) {
            outputViews.write(documentUtility.newDocument(data), document);
            documentCounter.inc();
        }
    } catch (XMLStreamException e) {
        throw new ExecutionException(e, XML_SERIALIZATION_FAILED).withResolutionAsDefect();
    } catch (Exception e) {
        Throwable rootCause = Throwables.getRootCause(e);
        String reason = rootCause.getMessage();
        Map<String, Object> errorMap = Maps.newHashMap();
        errorMap.put(KEY_ERROR, reason);
        errorMap.put(STACKTRACE, Throwables.getStackTraceAsString(e.getCause() != null ? e.getCause() : e));
        SnapDataException dataException = new SnapDataException(documentUtility.newDocument(errorMap), e,
                EXCEPTION_OCCURRED).withReason(reason).withResolution(SOAP_EXCEPTION_RESOLUTION);
        // serialize headers
        Map<String, Object> soapHeaders = Maps.newHashMap();

        Dispatch<SOAPMessage> dispatchClient = clientBuilder.getDispatchClient();
        Map<?, Object> requestContext = dispatchClient.getRequestContext();
        if (requestContext != null) {
            soapUtils.serializeHeader(requestContext, soapHeaders);
        }

        Message message = soapMessageSenderInterceptor.getMessage();
        if (message != null) {
            // protocol headers are the ones passed into the http/s request.
            soapUtils.serializeHeader((Map<?, Object>) message.get(Message.PROTOCOL_HEADERS), soapHeaders);
        }

        for (Header header : headerList) {
            String name = header.getName();
            if (name != null) {
                soapHeaders.put(name, header.getValue());
            }
        }
        errorMap.put(REQUEST_HEADERS, soapHeaders);
        // serialize the envelope
        if (envelope != null) {
            errorMap.put(KEY_ENVELOPE, parseXML2JSON(envelope, xmlUtils));
        }
        if (strippedEnvelope != null) {
            errorMap.put(KEY_STRIPPED_ENVELOPE, parseXML2JSON(strippedEnvelope, xmlUtils));
        }
        errorViews.write(dataException, document);
    }
}

From source file:whitelabel.cloud.wsclient.WebServiceAuthenticator.java

public void authenticateBasic(final Dispatch<SOAPMessage> dispatch, final String username,
        final String password) throws WsAuthenticationException {

    if (dispatch == null) {
        LOG.error(" SoapMessage dispatcher not defined");
        throw new WsAuthenticationException("SOAP_DISPATCHER_NOT_DEFINED");
    }/* w w  w  .  ja  v  a  2  s .  c  om*/
    if (username == null || password == null || username.trim().length() == 0
            || password.trim().length() == 0) {
        LOG.error("Username: " + username + " password: " + password + " - invalid parameters");
        throw new WsAuthenticationException("INVALID_PARAMETERS");
    }
    dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
    dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
}

From source file:io.hummer.util.ws.WebServiceClient.java

private InvocationResult doInvokeSOAP(Element request, List<Element> headers, int retries, String protocol,
        int connectTimeoutMS, int requestTimeoutMS) throws Exception {
    if (retries < 0)
        throw new Exception("Invocation to " + endpointURL + " failed: " + xmlUtil.toString(request));

    // if the service is null here because the WSDL is unavailable, 
    // create a plain HTTP POST invocation..
    if (service == null) {
        return doInvokePOST(request, new HashMap<String, String>(), retries);
    }// ww  w  . ja  v  a2 s. com

    Dispatch<SOAPMessage> dispatch = null;
    synchronized (service) {
        dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    }

    dispatch.getRequestContext().put("com.sun.xml.ws.connect.timeout", connectTimeoutMS);
    dispatch.getRequestContext().put("com.sun.xml.ws.request.timeout", requestTimeoutMS);
    dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", connectTimeoutMS);
    dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", requestTimeoutMS);
    dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
            Collections.singletonMap("Connection", Collections.singletonList("close")));

    try {
        SOAPMessage message = createSOAPMessage(request, headers, protocol);
        String tmpID = PerformanceInterceptor.event(EventType.START_SEND_INVOCATION);
        SOAPMessage response = dispatch.invoke(message);
        PerformanceInterceptor.event(EventType.FINISH_SEND_INVOCATION, tmpID);
        InvocationResult result = new InvocationResult(response.getSOAPBody());
        return result;
    } catch (Exception e) {
        if (!(e.getCause() instanceof ThreadDeath)) {
            //logger.warn("Exception in invocation; to: " + endpointURL + "; " + e);
        }

        if (retries <= 0) {
            throw new Exception("Invocation to " + endpointURL + " failed: " + xmlUtil.toString(request), e);
        }
        if (e instanceof BindException || e.getCause() instanceof BindException) {
            long sleep = 200L + (long) (Math.random() * 800);
            logger.warn("Cannot bind to (client) port, sleeping " + sleep);
            Thread.sleep(sleep);
        }
        request = xmlUtil.clone(request);
        return doInvokeSOAP(request, headers, retries - 1, protocol, connectTimeoutMS, requestTimeoutMS);
    } finally {
        //PerformanceInterceptor.event(EventType.FINISH_INVOCATION, eID);
        //System.out.println(eID + " finished " + endpointURL);
    }
}

From source file:com.snaplogic.snaps.firstdata.Transaction.java

private void configureDispatch(Dispatch<? extends SOAPMessage> dispatch, String action) {
    if (action == null) {
        return;/*from   w  w  w  . ja  v a  2 s .  com*/
    }
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, action);
}

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

private void createDispatch(WebServiceDispatcherProperties webServiceDispatcherProperties,
        DispatchContainer dispatchContainer) throws Exception {
    String wsdlUrl = webServiceDispatcherProperties.getWsdlUrl();
    String username = webServiceDispatcherProperties.getUsername();
    String password = webServiceDispatcherProperties.getPassword();
    String serviceName = webServiceDispatcherProperties.getService();
    String portName = webServiceDispatcherProperties.getPort();

    /*/*from ww w .j  a  v  a2  s  . c  o  m*/
     * The dispatch needs to be created if it hasn't been created yet (null). It needs to be
     * recreated if any of the above variables are different than what were used to create the
     * current dispatch object. This could happen if variables are being used for these
     * properties.
     */
    if (dispatchContainer.getDispatch() == null
            || !StringUtils.equals(wsdlUrl, dispatchContainer.getCurrentWsdlUrl())
            || !StringUtils.equals(username, dispatchContainer.getCurrentUsername())
            || !StringUtils.equals(password, dispatchContainer.getCurrentPassword())
            || !StringUtils.equals(serviceName, dispatchContainer.getCurrentServiceName())
            || !StringUtils.equals(portName, dispatchContainer.getCurrentPortName())) {
        dispatchContainer.setCurrentWsdlUrl(wsdlUrl);
        dispatchContainer.setCurrentUsername(username);
        dispatchContainer.setCurrentPassword(password);
        dispatchContainer.setCurrentServiceName(serviceName);
        dispatchContainer.setCurrentPortName(portName);

        URL endpointUrl = getWsdlUrl(dispatchContainer);
        QName serviceQName = QName.valueOf(serviceName);
        QName portQName = QName.valueOf(portName);

        // create the service and dispatch
        logger.debug("Creating web service: url=" + endpointUrl.toString() + ", service=" + serviceQName
                + ", port=" + portQName);
        Service service = Service.create(endpointUrl, serviceQName);

        Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName, SOAPMessage.class,
                Service.Mode.MESSAGE);

        if (timeout > 0) {
            dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.ws.connect.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.ws.request.timeout", timeout);
        }

        Map<String, List<String>> requestHeaders = (Map<String, List<String>>) dispatch.getRequestContext()
                .get(MessageContext.HTTP_REQUEST_HEADERS);
        if (requestHeaders == null) {
            requestHeaders = new HashMap<String, List<String>>();
        }
        dispatchContainer.setDefaultRequestHeaders(requestHeaders);

        dispatchContainer.setDispatch(dispatch);
    }
}

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

@Override
public Response send(ConnectorProperties connectorProperties, ConnectorMessage connectorMessage) {
    WebServiceDispatcherProperties webServiceDispatcherProperties = (WebServiceDispatcherProperties) connectorProperties;

    eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(),
            getDestinationName(), ConnectionStatusEventType.SENDING));

    String responseData = null;//www  . ja  va 2  s .  c  o m
    String responseError = null;
    String responseStatusMessage = null;
    Status responseStatus = Status.QUEUED;
    boolean validateResponse = false;

    try {
        long dispatcherId = getDispatcherId();
        DispatchContainer dispatchContainer = dispatchContainers.get(dispatcherId);
        if (dispatchContainer == null) {
            dispatchContainer = new DispatchContainer();
            dispatchContainers.put(dispatcherId, dispatchContainer);
        }

        /*
         * Initialize the dispatch object if it hasn't been initialized yet, or create a new one
         * if the connector properties have changed due to variables.
         */
        createDispatch(webServiceDispatcherProperties, dispatchContainer);

        Dispatch<SOAPMessage> dispatch = dispatchContainer.getDispatch();

        configuration.configureDispatcher(this, webServiceDispatcherProperties, dispatch.getRequestContext());

        SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();

        if (webServiceDispatcherProperties.isUseAuthentication()) {
            String currentUsername = dispatchContainer.getCurrentUsername();
            String currentPassword = dispatchContainer.getCurrentPassword();

            dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, currentUsername);
            dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, currentPassword);
            logger.debug("Using authentication: username=" + currentUsername + ", password length="
                    + currentPassword.length());
        }

        // See: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
        String soapAction = webServiceDispatcherProperties.getSoapAction();

        if (StringUtils.isNotEmpty(soapAction)) {
            dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true); // MIRTH-2109
            dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);
        }

        // Get default headers
        Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>(
                dispatchContainer.getDefaultRequestHeaders());

        // Add custom headers
        if (MapUtils.isNotEmpty(webServiceDispatcherProperties.getHeaders())) {
            for (Entry<String, List<String>> entry : webServiceDispatcherProperties.getHeaders().entrySet()) {
                List<String> valueList = requestHeaders.get(entry.getKey());

                if (valueList == null) {
                    valueList = new ArrayList<String>();
                    requestHeaders.put(entry.getKey(), valueList);
                }

                valueList.addAll(entry.getValue());
            }
        }

        dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

        // build the message
        logger.debug("Creating SOAP envelope.");
        AttachmentHandlerProvider attachmentHandlerProvider = getAttachmentHandlerProvider();
        String content = attachmentHandlerProvider.reAttachMessage(webServiceDispatcherProperties.getEnvelope(),
                connectorMessage);
        Source source = new StreamSource(new StringReader(content));
        SOAPMessage message = soapBinding.getMessageFactory().createMessage();
        message.getSOAPPart().setContent(source);

        if (webServiceDispatcherProperties.isUseMtom()) {
            soapBinding.setMTOMEnabled(true);

            List<String> attachmentIds = webServiceDispatcherProperties.getAttachmentNames();
            List<String> attachmentContents = webServiceDispatcherProperties.getAttachmentContents();
            List<String> attachmentTypes = webServiceDispatcherProperties.getAttachmentTypes();

            for (int i = 0; i < attachmentIds.size(); i++) {
                String attachmentContentId = attachmentIds.get(i);
                String attachmentContentType = attachmentTypes.get(i);
                String attachmentContent = attachmentHandlerProvider.reAttachMessage(attachmentContents.get(i),
                        connectorMessage);

                AttachmentPart attachment = message.createAttachmentPart();
                attachment.setBase64Content(new ByteArrayInputStream(attachmentContent.getBytes("UTF-8")),
                        attachmentContentType);
                attachment.setContentId(attachmentContentId);
                message.addAttachmentPart(attachment);
            }
        }

        message.saveChanges();

        if (StringUtils.isNotBlank(webServiceDispatcherProperties.getLocationURI())) {
            dispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                    webServiceDispatcherProperties.getLocationURI());
        }

        boolean redirect = false;
        int tryCount = 0;

        /*
         * Attempt the invocation until we hit the maximum allowed redirects. The redirections
         * we handle are when the scheme changes (i.e. from HTTP to HTTPS).
         */
        do {
            redirect = false;
            tryCount++;

            try {
                DispatchTask<SOAPMessage> task = new DispatchTask<SOAPMessage>(dispatch, message,
                        webServiceDispatcherProperties.isOneWay());
                SOAPMessage result;

                /*
                 * If the timeout is set to zero, we need to do the invocation in a separate
                 * thread. This is because there's no way to get a reference to the underlying
                 * JAX-WS socket, so there's no way to forcefully halt the dispatch. If the
                 * socket is truly hung and the user halts the channel, the best we can do is
                 * just interrupt and ignore the thread. This means that a thread leak is
                 * potentially introduced, so we need to notify the user appropriately.
                 */
                if (timeout == 0) {
                    // Submit the task to an executor so that it's interruptible
                    Future<SOAPMessage> future = executor.submit(task);
                    // Keep track of the task by adding it to our set
                    dispatchTasks.add(task);
                    result = future.get();
                } else {
                    // Call the task directly
                    result = task.call();
                }

                if (webServiceDispatcherProperties.isOneWay()) {
                    responseStatusMessage = "Invoked one way operation successfully.";
                } else {
                    responseData = sourceToXmlString(result.getSOAPPart().getContent());
                    responseStatusMessage = "Invoked two way operation successfully.";
                }
                logger.debug("Finished invoking web service, got result.");

                // Automatically accept message; leave it up to the response transformer to find SOAP faults
                responseStatus = Status.SENT;
            } catch (Throwable e) {
                // Unwrap the exception if it came from the executor
                if (e instanceof ExecutionException && e.getCause() != null) {
                    e = e.getCause();
                }

                // If the dispatch was interrupted, make sure to reset the interrupted flag
                if (e instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }

                Integer responseCode = null;
                String location = null;

                if (dispatch.getResponseContext() != null) {
                    responseCode = (Integer) dispatch.getResponseContext()
                            .get(MessageContext.HTTP_RESPONSE_CODE);

                    Map<String, List<String>> headers = (Map<String, List<String>>) dispatch
                            .getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
                    if (MapUtils.isNotEmpty(headers)) {
                        List<String> locations = headers.get("Location");
                        if (CollectionUtils.isNotEmpty(locations)) {
                            location = locations.get(0);
                        }
                    }
                }

                if (tryCount < MAX_REDIRECTS && responseCode != null && responseCode >= 300
                        && responseCode < 400 && StringUtils.isNotBlank(location)) {
                    redirect = true;

                    // Replace the endpoint with the redirected URL
                    dispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);
                } else {
                    // Leave the response status as QUEUED for NoRouteToHostException and ConnectException, otherwise ERROR
                    if (e instanceof NoRouteToHostException
                            || ((e.getCause() != null) && (e.getCause() instanceof NoRouteToHostException))) {
                        responseStatusMessage = ErrorMessageBuilder.buildErrorResponse("HTTP transport error",
                                e);
                        responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(),
                                "HTTP transport error", e);
                        eventController.dispatchEvent(
                                new ErrorEvent(getChannelId(), getMetaDataId(), connectorMessage.getMessageId(),
                                        ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(),
                                        connectorProperties.getName(), "HTTP transport error.", e));
                    } else if ((e.getClass() == ConnectException.class) || ((e.getCause() != null)
                            && (e.getCause().getClass() == ConnectException.class))) {
                        responseStatusMessage = ErrorMessageBuilder.buildErrorResponse("Connection refused.",
                                e);
                        eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(),
                                connectorMessage.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR,
                                getDestinationName(), connectorProperties.getName(), "Connection refused.", e));
                    } else {
                        if (e instanceof SOAPFaultException) {
                            try {
                                responseData = new DonkeyElement(((SOAPFaultException) e).getFault()).toXml();
                            } catch (DonkeyElementException e2) {
                            }
                        }
                        responseStatus = Status.ERROR;
                        responseStatusMessage = ErrorMessageBuilder
                                .buildErrorResponse("Error invoking web service", e);
                        responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(),
                                "Error invoking web service", e);
                        eventController.dispatchEvent(
                                new ErrorEvent(getChannelId(), getMetaDataId(), connectorMessage.getMessageId(),
                                        ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(),
                                        connectorProperties.getName(), "Error invoking web service.", e));
                    }
                }
            }
        } while (redirect && tryCount < MAX_REDIRECTS);
    } catch (Exception e) {
        responseStatusMessage = ErrorMessageBuilder.buildErrorResponse("Error creating web service dispatch",
                e);
        responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(),
                "Error creating web service dispatch", e);
        eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(),
                connectorMessage.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(),
                connectorProperties.getName(), "Error creating web service dispatch.", e));
    } finally {
        eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(),
                getDestinationName(), ConnectionStatusEventType.IDLE));
    }

    return new Response(responseStatus, responseData, responseStatusMessage, responseError, validateResponse);
}