Examples of HttpResponseBindingData


Examples of org.switchyard.component.http.composer.HttpResponseBindingData

     *
     * @param input the HTTP request message
     * @return the HTTP response message from invocation
     */
    public HttpResponseBindingData invoke(final HttpRequestBindingData input) {
        HttpResponseBindingData response = null;
        try {
            SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
            Exchange exchange = _serviceRef.createExchange(getOperationName(input), inOutHandler);

            // identify ourselves
            exchange.getContext().setProperty(ExchangeCompletionEvent.GATEWAY_NAME, _gatewayName, Scope.EXCHANGE)
                    .addLabels(BehaviorLabel.TRANSIENT.label());

            Message message = _messageComposer.compose(input, exchange);
            _securityContextManager.addCredentials(exchange, input.extractCredentials());
            if (exchange.getContract().getConsumerOperation().getExchangePattern() == ExchangePattern.IN_ONLY) {
                exchange.send(message);
                if (exchange.getState().equals(ExchangeState.FAULT)) {
                    response = (HttpResponseBindingData) _messageComposer.decompose(exchange, new HttpResponseBindingData());
                } else {
                    response = new HttpResponseBindingData();
                }
            } else {
                exchange.send(message);
                exchange = inOutHandler.waitForOut();
                response = (HttpResponseBindingData) _messageComposer.decompose(exchange, new HttpResponseBindingData());
            }
        } catch (Exception e) {
            HttpLogger.ROOT_LOGGER.unexpectedExceptionInvokingSwitchyardServcie(e);
        }
        return response;
View Full Code Here

Examples of org.switchyard.component.http.composer.HttpResponseBindingData

                response = httpclient.execute(request);
            }
            int status = response.getStatusLine().getStatusCode();

            HttpEntity entity = response.getEntity();
            HttpResponseBindingData httpResponse = new HttpResponseBindingData();
            Header[] headers = response.getAllHeaders();
            for (Header header : headers) {
                httpResponse.addHeader(header.getName(), header.getValue());
            }
            if (entity != null) {
                if (entity.getContentType() != null) {
                    httpResponse.setContentType(new ContentType(entity.getContentType().getValue()));
                } else {
                    httpResponse.setContentType(new ContentType());
                }
                httpResponse.setBodyFromStream(entity.getContent());
            }
            httpResponse.setStatus(status);
            Message out = _messageComposer.compose(httpResponse, exchange);
            if (httpResponse.getStatus() < 400) {
                exchange.send(out);
            } else {
                exchange.sendFault(out);
            }
        } catch (Exception e) {
View Full Code Here

Examples of org.switchyard.component.http.composer.HttpResponseBindingData

                if (_classLoader != null) {
                    origCl = Classes.setTCCL(_classLoader);
                   
                }

                HttpResponseBindingData httpResponse = _handler.invoke(httpRequest);
                if (httpResponse != null) {
                    Iterator<Map.Entry<String, List<String>>> entries = httpResponse.getHeaders().entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<String, List<String>> entry = entries.next();
                        String name = entry.getKey();
                        List<String> values = entry.getValue();
                        for (String value : values) {
                            response.addHeader(name, value);
                        }
                    }
                    if (httpResponse.getBodyBytes() != null) {
                        response.setStatus(httpResponse.getStatus());
                        httpResponse.writeBodyToStream(response.getOutputStream());
                    } else {
                        if (httpResponse.getStatus() != null) {
                            response.setStatus(httpResponse.getStatus());
                        } else {
                            // Consider it as a One-Way MEP
                            response.setStatus(HttpServletResponse.SC_ACCEPTED);
                            response.setContentLength(0);
                        }
View Full Code Here

Examples of org.switchyard.component.http.composer.HttpResponseBindingData

                    httpRequest.setHeaders(exchange.getRequestHeaders());
                    httpRequest.setRequestInfo(getRequestInfo(exchange, contentType));
                } catch (IOException e) {
                    HttpLogger.ROOT_LOGGER.unexpectedExceptionWhileReadingRequest(e);
                }
                HttpResponseBindingData httpResponse = _handler.invoke(httpRequest);
                try {
                    if (httpResponse != null) {
                        exchange.getResponseHeaders().putAll(httpResponse.getHeaders());
                        if (httpResponse.getBodyBytes() != null) {
                            exchange.sendResponseHeaders(httpResponse.getStatus(), httpResponse.getBodyBytes().available());
                            httpResponse.writeBodyToStream(exchange.getResponseBody());
                        } else {
                            if (httpResponse.getStatus() != null) {
                                exchange.sendResponseHeaders(httpResponse.getStatus(), 0);
                            } else {
                                exchange.sendResponseHeaders(HttpServletResponse.SC_ACCEPTED, 0);
                            }
                        }
                    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.