use of org.mule.runtime.core.api.transformer.TransformerException in project mule by mulesoft.
the class ObjectToString method createStringFromInputStream.
protected String createStringFromInputStream(InputStream input, Charset outputEncoding) throws TransformerException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
copyLarge(input, outputStream);
return outputStream.toString(outputEncoding.name());
} catch (IOException e) {
throw new TransformerException(errorReadingStream(), e);
} finally {
try {
input.close();
} catch (IOException e) {
logger.warn("Could not close stream", e);
}
}
}
use of org.mule.runtime.core.api.transformer.TransformerException in project mule by mulesoft.
the class ExtendedTransformationService method canSkipTransformer.
private boolean canSkipTransformer(Message message, List<? extends Transformer> transformers, int index) {
Transformer transformer = transformers.get(index);
boolean skipConverter = false;
if (transformer instanceof Converter) {
if (index == transformers.size() - 1) {
try {
checkTransformerReturnClass(transformer, message.getPayload().getValue());
skipConverter = true;
} catch (TransformerException e) {
// Converter cannot be skipped
}
} else {
skipConverter = true;
}
}
if (skipConverter) {
logger.debug("Skipping converter: " + transformer);
}
return skipConverter;
}
use of org.mule.runtime.core.api.transformer.TransformerException in project mule by mulesoft.
the class ByteArrayToObject method doTransform.
@Override
public Object doTransform(Object src, Charset encoding) throws TransformerException {
if (src instanceof byte[]) {
byte[] bytes = (byte[]) src;
if (this.checkStreamHeader(bytes[0])) {
return super.doTransform(src, encoding);
} else {
return new String(bytes, encoding);
}
} else {
try {
return ifInputStream(src, stream -> {
try {
PushbackInputStream pushbackStream = new PushbackInputStream(stream);
int firstByte = pushbackStream.read();
pushbackStream.unread((byte) firstByte);
if (this.checkStreamHeader((byte) firstByte)) {
return super.doTransform(pushbackStream, encoding);
} else {
try {
return org.apache.commons.io.IOUtils.toString(pushbackStream, encoding);
} finally {
// this also closes the underlying stream that's stored in src
pushbackStream.close();
}
}
} catch (IOException iox) {
throw new TransformerException(this, iox);
}
});
} catch (NotAnInputStreamException e) {
throw new TransformerException(transformOnObjectUnsupportedTypeOfEndpoint(this.getName(), src.getClass()));
}
}
}
use of org.mule.runtime.core.api.transformer.TransformerException in project mule by mulesoft.
the class SoapOperationExecutor method execute.
/**
* {@inheritDoc}
*/
@Override
public Publisher<Object> execute(ExecutionContext<OperationModel> context) {
try {
String serviceId = context.getParameter(SERVICE_PARAM);
ForwardingSoapClient connection = (ForwardingSoapClient) connectionResolver.resolve(context).get();
Map<String, String> customHeaders = connection.getCustomHeaders(serviceId, getOperation(context));
SoapRequest request = getRequest(context, customHeaders);
SoapClient soapClient = connection.getSoapClient(serviceId);
SoapResponse response = connection.getExtensionsClientDispatcher(() -> new ExtensionsClientArgumentResolver(registry, policyManager).resolve(context).get()).map(d -> soapClient.consume(request, d)).orElseGet(() -> soapClient.consume(request));
return justOrEmpty(response.getAsResult(streamingHelperArgumentResolver.resolve(context).get()));
} catch (MessageTransformerException | TransformerException e) {
return error(e);
} catch (Exception e) {
return error(soapExceptionEnricher.enrich(e));
} catch (Throwable t) {
return error(wrapFatal(t));
}
}
Aggregations