public ResponseInfo.Builder parseMessage(ResponseInfo.Builder builder, SOAPMessage soapMessage) { Preconditions.checkNotNull(builder, "Null builder"); if (soapMessage == null) { return builder; } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { soapMessage.writeTo(outputStream); builder.withPayload(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (SOAPException | IOException e) { builder.withPayload("Unable to read response due to exception: " + e); } try { SOAPHeader soapHeader = soapMessage.getSOAPHeader(); String responseTimeString = nodeExtractor.extractNodeValue(soapHeader, responseTimeXPath); String operationsString = nodeExtractor.extractNodeValue(soapHeader, operationsCountXPath); builder .withRequestId(nodeExtractor.extractNodeValue(soapHeader, requestIdXPath)) .withResponseTimeMillis(Longs.tryParse(Strings.nullToEmpty(responseTimeString))) .withOperationsCount(Longs.tryParse(Strings.nullToEmpty(operationsString))); } catch (SOAPException e) { // Since requestId is arguably the most important value extracted above, put the exception // in the requestId field. Adding the exception to every field of the builder would be // redundant. builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } }
public ResponseInfo.Builder parseMessage(ResponseInfo.Builder builder, SOAPMessage soapMessage) { Preconditions.checkNotNull(builder, "Null builder"); if (soapMessage == null) { return builder; } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { soapMessage.writeTo(outputStream); builder.withPayload(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (SOAPException | IOException e) { builder.withPayload("Unable to read response due to exception: " + e); } try { SOAPHeader soapHeader = soapMessage.getSOAPHeader(); String responseTimeString = nodeExtractor.extractNodeValue(soapHeader, responseTimeXPath); String operationsString = nodeExtractor.extractNodeValue(soapHeader, operationsCountXPath); builder .withRequestId(nodeExtractor.extractNodeValue(soapHeader, requestIdXPath)) .withResponseTimeMillis(Longs.tryParse(Strings.nullToEmpty(responseTimeString))) .withOperationsCount(Longs.tryParse(Strings.nullToEmpty(operationsString))); } catch (SOAPException e) { // Since requestId is arguably the most important value extracted above, put the exception // in the requestId field. Adding the exception to every field of the builder would be // redundant. builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } }
public RequestInfo.Builder parseMessage(RequestInfo.Builder builder, SOAPMessage soapMessage) { Preconditions.checkNotNull(builder, "Null builder"); Transformer transformer = transformerSupplier.get(); if (soapMessage == null || soapMessage.getSOAPPart() == null || transformer == null) { return builder; } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { // Some SOAP frameworks don't include SOAP headers when calling SOAPMessage.writeTo. // Use an XML transformer to write the XML content instead. transformer.transform(soapMessage.getSOAPPart().getContent(), new StreamResult(outputStream)); builder.withPayload(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (TransformerException | SOAPException | IOException e) { builder.withPayload("Unable to read request content due to exception: " + e); libLogger.warn("Unable to read request content due to exception.", e); } try { SOAPHeader soapHeader = soapMessage.getSOAPHeader(); builder.withContext(contextName, nodeExtractor.extractNodeValue(soapHeader, contextXPath)); } catch (SOAPException e) { builder.withContext( contextName, "Unable to extract " + contextName + " from request due to exception: " + e); } return builder; } }
public RequestInfo.Builder parseMessage(RequestInfo.Builder builder, SOAPMessage soapMessage) { Preconditions.checkNotNull(builder, "Null builder"); Transformer transformer = transformerSupplier.get(); if (soapMessage == null || soapMessage.getSOAPPart() == null || transformer == null) { return builder; } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { // Some SOAP frameworks don't include SOAP headers when calling SOAPMessage.writeTo. // Use an XML transformer to write the XML content instead. transformer.transform(soapMessage.getSOAPPart().getContent(), new StreamResult(outputStream)); builder.withPayload(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (TransformerException | SOAPException | IOException e) { builder.withPayload("Unable to read request content due to exception: " + e); libLogger.warn("Unable to read request content due to exception.", e); } try { SOAPHeader soapHeader = soapMessage.getSOAPHeader(); builder.withContext(contextName, nodeExtractor.extractNodeValue(soapHeader, contextXPath)); } catch (SOAPException e) { builder.withContext( contextName, "Unable to extract " + contextName + " from request due to exception: " + e); } return builder; } }