Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

UI Text Box
typenote

At the moment, hooks do not exist for processing the SOAP response. These hooks are used for processing the request only.

Step-by-step guide

Create a class that implements com.aquima.interactions.communication.ISoapMessageHandler

Code Block
languagejava
import com.aquima.interactions.communication.ISoapMessageContext;
import com.aquima.interactions.communication.ISoapMessageHandler;

public class WSSTimestampSoapHandler implements ISoapMessageHandler {
	@Override
	public void handle(ISoapMessageContext context) {}
}
UI Text Box
typenote

Three demo ISoapMessageHandler implementations are attached to this page. The code is provided for demonstration purposes only and should not be used in a production environment.

Annotate the class with com.aquima.web.config.annotation.AquimaSoapMessageHandler

Make sure you provide a unique name to the handler:

...

UI Text Box
typenote

The AquimaSoapMessageHandler annotation makes the class a Spring bean. Make sure the Spring configuration scans the package the handler resides in for component annotations (using context:component-scan for example).

Implement the handle(ISoapMessageContext) method

The following code is adapted from com.aquima.web.communication.WSSTimestampSoapHandler and demonstrates adding the WS-Security Timestamp header:

Code Block
languagejava
@AquimaSoapMessageHandler(value = "WSSTimestamp")
public class WSSTimestampSoapHandler implements ISoapMessageHandler {

	final String WSSE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
	final String WSU = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
	final String SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
	final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

	@Override
	public void handle(ISoapMessageContext context) {
		Calendar calendar = Calendar.getInstance();
 
        // Add custom namespaces
		context.setNamespace("wsu", WSU);
		context.setNamespace("wsse", WSSE);
 
        // Add a new SOAP header
		IXmlElementContext security = context.addHeader(new QualifiedName(WSSE, "Security"));
		security.setAttribute(new QualifiedName(SOAPENV, "mustUnderstand"), "1");
 
        // Add a child to the Security header
		IXmlElementContext timestamp = security.addElement(new QualifiedName(WSU, "Timestamp"));
		timestamp.setAttribute(new QualifiedName(WSU, "Id"), "TS-" + GUID.generate());
		IXmlElementContext created = timestamp.addElement(new QualifiedName(WSU, "Created"));
		created.setValue(dateFormat.format(calendar.getTime()), false);
		IXmlElementContext expires = timestamp.addElement(new QualifiedName(WSU, "Expires"));
		calendar.add(Calendar.MINUTE, 5);
		expires.setValue(dateFormat.format(calendar.getTime()), false);
	}
}


Specify the SoapServiceCall objects that should use this handler by modifying aquima.properties

Code Block
blueriq.soap-service-calls.<service_call>.handlers=<comma_separated_list_of_handler_names>

...

Note
titleBefore Blueriq 12.8

Before Blueriq 12.8, the property was called soap_service_calls.<service_call>.handlers.

Test the result

Capturing the SOAP request or setting the log level to debug will show the request having a new header. It should look something like:

Code Block
languagexml
<?xml version="1.0"?>
<soapenv:Envelope xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<soapenv:Header>
		<wsse:Security soapenv:mustUnderstand="1">
			<wsu:Timestamp wsu:Id="TS-930e7809-2cde-415b-ad5c-0af0b9127083">
				<wsu:Created>2015-04-02T09:46:58.824Z</wsu:Created>
				<wsu:Expires>2015-04-02T09:51:58.824Z</wsu:Expires>
			</wsu:Timestamp>
		</wsse:Security>
	</soapenv:Header>
	<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	   ...
	</soapenv:Body>
</soapenv:Envelope>

.NET registration

In the .NET runtime, the usual registration mechanism is used to register a SOAP message handler:

...