简体   繁体   中英

Helloworld Mule Rest WS error

I am trying to get the basic http rest helloworld example working in Mule but I get this error

Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException). Message payload is of type: String

This is my config file:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" 
    xsi:schemaLocation="  
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd  
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd  
    http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.3/mule-xml.xsd 
    http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/3.0/mule-jersey.xsd
    http://jersey.apache.org/core http://jersey.apache.org/schemas/core.xsd">

    <flow name="HelloWorld">
        <inbound-endpoint address="http://localhost:8081/api"/>
        <jersey:resources>
            <component class="com.helloworld.AdminApi"/>
        </jersey:resources>
    </flow> 
</mule>

And my jersey service class

@Path("version")
public class AdminApi {

    @GET
    @Produces("text/plain")
    public String sayHelloWithUri() {
        return "Version 999 " ;
    }
}

I am trying to access the service using:

http://localhost:8081/api/version

which I believe should be the right url but no luck I always get the above exception message.

Anyone has an idea what this could be?

EDIT:

Root Exception stack trace:
org.mule.api.registry.ResolverException: There are two transformers that are an exact match for input: "class java.lang.String", output: "class java.io.InputStream". Transformers are: "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)" and "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)"
    at org.mule.transformer.graph.GraphTransformerResolver.resolve(GraphTransformerResolver.java:65)
    at org.mule.registry.TypeBasedTransformerResolver.resolve(TypeBasedTransformerResolver.java:93)
    at org.mule.registry.MuleRegistryHelper.resolveTransformer(MuleRegistryHelper.java:265)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Your configuration runs just fine with Mule 3.3.0 (tested outside of Tomcat, in Eclipse) so I suspect the problem comes from either missing or duplicated JARs on your web application classpath.

Check the JARs that get packaged in WEB-INF/lib and potential manually added JARs in Tomcat's /lib directory.

<flow name="HelloWorld">
    <inbound-endpoint address="http://localhost:8081/api"/>
    <jersey:resources>
        <component class="com.helloworld.AdminApi"/>
    </jersey:resources>
</flow> 

and use this url. http://localhost:8081/api/version result is -Version 999

If you are running with Mule Studio 3.3.0, you must put the mimeType. Example:

   <flow name="RestServiceFlow" doc:name="RestServiceFlow">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083"  doc:name="HTTP" mimeType="application/json"/>
        <jersey:resources doc:name="RESTUTCNotification">
            <component class="example.esb.restApi"/>
        </jersey:resources>
    </flow>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM