[英]Mule ESB Riak connector: How to configure HTTP over SSL endpoints
[英]How to flush xml data in request by using HTTP connector in mule
我正在使用Java組件發送請求,它對我來說工作正常。 代碼是。
public class parseXmlToString implements Callable
{
public Object onCall(MuleEventContext eventContext) throws Exception
{
String xmlData = eventContext.getMessage().getInvocationProperty("sampleXmlData");
String content = URLEncoder.encode(xmlData, "UTF-8");
eventContext.getMessage().setInvocationProperty("xmlData", content);
try
{
URL url = new URL(webServiceURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.connect();
DataOutputStream output = null;
output = new DataOutputStream(conn.getOutputStream());
String content = "xmlData=" + URLEncoder.encode(xmlData, "UTF-8");
output.writeBytes(content);
output.flush();
output.close();
if (conn.getResponseCode() != 200)
{
System.out.println(conn.getResponseCode());
throw new IOException(conn.getResponseMessage());
}
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null)
{
sb.append(line);
}
rd.close();
conn.disconnect();
eventContext.getMessage().setPayload("Import Initiated");
}
catch (Exception e)
{
System.out.println("Failed REST service call. " + e.getMessage());
e.printStackTrace();
}
eventContext.getMessage().setPayload(content);
return eventContext.getMessage().getPayload();enter code here
}
}
現在,我試圖通過在HTTP子中使用HTTP連接器發送請求,為此,我正在使用請求參數發送數據。 的代碼是
<http:request config-ref="HTTP_Request_Configuration1" path="/#flowVars.outputAppName]/services/EmployeeService/importUsers" method="POST" doc:name="HTTP" parseResponse="false">
<http:request-builder>
<http:query-param paramName="serviceId" value="#[flowVars.outputServiceID]"/>
<http:query-param paramName="expiresOn" value="#[flowVars.expiresOnImport]"/>
<http:query-param paramName="importId" value="#[flowVars.importId]"/>
<http:query-param paramName="signature" value="#[flowVars.signatureImport]"/>
<http:header headerName="xmlData" value="#[flowVars.xmlData]"/>
</http:request-builder>
</http:request>
如果我運行它,則出現以下錯誤
ERROR 2015-03-09 11:03:31,251 [[catalystoneconnector].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Response code 500 mapped as failure. Message payload is of type: BufferInputStream
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Response code 500 mapped as failure. Message payload is of type: BufferInputStream (org.mule.module.http.internal.request.ResponseValidatorException)
org.mule.module.http.internal.request.SuccessStatusCodeValidator:37 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/http/internal/request/ResponseValidatorException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.module.http.internal.request.ResponseValidatorException: Response code 500 mapped as failure. Message payload is of type: BufferInputStream
at org.mule.module.http.internal.request.SuccessStatusCodeValidator.validate(SuccessStatusCodeValidator.java:37)
at org.mule.module.http.internal.request.DefaultHttpRequester.innerProcess(DefaultHttpRequester.java:202)
at org.mule.module.http.internal.request.DefaultHttpRequester.process(DefaultHttpRequester.java:166)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
我還嘗試過將XML數據作為查詢參數發送,就像http連接器中的其他參數一樣。 它也不起作用。
我做錯了什么,或者有任何適當的方法以M子的方式進行? 像在請求中發送大型xml嗎?
您需要將實體正文添加到POST請求中。 這是文檔中的示例:
<set-payload value="Hello world" />
<http:request request-config="HTTP_Request_Configuration"
path="test" method="GET" sendBodyMode="ALWAYS" />
因此,對於您的情況,您想要:
<set-payload value="#[flowVars.xmlData]"/>
<http:request config-ref="HTTP_Request_Configuration1"
path="/#flowVars.outputAppName]/services/EmployeeService/importUsers"
method="POST" parseResponse="false"
sendBodyMode="ALWAYS">
<http:request-builder>
<http:query-param paramName="serviceId" value="#[flowVars.outputServiceID]"/>
<http:query-param paramName="expiresOn" value="#[flowVars.expiresOnImport]"/>
<http:query-param paramName="importId" value="#[flowVars.importId]"/>
<http:query-param paramName="signature" value="#[flowVars.signatureImport]"/>
</http:request-builder>
</http:request>
我建議您查看一下提供的http路徑的定義,如下所示:/#flowVars.outputAppName]/services/EmployeeService/importUsers
您可以通過如下重新定義嘗試嗎
#['/'+flowVars.outputAppName+'/services/EmployeeService/importUsers']
@David建議使用set-payload組件設置xml數據,並使用所需的查詢參數集和http連接器方法=“ POST”定義http組件
不知道這是否有幫助,但是我正在尋找一種刷新xml數據的方法並進入了這個主題。 可能無法完全回答這個問題,但是如果有人像我一樣來這里尋找答案,我會遇到以下同樣的疑問:
從響應中刷新xml數據的一種方法是:
...使用Axis2 + SOAP 1.2
OMElement omElement = payloadTypeResponse.getOMElement(ServiceEMEStub.QueryData.MY_QNAME,OMAbstractFactory.getSOAP12Factory());
System.out.println(omElement.toString());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.