我有Spring Jersey API,它将webhook负载发送到外部服务器。当前响应是在application / json和application / x-www-form-urlencoded中。我想要SOAP-XML格式的负载,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<req:ResponseMsg xmlns:req="http://cps.taat.com/cpsinterface/request"><!
[CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Response>
<ResponseCode>0</ResponseCode>
<ResponseDesc>Process service request successfully.</ResponseDesc>
<OriginatorConversationID>S_X2013012921001</OriginatorConversationID>
</Response>]]></req:ResponseMsg>
</soapenv:Body>
</soapenv:Envelope>
我在json中的webhook有效负载如下:
{"officeId":1,"clientId":1787,"resourceId":1787}.
在我的webhook服务中,我有:
import retrofit.Callback;
import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.FieldMap;
import retrofit.http.FormUrlEncoded;
import com.google.gson.JsonObject;
@POST("/")
void sendJsonRequest(@Header(ENTITY_HEADER) String entityHeader,
@Header(ACTION_HEADER) String actionHeader,
@Header(TENANT_HEADER) String tenantHeader,
@Header(ENDPOINT_HEADER) String endpointHeader,
@Body JsonObject result, Callback<Response> callBack);
@FormUrlEncoded
@POST("/")
void sendFormRequest(@Header(ENTITY_HEADER) String entityHeader,
@Header(ACTION_HEADER) String actionHeader,
@Header(TENANT_HEADER) String tenantHeader,
@Header(ENDPOINT_HEADER) String endpointHeader,
@FieldMap Map<String, String> params, Callback<Response> callBack);
在Implementantion类中,我有:
@SuppressWarnings("unchecked")
private void sendRequest(final String url, final String contentType,
final String payload, final String entityName,
final String actionName, final String tenantIdentifier,
@SuppressWarnings("unused") final String authToken) {
final String fineractEndpointUrl = System.getProperty("baseUrl");
final WebHookService service = ProcessorHelper
.createWebHookService(url);
@SuppressWarnings("rawtypes")
final Callback callback = ProcessorHelper.createCallback(url);
if (contentType.equalsIgnoreCase("json")
|| contentType.contains("json")) {
final JsonObject json = new JsonParser().parse(payload)
.getAsJsonObject();
service.sendJsonRequest(entityName, actionName, tenantIdentifier,
weseEndpointUrl, json, callback);
} else {
Map<String, String> map = new HashMap<>();
map = new Gson().fromJson(payload, map.getClass());
service.sendFormRequest(entityName, actionName, tenantIdentifier,
weseEndpointUrl, map, callback);
}
我不确定我如何使用WSO2 ESB生成格式,因为它需要在WSO2 Carbon服务器中嵌入一个tomcat实例。当前,我的API运行在独立的Tomcat容器中。我不想重构应用程序的体系结构。关于如何使用现有Retrofit / GSON库或更好的WS02方法进行解析的任何帮助。