2

我正在尝试让基本的 http rest helloworld 示例在 Mule 中工作,但出现此错误

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

这是我的配置文件:

<?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>

还有我的球衣服务班

@Path("version")
public class AdminApi {

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

我正在尝试使用以下方式访问服务:

http://localhost:8081/api/version

我认为这应该是正确的网址,但没有运气,我总是收到上述异常消息。

任何人都知道这可能是什么?

编辑:

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)
4

3 回答 3

2

您的配置在 Mule 3.3.0 上运行得很好(在 Tomcat 之外,在 Eclipse 中测试),所以我怀疑问题来自您的 Web 应用程序类路径中缺少或重复的 JAR。

检查打包的 JAR和可能在 Tomcat目录WEB-INF/lib中手动添加的 JAR 。/lib

于 2012-11-21T16:40:51.833 回答
0
<flow name="HelloWorld">
    <inbound-endpoint address="http://localhost:8081/api"/>
    <jersey:resources>
        <component class="com.helloworld.AdminApi"/>
    </jersey:resources>
</flow> 

并使用此网址。http://localhost:8081/api/version 结果是 -Version 999

于 2015-05-28T09:39:10.993 回答
0

如果您使用 Mule Studio 3.3.0 运行,则必须输入 mimeType。例子:

   <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>
于 2017-08-31T09:52:51.040 回答