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);
}
}
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;
}
Aggregations