两天前,我的应用程序工作正常,但现在我测试时收到错误并且不知道问题是什么。知道应用程序中没有任何变化。所以我的应用程序正在侦听端口并等待json数据,然后将此json发送到Web服务,该服务将发送响应。
这是我的代码片段:
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" contentType="application/json" path="getDetails" />
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
<set-session-variable variableName="tkn" value="#[message.payload.token]" doc:name="token" />
<set-session-variable variableName="msg" value="#[message.payload.msg]" doc:name="message" />
<component doc:name="Java" class="Transformer">
<method-entry-point-resolver>
<include-entry-point method="methhod" />
</method-entry-point-resolver>
</component>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
<logger message=""I can get properties this is app"+#[message.payload.application]+"this is the type"+#[message.payload.type]" level="INFO" doc:name="Logger" />
<http:outbound-endpoint exchange-pattern="request-response" address="http://slice.ws.com/api.php/push/send_test_push" contentType="application/x-www-form-urlencoded" doc:name="HTTP" method="POST">
<set-property propertyName="application" value="#[message.payload.application]" doc:name="Property" />
<set-property propertyName="token" value="#[sessionVars['tkn']]" doc:name="Property" />
<set-property propertyName="user" value="#[message.payload.user]" doc:name="Property" />
<set-property propertyName="type" value="#[message.payload.type]" doc:name="Property" />
<set-property propertyName="message" value="#[sessionVars['msg']]" doc:name="Property" />
</http:outbound-endpoint>
<response>
<http:response-builder status="200" doc:name="HTTP Response Builder" />
</response>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
<logger message=""result"#[message.payload.success]" level="INFO" doc:name="Logger" />
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.json.simple.*;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class Transformer {
JSONObject finalObj = new JSONObject();
public JSONObject methhod(HashMap <String, String> s) {
Map <String, String> studentGrades = s;
Iterator <Map.Entry <String, String>> iterator = studentGrades.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry <String, String> studentEntry = iterator.next();
System.out.println(studentEntry.getKey() + " :: " + studentEntry.getValue());
finalObj.put(studentEntry.getKey(), studentEntry.getValue());
// iterator.remove();
}
System.out.println("json" + finalObj);
return finalObj;
}
}
ERROR 2015-04-13 10:34:47,458 [[applipush].connector.http.mule.default.receiver.03] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to transform from "json" to "java.lang.Object"
Code : MULE_ERROR-109
--------------------------------------------------------------------------------
Exception stack is:
1. Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.InputStreamReader@396e2b; line: 1, column: 2] (org.codehaus.jackson.JsonParseException)
org.codehaus.jackson.JsonParser:1433 (null)
2. Failed to transform from "json" to "java.lang.Object" (org.mule.api.transformer.TransformerException)
org.mule.module.json.transformers.JsonToObject:132 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.InputStreamReader@396e2b; line: 1, column: 2]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
我通过postman发送这个json来测试应用程序:
{
"application": "91",
"token":"APA91bEkK-ghBivQRIm7Rs1HfvmXPZ4i7XpcYMA5NGpN4orsqT",
"user": "1",
"type": "Android",
"msg": "rajeun"
}
答案 0 :(得分:0)
问题在于发送除json之外的数据的Web服务。
答案 1 :(得分:0)
这是修复我希望它能为你效果,如果没有请告诉我。
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" contentType="application/json" path="getDetails" />
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
<set-session-variable variableName="tkn" value="#[message.payload.token]" doc:name="token" />
<set-session-variable variableName="msg" value="#[message.payload.msg]" doc:name="message" />
<component doc:name="Java" class="Transformer">
<method-entry-point-resolver>
<include-entry-point method="methhod" />
</method-entry-point-resolver>
</component>
<logger message=""I can get properties this is app"+#[message.payload.application]+"this is the type"+#[message.payload.type]" level="INFO" doc:name="Logger" />
<http:outbound-endpoint exchange-pattern="request-response" address="http://slice.ws.com/api.php/push/send_test_push" contentType="application/x-www-form-urlencoded" doc:name="HTTP" method="POST">
<set-property propertyName="application" value="#[message.payload.application]" doc:name="Property" />
<set-property propertyName="token" value="#[sessionVars['tkn']]" doc:name="Property" />
<set-property propertyName="user" value="#[message.payload.user]" doc:name="Property" />
<set-property propertyName="type" value="#[message.payload.type]" doc:name="Property" />
<set-property propertyName="message" value="#[sessionVars['msg']]" doc:name="Property" />
</http:outbound-endpoint>
<response>
<http:response-builder status="200" doc:name="HTTP Response Builder" />
</response>
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
<logger message=""result"#[message.payload.success]" level="INFO" doc:name="Logger" />
<json:object-to-json-transformer returnClass="java.util.HashMap" doc:name="Object to JSON" />