Skip to content

Commit

Permalink
Merge pull request #516 from scireum/feature/fha/SE-13428-SOAP-Conten…
Browse files Browse the repository at this point in the history
…t-Type

Allows defining a custom Content-Type header for SOAP requests.
  • Loading branch information
fhaScireum authored Feb 12, 2024
2 parents c988357 + 0d96e38 commit 0210779
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/sirius/kernel/xml/SOAPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ public class SOAPClient {
*/
public static final String SOAP_TIMEOUT_CONFIG_KEY = "soap";

private static final String DEFAULT_CONTENT_TYPE_HEADER = "text/xml";

private final URL endpoint;
private final BasicNamespaceContext namespaceContext = new BasicNamespaceContext();
private List<Attribute> namespaceDefinitions;
private String actionPrefix = "";
private String contentTypeHeader = DEFAULT_CONTENT_TYPE_HEADER;
private Consumer<XMLCall> callEnhancer;
private final Map<String, URL> customEndpoints = new HashMap<>();
private Consumer<BiConsumer<String, Object>> defaultParameterProvider;
Expand Down Expand Up @@ -169,6 +172,18 @@ public SOAPClient withActionPrefix(@Nonnull String prefix) {
return this;
}

/**
* Defines a custom value for the "Content-Type" HTTP header to use for requests. By default, the header is set
* to {@link #DEFAULT_CONTENT_TYPE_HEADER}.
*
* @param contentTypeHeader the content type to use for requests
* @return the client itself for fluent method calls
*/
public SOAPClient withCustomContentTypeHeader(@Nonnull String contentTypeHeader) {
this.contentTypeHeader = contentTypeHeader;
return this;
}

/**
* Permits to modify the <tt>XMLCall</tt> and its underlying <tt>Outcall</tt> right before it is sent to the server.
*
Expand Down Expand Up @@ -311,7 +326,8 @@ public StructuredNode call(@Nonnull String action,

try (Operation op = new Operation(() -> Strings.apply("SOAP %s -> %s", action, effectiveEndpoint),
Duration.ofSeconds(15))) {
XMLCall call = XMLCall.to(effectiveEndpoint.toURI()).withFineLogger(LOG, isDebugLogActive);
XMLCall call =
XMLCall.to(effectiveEndpoint.toURI(), contentTypeHeader).withFineLogger(LOG, isDebugLogActive);
call.getOutcall().withConfiguredTimeout(SOAP_TIMEOUT_CONFIG_KEY);
call.withNamespaceContext(namespaceContext);
if (callEnhancer != null) {
Expand Down

0 comments on commit 0210779

Please sign in to comment.