我正在尝试创建一个简单的服务,在该服务中发出 HTTP 请求,获得查询参数的键/值对映射,并返回一些响应。这是我的配置文件的相关部分:
<servlet:http-request-to-parameter-map name="http-request-to-param-map"/>
<pattern:simple-service name="ScenarioIndex"
address="http://localhost:63081/index"
transformer-refs="http-request-to-param-map"
>
<component>
<singleton-object class="com.test.ScenarioIndex"/>
</component>
</pattern:simple-service>
这是 ScenarioIndex 类的相关部分。
public Object scenarioIndex(Map queryParameters) {
return queryParameters.toString();
}
首先,我只想测试查询参数片段是否按照我认为的方式工作,所以我返回查询参数的字符串表示形式。在此之后的真正实现将更加复杂。
服务器启动正常,但是当localhost:63081/index
URL 被命中时,无论有没有查询参数,我都会得到以下异常:
ERROR 2011-06-03 13:29:04,353 [connector.http.mule.default.receiver.2] org.mule.exception.DefaultServiceExceptionStrategy:
********************************************************************************
Message : The object transformed is of type: "SimpleDataType{type=org.mule.transport.NullPayload, mimeType='*/*'}", but the expected return type is "SimpleDataType{type=java.util.Map, mimeType='*/*'}". Message payload is of type: String
Type : org.mule.api.transformer.TransformerMessagingException
Code : MULE_ERROR--2
Payload : /index?param=true
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html
********************************************************************************
Exception stack is:
1. The object transformed is of type: "SimpleDataType{type=org.mule.transport.NullPayload, mimeType='*/*'}", but the expected return type is "SimpleDataType{type=java.util.Map, mimeType='*/*'}". Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractMessageTransformer:183 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
********************************************************************************
Root Exception stack trace:
org.mule.api.transformer.TransformerMessagingException: The object transformed is of type: "SimpleDataType{type=org.mule.transport.NullPayload, mimeType='*/*'}", but the expected return type is "SimpleDataType{type=java.util.Map, mimeType='*/*'}". Message payload is of type: String
at org.mule.transformer.AbstractMessageTransformer.checkReturnClass(AbstractMessageTransformer.java:183)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:162)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:93)
at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:1305)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1265)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1258)
at org.mule.transformer.AbstractTransformer.process(AbstractTransformer.java:118)
at org.mule.processor.ExceptionHandlingMessageProcessor.process(ExceptionHandlingMessageProcessor.java:25)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:185)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:158)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:145)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.doRequest(HttpMessageReceiver.java:247)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.processRequest(HttpMessageReceiver.java:206)
at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:164)
at org.mule.work.WorkerContext.run(WorkerContext.java:309)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Thread.java:680)
如果我取出对 http-request-to-param-map 转换器的引用,我可以接收一个字符串并返回一个字符串。我不明白为什么接收地图会突然阻止我返回字符串。在这方面有什么帮助吗?