List of usage examples for javax.xml.soap SOAPHeader setPrefix
public void setPrefix(String prefix) throws DOMException;
null
if it is unspecified. From source file:org.openhab.binding.fritzboxtr064.internal.Tr064Comm.java
/** * Sets all required namespaces and prepares the SOAP message to send. * Creates skeleton + body data.//ww w.ja va 2s . c om * * @param bodyData * is attached to skeleton to form entire SOAP message * @return ready to send SOAP message */ private SOAPMessage constructTr064Msg(SOAPBodyElement bodyData) { SOAPMessage soapMsg = null; try { MessageFactory msgFac; msgFac = MessageFactory.newInstance(); soapMsg = msgFac.createMessage(); soapMsg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); soapMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8"); SOAPPart part = soapMsg.getSOAPPart(); // valid for entire SOAP msg String namespace = "s"; // create suitable fbox envelope SOAPEnvelope envelope = part.getEnvelope(); envelope.setPrefix(namespace); envelope.removeNamespaceDeclaration("SOAP-ENV"); // delete standard namespace which was already set envelope.addNamespaceDeclaration(namespace, "http://schemas.xmlsoap.org/soap/envelope/"); Name nEncoding = envelope.createName("encodingStyle", namespace, "http://schemas.xmlsoap.org/soap/encoding/"); envelope.addAttribute(nEncoding, "http://schemas.xmlsoap.org/soap/encoding/"); // create empty header SOAPHeader header = envelope.getHeader(); header.setPrefix(namespace); // create body with command based on parameter SOAPBody body = envelope.getBody(); body.setPrefix(namespace); body.addChildElement(bodyData); // bodyData already prepared. Needs only be added } catch (Exception e) { logger.error("Error creating SOAP message for fbox request with data {}", bodyData); e.printStackTrace(); } return soapMsg; }