Skip to content

Commit

Permalink
Updated SOAP Exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuncle committed Nov 20, 2018
1 parent e909a7e commit 0335b2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.jbuncle.hnapclient</groupId>
<artifactId>hnap-client</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<packaging>jar</packaging>
<properties>
<build.number>0</build.number>
Expand Down
36 changes: 28 additions & 8 deletions src/main/java/uk/co/jbuncle/hnapclient/soap/BasicSoapClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.net.URL;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import uk.co.jbuncle.hnapclient.http.HttpClientI;
Expand All @@ -31,17 +33,35 @@ private String soapBody(final String payload) {
+ "<soap:Body>" + payload + "</soap:Body></soap:Envelope>";
}

public String soapPost(final URL url, final String soapAction,
final Map<String, String> headers, final String body) throws SoapException {
public String soapPost(
final URL url,
final String soapAction,
final Map<String, String> headers,
final String body
) throws SoapException {
final String soapBody = this.soapBody(body);
headers.put("Content-Type", "text/xml; charset=utf-8");
headers.put("SOAPAction", '"' + soapAction + '"');

final String urlString = url.toString();

final String result;
try {
result = this.httpClient.post(urlString, headers, soapBody);
}
catch (HttpException ex) {
throw new SoapException("Request to '" + urlString + "' failed", ex);
}

if (result.isEmpty()) {
throw new SoapException("Recieved empty response body from '" + urlString + "'");
}

try {
final String soapBody = this.soapBody(body);
headers.put("Content-Type", "text/xml; charset=utf-8");
headers.put("SOAPAction", '"' + soapAction + '"');
String result = this.httpClient.post(url.toString(), headers, soapBody);
return getSoapBody(result);
}
catch (HttpException | XMLException ex) {
throw new SoapException(ex);
catch (XMLException ex) {
throw new SoapException("Response body from '" + urlString + "' is not valid XML'" + result + "'", ex);
}
}

Expand Down

0 comments on commit 0335b2e

Please sign in to comment.