TicketAgentClient { @SuppressWarnings("unchecked") public List<BigInteger> listFlights() { ObjectFactory factory = new ObjectFactory(); TListFlights tListFlights = factory.createTListFlights(); JAXBElement<TListFlights> request = factory.createListFlightsRequest(tListFlights); JAXBElement<TFlightsResponse> response = (JAXBElement<TFlightsResponse>) webServiceTemplate .marshalSendAndReceive(request, new WebServiceMessageCallback() { @Override public void doWithMessage(WebServiceMessage message) { try { SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader(); ObjectFactory factory = new ObjectFactory(); ListFlightsSoapHeaders listFlightsSoapHeaders = factory.createListFlightsSoapHeaders(); listFlightsSoapHeaders.setClientId("abc123"); JAXBElement<ListFlightsSoapHeaders> headers = factory.createListFlightsSoapHeaders(listFlightsSoapHeaders); JAXBContext context = JAXBContext.newInstance(ListFlightsSoapHeaders.class); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(headers, soapHeader.getResult()); } catch (Exception e) { LOGGER.error("error during marshalling of the SOAP headers", e); } } }); return response.getValue().getFlightNumber(); }  @SuppressWarnings("unchecked") List<BigInteger> listFlights();  }
@Test public void testListFlights() { Source requestPayload = new StringSource("<ns3:listFlightsRequest xmlns:ns3=\"http: + "</ns3:listFlightsRequest>"); Source responsePayload = new StringSource("<v1:listFlightsResponse xmlns:v1=\"http: + "<flightNumber>101</flightNumber>" + "</v1:listFlightsResponse>"); mockWebServiceServer .expect( soapHeader(new QName("http: .andExpect(payload(requestPayload)).andRespond(withPayload(responsePayload)); List<BigInteger> flights = ticketAgentClient.listFlights(); assertThat(flights.get(0)).isEqualTo(BigInteger.valueOf(101)); mockWebServiceServer.verify(); }