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; } }