Java Code Examples for org.apache.cxf.message.MessageContentsList#isEmpty()

The following examples show how to use org.apache.cxf.message.MessageContentsList#isEmpty() . 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: AbstractClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(Message outMessage) throws Fault {
    MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    OutputStream os = outMessage.getContent(OutputStream.class);
    if (os == null) {
        XMLStreamWriter writer = outMessage.getContent(XMLStreamWriter.class);
        if (writer == null) {
            return;
        }
    }

    Object body = objs.get(0);
    Annotation[] customAnns = (Annotation[])outMessage.get(Annotation.class.getName());
    Type t = outMessage.get(Type.class);
    doWriteBody(outMessage, body, t, customAnns, os);
}
 
Example 2
Source File: CustomHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(final Message message) throws Fault {
    if (isResponseAlreadyHandled(message)) {
        return;
    }
    final MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    final Object responseObj = objs.get(0);
    if (Response.class.isInstance(responseObj)) {
        final Response response = Response.class.cast(responseObj);
        if (is404(message, response)) {
            switchResponse(message);
        }
    } else {
        final Object exchangeStatus = message.getExchange().get(Message.RESPONSE_CODE);
        final int status = exchangeStatus != null ? Integer.class.cast(exchangeStatus) : HttpsURLConnection.HTTP_OK;
        if (status == HttpsURLConnection.HTTP_NOT_FOUND) {
            switchResponse(message);
        }
    }
}
 
Example 3
Source File: MessageModeInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doDataSource(final Message message) {
    MessageContentsList list = (MessageContentsList)message.getContent(List.class);
    //reconstitute all the parts into a Mime data source
    if (message.getAttachments() != null && !message.getAttachments().isEmpty()
        && list != null
        && !list.isEmpty() && list.get(0) instanceof DataSource) {
        list.set(0, new MultiPartDataSource(message, (DataSource)list.get(0)));
    }
}
 
Example 4
Source File: AbstractXmlSecOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object getRequestBody(Message message) {
    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return null;
    }
    return objs.get(0);
}
 
Example 5
Source File: ClientRequestContextImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object getMessageContent() {
    MessageContentsList objs = MessageContentsList.getContentsList(m);
    if (objs == null || objs.isEmpty()) {
        return null;
    }
    return objs.get(0);
}
 
Example 6
Source File: HTTPConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean isChunkingSupported(Message message, String httpMethod) {
    if (HTTP_POST_METHOD.equals(httpMethod)) {
        return true;
    } else if (!HTTP_GET_METHOD.equals(httpMethod)) {
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs != null && !objs.isEmpty()) {
            Object obj = objs.get(0);
            return obj.getClass() != String.class
                || (obj.getClass() == String.class && ((String)obj).length() > 0);
        }
    }
    return false;
}
 
Example 7
Source File: BareOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    Exchange exchange = message.getExchange();
    BindingOperationInfo operation = exchange.getBindingOperationInfo();

    if (operation == null) {
        return;
    }

    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    List<MessagePartInfo> parts = null;
    BindingMessageInfo bmsg = null;
    boolean client = isRequestor(message);

    if (!client) {
        if (operation.getOutput() != null) {
            bmsg = operation.getOutput();
            parts = bmsg.getMessageParts();
        } else {
            // partial response to oneway
            return;
        }
    } else {
        bmsg = operation.getInput();
        parts = bmsg.getMessageParts();
    }

    writeParts(message, exchange, operation, objs, parts);
}
 
Example 8
Source File: StaxDataBindingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("StaxDataBindingInterceptor skipped in HTTP GET method");
        return;
    }

    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();

    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();

    //if body is empty and we have BindingOperationInfo, we do not need to match
    //operation anymore, just return
    if (!StaxUtils.toNextElement(xmlReader) && bop != null) {
        // body may be empty for partial response to decoupled request
        return;
    }

    if (bop == null) {
        Endpoint ep = exchange.getEndpoint();
        bop = ep.getBinding().getBindingInfo().getOperations().iterator().next();
    }

    message.getExchange().put(BindingOperationInfo.class, bop);

    if (isRequestor(message)) {
        parameters.put(bop.getOutput().getMessageParts().get(0), dr.read(xmlReader));
    } else {
        parameters.put(bop.getInput().getMessageParts().get(0), dr.read(xmlReader));
    }


    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}