根据大卫的反馈。以下是我的实现方式——
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);
}
这是 mule 流程,它显示了 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>