Java Code Examples for org.apache.cxf.message.Exchange#getInFaultMessage()

The following examples show how to use org.apache.cxf.message.Exchange#getInFaultMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Exception getException(Exchange exchange) {
    if (exchange.getInFaultMessage() != null) {
        return exchange.getInFaultMessage().getContent(Exception.class);
    } else if (exchange.getOutFaultMessage() != null) {
        return exchange.getOutFaultMessage().getContent(Exception.class);
    } else if (exchange.getInMessage() != null) {
        return exchange.getInMessage().getContent(Exception.class);
    }
    return null;
}
 
Example 2
Source File: ExchangeUtils.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
public static Exception getException(Exchange exchange) {
    Exception throwable = exchange.get(Exception.class);

    if (exchange.getInFaultMessage() != null) {
        return exchange.getInFaultMessage().getContent(Exception.class);
    } else if (exchange.getOutFaultMessage() != null) {
        return exchange.getOutFaultMessage().getContent(Exception.class);
    }

    if (throwable != null) {
        return throwable;
    }

    throwable = getException(exchange.getOutMessage());

    if (throwable != null) {
        return throwable;
    }

    throwable = getException(exchange.getInMessage());

    if (throwable != null) {
        return throwable;
    }

    return null;
}
 
Example 3
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected Message getInBoundMessage(Exchange ex) {
    return  (ex.getInFaultMessage() != null)
               ? ex.getInFaultMessage()
               : ex.getInMessage();
}
 
Example 4
Source File: AbstractClient.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws Exception {
    Response response = exchange.get(Response.class);
    if (response != null) {
        outMessage.getExchange().getInMessage().put(Message.PROTOCOL_HEADERS, response.getStringHeaders());
        return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response));
    }

    Integer status = getResponseCode(exchange);
    ResponseBuilder currentResponseBuilder = JAXRSUtils.toResponseBuilder(status);

    Message responseMessage = exchange.getInMessage() != null
        ? exchange.getInMessage() : exchange.getInFaultMessage();
    // if there is no response message, we just send the response back directly
    if (responseMessage == null) {
        return currentResponseBuilder;
    }

    Map<String, List<Object>> protocolHeaders =
        CastUtils.cast((Map<?, ?>)responseMessage.get(Message.PROTOCOL_HEADERS));

    boolean splitHeaders = MessageUtils.getContextualBoolean(outMessage, HEADER_SPLIT_PROPERTY);
    for (Map.Entry<String, List<Object>> entry : protocolHeaders.entrySet()) {
        if (null == entry.getKey()) {
            continue;
        }
        if (entry.getValue().size() > 0) {
            if (HttpUtils.isDateRelatedHeader(entry.getKey())) {
                currentResponseBuilder.header(entry.getKey(), entry.getValue().get(0));
                continue;
            }
            entry.getValue().forEach(valObject -> {
                if (splitHeaders && valObject instanceof String) {
                    String val = (String) valObject;
                    final String[] values;
                    if (val.isEmpty()) {
                        values = new String[]{""};
                    } else if (val.charAt(0) == '"' && val.charAt(val.length() - 1) == '"') {
                        // if the value starts with a quote and ends with a quote, we do a best
                        // effort attempt to determine what the individual values are.
                        values = parseQuotedHeaderValue(val);
                    } else {
                        boolean splitPossible = !(HttpHeaders.SET_COOKIE.equalsIgnoreCase(entry.getKey())
                                && val.toUpperCase().contains(HttpHeaders.EXPIRES.toUpperCase()));
                        values = splitPossible ? val.split(",") : new String[]{val};
                    }
                    for (String s : values) {
                        String theValue = s.trim();
                        if (!theValue.isEmpty()) {
                            currentResponseBuilder.header(entry.getKey(), theValue);
                        }
                    }
                } else {
                    currentResponseBuilder.header(entry.getKey(), valObject);
                }
            });
        }
    }
    String ct = (String)responseMessage.get(Message.CONTENT_TYPE);
    if (ct != null) {
        currentResponseBuilder.type(ct);
    }
    InputStream mStream = responseMessage.getContent(InputStream.class);
    currentResponseBuilder.entity(mStream);

    return currentResponseBuilder;
}