0
방금 WIREMOCK을 사용하고 Java에서 XML 템플릿으로 요청을 보내려고했습니다. JSON으로 몇 가지 예를 보았지만 Java로 찾을 수 없었습니다. (I는 XML 파일로 요청 템플릿을 생성하고 웹 서비스로 전송 의미.)WIREMOCK을 사용하여 XML 템플릿으로 SOAP 요청 보내기 (Java)
방금 WIREMOCK을 사용하고 Java에서 XML 템플릿으로 요청을 보내려고했습니다. JSON으로 몇 가지 예를 보았지만 Java로 찾을 수 없었습니다. (I는 XML 파일로 요청 템플릿을 생성하고 웹 서비스로 전송 의미.)WIREMOCK을 사용하여 XML 템플릿으로 SOAP 요청 보내기 (Java)
당신은 간단한 HttpURLConnection의에
샘플 코드 내용 본문으로 내용을 보낼 수 있습니다 :
URL endpoint = null;
endpoint = new URL("https://someurlhere.com");
conn = (HttpURLConnection) endpoint.openConnection();
// Set the necessary header fields
//The SOAPAction is required to be blank
/*The presence and content of the SOAPAction header field can be used by servers such as firewalls to appropriately
filter SOAP request messages in HTTP. The header field value of empty string ("") means that the intent of the SOAP
message is provided by the HTTP Request-URI. No value means that there is no indication of the intent of the message.*/
conn.addRequestProperty("SOAPAction", "");
//Telling the server not to Skip the SOAPAction. It's a mandatory field when we send SOAP Requests.
conn.addRequestProperty("Skip SOAP Action", "false");
conn.addRequestProperty("Content-Type", "text/xml;charset=UTF-8");
//We use POST because we are sending data to the server
conn.setRequestMethod("POST");
//This is required to read response from Server
conn.setDoOutput(true);
//The server has 5 seconds to respond. Else, a timeout occurs and the connection is terminated.
conn.setConnectTimeout(5000);
// Send the request
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(xmlContent);
wr.flush();
// Read the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String temp;
//Reading as long as there is response to read
while ((temp = rd.readLine()) != null) {
response += temp;
}
을 보시다시피 xmlContent라는 문자열을 서버에 보내고 있습니다. 선택한 XML 파일로 내용을 설정하면 효과가 있습니다.
실제로, 나는 wiremock으로 할 수있는 더 간단한 해결책을 찾고 있었지만, 역시 도움이 될 수 있습니다. 당신의 노력에 너무 감사합니다 :). –