Based on feedback from David. Here's how I implemented it -
The REST class is TestAPI -
@Path("/test") public class TestAPI { private DBOperations dbo; @POST @Produces(MediaType.APPLICATION_JSON) public String create(String jsonPayload) { System.out.println("Received and added global attribute :" + jsonPayload); dbo.create(jsonPayload); return jsonPayload; }
Here is the interface -
public interface DBOperations { public String create(String json); public String read(String json); public String update(String json); public String delete(String json); }
Here is a mule stream that shows how each DBOperations method maps to a different stream in a mule configuration.
<flow name="jersey-rest-flow" doc:name="jersey-rest-flow"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8100" doc:name="HTTP" /> <logger message="Message Received - #[payload]" level="INFO" doc:name="Logger" /> <jersey:resources doc:name="REST"> <component class="com.test.rest.TestAPI"> <binding interface="com.test.DBOperations" method="create"> <vm:outbound-endpoint exchange-pattern="request-response" path="create-data-vm" /> </binding> <binding interface="com.test.DBOperations" method="read"> <vm:outbound-endpoint exchange-pattern="request-response" path="read-data-vm" /> </binding> <binding interface="com.test.DBOperations" method="update"> <vm:outbound-endpoint exchange-pattern="request-response" path="update-data-vm" /> </binding> <binding interface="com.test.DBOperations" method="delete"> <vm:outbound-endpoint exchange-pattern="request-response" path="delete-data-vm" /> </binding> </component> </jersey:resources> </flow>
source share