@Path("/")
public class RestIntegration {
@GET
@Path("get/{id1}")
@Produces(MediaType.APPLICATION_JSON)
public String getOperation(@PathParam("id1")String id){
System.out.println("GET: Id from UI-->"+id);
return "Your Id is-->"+id;
}
@POST
@Path("/post/{id1}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postOperation(@PathParam("id1")String id){
System.out.println("----INSIDE POST operation----"+id);
return Response.ok("Response from Mule Rest component").build();
}
}
Muleflow:
<flow name="restintegrationFlow1" doc:name="restintegrationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="restint" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.net.rest.RestIntegration"/>
</jersey:resources>
</flow>
使用get方法可以正常工作。 http://localhost:8081/restint/get/10
。
当我通过http://localhost:8081/restint/post/22
时,选择帖子类型,然后点击发送给出以下错误:
ERROR 2014-07-31 11:18:43,337 [[restintegration].connector.http.mule.default.receiver.03] org.mule.exception.DefaultSystemExceptionStrategy:
********************************************************************************
Message : Failed to create MuleMessage
Code : MULE_ERROR-64
--------------------------------------------------------------------------------
Exception stack is:
1. String index out of range: -1 (java.lang.StringIndexOutOfBoundsException)
java.lang.String:1871 (null)
2. Failed to create MuleMessage (org.mule.api.lifecycle.CreateException)
org.mule.transport.AbstractTransportMessageHandler:462 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/lifecycle/CreateException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1871)
at org.mule.transport.http.multipart.MultiPartInputStream.parse(MultiPartInputStream.java:349)
at org.mule.transport.http.multipart.MultiPartInputStream.getParts(MultiPartInputStream.java:304)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
我使用chrome rest客户端来调用url。在休息客户端,我没有在header或paload中传递任何值。
答案 0 :(得分:0)
找到解决方案,在google chrome rest客户端中,我没有在标题中选择内容类型。
答案 1 :(得分:0)
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration" basePath="restint"/>
http://localhost:8081/restint/post/22 它对我有用----- INSIDE POST操作---- 22- 来自Mule Rest组件的回应