Search in sources :

Example 16 with TransformerException

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);
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Example 17 with TransformerException

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;
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MessageTransformer(org.mule.runtime.core.api.transformer.MessageTransformer) Converter(org.mule.runtime.core.api.transformer.Converter) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Example 18 with TransformerException

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()));
        }
    }
}
Also used : NotAnInputStreamException(org.mule.runtime.core.api.util.NotAnInputStreamException) PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException) CoreMessages.transformOnObjectUnsupportedTypeOfEndpoint(org.mule.runtime.core.api.config.i18n.CoreMessages.transformOnObjectUnsupportedTypeOfEndpoint) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Example 19 with TransformerException

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));
    }
}
Also used : HEADERS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.HEADERS_PARAM) Exceptions.wrapFatal(org.mule.runtime.core.api.rx.Exceptions.wrapFatal) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) BindingContext(org.mule.runtime.api.el.BindingContext) MuleExpressionLanguage(org.mule.runtime.api.el.MuleExpressionLanguage) ComponentExecutor(org.mule.runtime.extension.api.runtime.operation.ComponentExecutor) ATTACHMENTS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.ATTACHMENTS_PARAM) HashMap(java.util.HashMap) SoapRequestBuilder(org.mule.runtime.soap.api.message.SoapRequestBuilder) Inject(javax.inject.Inject) ExtensionsClientArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExtensionsClientArgumentResolver) ConnectionArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionArgumentResolver) MESSAGE_GROUP(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.MESSAGE_GROUP) SoapClient(org.mule.runtime.soap.api.client.SoapClient) Map(java.util.Map) SoapResponse(org.mule.runtime.soap.api.message.SoapResponse) Registry(org.mule.runtime.api.artifact.Registry) IOUtils(org.mule.runtime.core.api.util.IOUtils) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) Mono.error(reactor.core.publisher.Mono.error) INPUT_STREAM(org.mule.runtime.api.metadata.DataType.INPUT_STREAM) BODY_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.BODY_PARAM) TransformationService(org.mule.runtime.api.transformation.TransformationService) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) OPERATION_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.OPERATION_PARAM) DataType(org.mule.runtime.api.metadata.DataType) Publisher(org.reactivestreams.Publisher) SoapRequest(org.mule.runtime.soap.api.message.SoapRequest) Mono.justOrEmpty(reactor.core.publisher.Mono.justOrEmpty) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) SoapAttachment(org.mule.runtime.extension.api.soap.SoapAttachment) SERVICE_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.SERVICE_PARAM) TypedValue(org.mule.runtime.api.metadata.TypedValue) TRANSPORT_HEADERS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.TRANSPORT_HEADERS_PARAM) StreamingHelperArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StreamingHelperArgumentResolver) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) ExtensionsClient(org.mule.runtime.extension.api.client.ExtensionsClient) Optional(java.util.Optional) SoapExceptionEnricher(org.mule.runtime.soap.api.exception.error.SoapExceptionEnricher) InputStream(java.io.InputStream) SoapClient(org.mule.runtime.soap.api.client.SoapClient) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) SoapRequest(org.mule.runtime.soap.api.message.SoapRequest) SoapResponse(org.mule.runtime.soap.api.message.SoapResponse) ExtensionsClientArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExtensionsClientArgumentResolver) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Aggregations

TransformerException (org.mule.runtime.core.api.transformer.TransformerException)19 Transformer (org.mule.runtime.core.api.transformer.Transformer)10 Test (org.junit.Test)5 IOException (java.io.IOException)4 DataType (org.mule.runtime.api.metadata.DataType)4 MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)4 InputStream (java.io.InputStream)3 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)3 Message (org.mule.runtime.api.message.Message)2 AbstractTransformer (org.mule.runtime.core.api.transformer.AbstractTransformer)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 SmallTest (org.mule.tck.size.SmallTest)2 Apple (org.mule.tck.testmodels.fruit.Apple)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PushbackInputStream (java.io.PushbackInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Lock (java.util.concurrent.locks.Lock)1