根據David的反饋。這是我如何實現它 -
REST類是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;
}
這裏是接口 -
public interface DBOperations {
public String create(String json);
public String read(String json);
public String update(String json);
public String delete(String json);
}
這裏是騾流,這顯示瞭如何的每個方法DBOperations被映射到mule配置中的不同流。
<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>
謝謝大衛。我喜歡這種方法。不過,我面臨[this](http://stackoverflow.com/questions/17224946)問題。任何想法如何解決這個問題? – user1493140