/** * Parses a context map from a given soap header. */ public Map<String, String> parse(SOAPHeader header) { final NodeList nodeList = header.getElementsByTagName( TraceeWsHandlerConstants.TRACEE_SOAP_HEADER_TAG_NAME); final Map<String, String> context = new HashMap<String, String>(); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); final NodeList childNodeList = node.getChildNodes(); for (int j = 0; j < childNodeList.getLength(); j++) { final Node childNode = childNodeList.item(j); final String attributeName = childNode.getNodeName(); final String value = childNode.getTextContent(); if (attributeName != null && !attributeName.isEmpty() && !"#text".equals(attributeName)) { context.put(attributeName, value); } } } return context; }
@Override public void handleMessage(SoapMessage message) throws Fault { SOAPMessage sm = message.getContent(SOAPMessage.class); try { SOAPHeader sh = sm.getSOAPHeader(); /* Note in real use validity checking should be done (really two terms present? namespaces? etc.) */ NodeList termNodes = sh.getElementsByTagName("term"); message.put("termOne", termNodes.item(0).getTextContent()); message.put("termTwo", termNodes.item(1).getTextContent()); /* JAX-WS Handler "setScope()" (HANDLER/APPLICATION) not available with interceptors, APPLICATION is standard meaning both properties readable by service bean */ } catch (SOAPException e) { throw new Fault(e); } } }
@Override public boolean handleMessage(SOAPMessageContext mc) { HandlerUtils.printMessageContext("Service SOAPHandler", mc); if (Boolean.FALSE.equals(mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) { SOAPMessage sm = mc.getMessage(); try { SOAPHeader sh = sm.getSOAPHeader(); // Note in real use validity checking should be done // (really two terms present? namespaces? etc.) NodeList termNodes = sh.getElementsByTagName("term"); mc.put("termOne", termNodes.item(0).getTextContent()); mc.put("termTwo", termNodes.item(1).getTextContent()); // default scope is HANDLER (i.e., not readable by SEI // implementation) mc.setScope("termTwo", MessageContext.Scope.APPLICATION); } catch (SOAPException e) { throw new ProtocolException(e); } } return true; } }