Search in sources :

Example 1 with AbstractDTOBase

use of org.apache.camel.component.salesforce.api.dto.AbstractDTOBase in project camel by apache.

the class XmlRestProcessor method getRequestStream.

protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
    try {
        // get request stream from In message
        Message in = exchange.getIn();
        InputStream request = in.getBody(InputStream.class);
        if (request == null) {
            AbstractDTOBase dto = in.getBody(AbstractDTOBase.class);
            if (dto != null) {
                // marshall the DTO
                request = getRequestStream(dto);
            } else {
                // if all else fails, get body as String
                final String body = in.getBody(String.class);
                if (null == body) {
                    String msg = "Unsupported request message body " + (in.getBody() == null ? null : in.getBody().getClass());
                    throw new SalesforceException(msg, null);
                } else {
                    request = new ByteArrayInputStream(body.getBytes(StringUtil.__UTF8));
                }
            }
        }
        return request;
    } catch (XStreamException e) {
        String msg = "Error marshaling request: " + e.getMessage();
        throw new SalesforceException(msg, e);
    } catch (UnsupportedEncodingException e) {
        String msg = "Error marshaling request: " + e.getMessage();
        throw new SalesforceException(msg, e);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) XStreamException(com.thoughtworks.xstream.XStreamException) Message(org.apache.camel.Message) AbstractDTOBase(org.apache.camel.component.salesforce.api.dto.AbstractDTOBase) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with AbstractDTOBase

use of org.apache.camel.component.salesforce.api.dto.AbstractDTOBase in project camel by apache.

the class JsonRestProcessor method getRequestStream.

@Override
protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
    InputStream request;
    Message in = exchange.getIn();
    request = in.getBody(InputStream.class);
    if (request == null) {
        AbstractDTOBase dto = in.getBody(AbstractDTOBase.class);
        if (dto != null) {
            // marshall the DTO
            request = getRequestStream(dto);
        } else {
            // if all else fails, get body as String
            final String body = in.getBody(String.class);
            if (null == body) {
                String msg = "Unsupported request message body " + (in.getBody() == null ? null : in.getBody().getClass());
                throw new SalesforceException(msg, null);
            } else {
                request = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
            }
        }
    }
    return request;
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) AbstractDTOBase(org.apache.camel.component.salesforce.api.dto.AbstractDTOBase) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Message (org.apache.camel.Message)2 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 AbstractDTOBase (org.apache.camel.component.salesforce.api.dto.AbstractDTOBase)2 XStreamException (com.thoughtworks.xstream.XStreamException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1