List of usage examples for javax.xml.soap SOAPEnvelope setPrefix
public void setPrefix(String prefix) throws DOMException;
null
if it is unspecified. From source file:com.konakart.bl.modules.ordertotal.thomson.HeaderSecrityHandler.java
public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outboundProperty.booleanValue()) { SOAPMessage message = smc.getMessage(); if (log.isInfoEnabled()) { log.info("Adding Credentials : " + getUName() + "/" + getPWord()); }//from w ww .j a va 2s. com try { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); envelope.setPrefix("soapenv"); envelope.getBody().setPrefix("soapenv"); SOAPHeader header = envelope.addHeader(); SOAPElement security = header.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); SOAPElement usernameToken = security.addChildElement("UsernameToken", "wsse"); usernameToken.addAttribute(new QName("wsu:Id"), "UsernameToken-1"); usernameToken.setAttribute("wsu:Id", "UsernameToken-1"); usernameToken.addAttribute(new QName("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); SOAPElement username = usernameToken.addChildElement("Username", "wsse"); username.addTextNode(getUName()); SOAPElement password = usernameToken.addChildElement("Password", "wsse"); password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); password.addTextNode(getPWord()); SOAPElement encodingType = usernameToken.addChildElement("Nonce", "wsse"); encodingType.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); encodingType.addTextNode("Encoding"); } catch (Exception e) { e.printStackTrace(); } } return outboundProperty; }
From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java
private Document createSOAPFaultDocument(String faultString) throws SOAPException { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPPart sp = message.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); se.setPrefix(SOAP_PREFIX); se.getHeader().detachNode();//from w w w. ja v a 2 s .c o m se.addHeader(); se.getBody().detachNode(); SOAPBody body = se.addBody(); SOAPFault fault = body.addFault(); Name faultCode = se.createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE); fault.setFaultCode(faultCode); fault.setFaultString(faultString); return se.getOwnerDocument(); }
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.//from w ww. j av a 2 s . 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; }