@Test public void testParseActualMessage() throws SOAPException, IOException { Builder builder = new Builder(); SOAPMessage message = Mockito.mock(SOAPMessage.class); SOAPHeader header = Mockito.mock(SOAPHeader.class); when(message.getSOAPHeader()).thenReturn(header); final String payload = "<foo><bar>MyBar</bar></foo>"; doAnswer( invocation -> { OutputStream outputStream = (OutputStream) invocation.getArguments()[0]; outputStream.write(payload.getBytes(StandardCharsets.UTF_8)); return null; }) .when(message) .writeTo(org.mockito.Matchers.any(OutputStream.class)); assertSame( "parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message)); ResponseInfo responseInfo = builder.build(); assertEquals("Payload doesn't match", payload, responseInfo.getPayload()); }
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) { builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; }
ResponseInfoXPathSet { 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) { builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } }
ResponseInfoXPathSet { 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) { builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } @Inject  ResponseInfoXPathSet(AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor); }
ResponseInfoXPathSet { 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) { builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } @Inject  ResponseInfoXPathSet(AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor); IterableXPath getRequestIdXPath(); IterableXPath getResponseTimeXPath(); IterableXPath getOperationsCountXPath(); @Override String toString(); ResponseInfo.Builder parseMessage(ResponseInfo.Builder builder, SOAPMessage soapMessage); }
ResponseInfoXPathSet { 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) { builder.withRequestId("Unable to extract the requestId due to exception: " + e); } return builder; } @Inject  ResponseInfoXPathSet(AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor); IterableXPath getRequestIdXPath(); IterableXPath getResponseTimeXPath(); IterableXPath getOperationsCountXPath(); @Override String toString(); ResponseInfo.Builder parseMessage(ResponseInfo.Builder builder, SOAPMessage soapMessage);  }