我试图让基本的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)
答案 0 :(得分:2)
您的配置与Mule 3.3.0(在Tomcat外部在Eclipse中测试)运行良好,所以我怀疑问题来自Web应用程序类路径中丢失或重复的JAR。
检查在WEB-INF/lib
中打包的JAR以及在Tomcat的/lib
目录中可能手动添加的JAR。
答案 1 :(得分: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
答案 2 :(得分: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>