List of usage examples for javax.xml.soap SOAPBody getChildNodes
public NodeList getChildNodes();
NodeList
that contains all children of this node. From source file:ee.ria.xroad.proxy.util.MetaserviceTestUtil.java
/** Try to extract a single element of type T from the Soap Body, of class clazz. * @param body the {@link SOAPBody}/* w ww. jav a 2 s . c o m*/ * @param clazz the class of type T * @param unmarshallerSupplier a {@link Supplier} for the unmarshaller. Needed if this util class does not * know of the class you want to unmarshall * @param <T> the {@link JAXBElement} value to extract, like {@link ee.ria.xroad.common.metadata.MethodListType} * @return the resulting element of type T * @throws JAXBException if unexpected errors occur during unmarshalling */ public static <T> T verifyAndGetSingleBodyElementOfType(SOAPBody body, Class<T> clazz, Supplier<Unmarshaller> unmarshallerSupplier) throws JAXBException { NodeList list = body.getChildNodes(); List<Element> elements = new ArrayList<>(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { elements.add((Element) node); } } assertThat("Was expecting a single element", elements.size(), is(1)); JAXBElement<T> element = unmarshallerSupplier.get().unmarshal(elements.get(0), clazz); return element.getValue(); }
From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java
@SuppressWarnings("unchecked") @Override// w w w .ja v a2 s .c o m public boolean handleMessage(SOAPMessageContext context) { try { Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); logger.debug("LicenseHandler:{}", out); if (!out) { SOAPMessage message = context.getMessage(); logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message)); SOAPEnvelope enve = message.getSOAPPart().getEnvelope(); SOAPHeader header = enve.getHeader(); SOAPBody body = enve.getBody(); Node bn = body.getChildNodes().item(0); String partname = bn.getLocalName(); if ("getUser".equals(partname)) { if (header == null) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements(); if (!iterator.hasNext()) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } while (iterator.hasNext()) { SOAPHeaderElement ele = iterator.next(); System.out.println(ele.getTextContent()); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
From source file:au.com.ors.rest.controller.AutoCheckController.java
@RequestMapping(method = RequestMethod.POST) @ResponseBody/*from w ww . j a va 2 s . c om*/ public ResponseEntity<AutoCheckRes> autoCheck(@RequestBody AutoCheckReq req) throws Exception { AutoCheckRes autoCheckRes = new AutoCheckRes(null, null); SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); String url = "http://localhost:6060/ode/processes/AutoCheck"; SOAPMessage soapResponse = soapConnection .call(createSOAPRequest(req.getDriverLicenseNumber(), req.getFullName(), req.getPostCode()), url); soapConnection.close(); SOAPBody body = soapResponse.getSOAPBody(); Node rootnode = body.getChildNodes().item(0); NodeList nodeList = rootnode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); ++i) { Node currentNode = nodeList.item(i); if (currentNode.getNodeName().equals("ns:pdvResult")) { autoCheckRes.setPdvResult(currentNode.getTextContent()); } else if (currentNode.getNodeName().equals("ns:crvResult")) { autoCheckRes.setCrvResult(currentNode.getTextContent()); } } return new ResponseEntity<AutoCheckRes>(autoCheckRes, HttpStatus.OK); }