I have a simple Mule flow setup with a servlet inbound endpoint, which calls a REST service:
<flow name="sandboxFlow" doc:name="sandboxFlow">
<servlet:inbound-endpoint path="rest" responseTimeout="10000" doc:name="Servlet"/>
<set-payload value="#[message.inboundProperties['http.query.params']]" doc:name="Set Payload"/>
<logger message="Payload is #[message.payload]" level="INFO" doc:name="Logger"/>
<jersey:resources doc:name="REST">
<component class="com.csc.rest.service.PersonService">
</jersey:resources>
</flow>
By the way, the reason I am using a servlet endpoint is because this is running in a JBoss webapp.
Here is a simple html/jquery/ajax client i made to call the REST service:
$(document).ready(function(){
$("#buttonEnroll").click(function(){
var name = $("#textName").val();
var ssn = $("#textSsn").val();
var params = "name="+name+"&ssn="+ssn;
$.ajax({
type: "POST"
url: "esb/rest/PersonService",
data: params,
cache: false,
success: function(data){
alert("POST success: " + data);
}
});
});
});
The problem is that the parameters are not being passed to the REST service. The service is getting called, but I have a NullPayload.
If I change my endpoint to HTTP, and run this same app in the Mule container instead of JBoss, then it works. The parameters do pass. But with a servlet endpoint in JBoss, the parameters are lost. Here is the output from the logger component:
INFO [org.mule.api.processor.LoggerMessageProcessor] (default task-2) Payload is null
Any idea how to fix this? I need to be able to POST data to the REST service
This is just a starting point, I am hoping to get working before adding more components to the project.
EDIT: Adding web.xml to show mule config and structure of PersonService
Web.xml:
<context-param>
<param-name>org.mule.config</param-name>
<param-value>mule-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<servlet>
<servlet-name>muleServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>muleServlet</servlet-name>
<url-pattern>/esb/*</url-pattern>
</servlet-mapping>
PersonService
@Path("/PersonService")
@RequestScoped
public class PersonService {
PersonManager manager = PersonManager.newPersonManager();
@POST
public String addPerson(String input) {
System.out.println("addPerson: input=" + input.toString());
HashMap<String,String> params = Toolbox.parseParameters(input)
String name = params.get("name");
String ssn = params.get("ssn");
if(name != null && ssn != null) {
Person person = new Person(name, ssn);
manager.persist(person);
}
return "person added: " + name + ";" + ssn;
}
}
com.csc.rest.service.PersonService
(no method content, just class/methods so we can see the annotations. – David Dossotinput
String that contains"NullPayload"
? – David Dossot