Example usage for javax.xml.soap SOAPBodyElement addNamespaceDeclaration

List of usage examples for javax.xml.soap SOAPBodyElement addNamespaceDeclaration

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBodyElement addNamespaceDeclaration.

Prototype

public SOAPElement addNamespaceDeclaration(String prefix, String uri) throws SOAPException;

Source Link

Document

Adds a namespace declaration with the specified prefix and URI to this SOAPElement object.

Usage

From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java

private byte[] createRequestXml(String action, ImmutablePair<String, String>... params) {
    try {//w  ww.  j  a va2s.  co m
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapMessage = factory.createMessage();

        SOAPBodyElement actionElement = soapMessage.getSOAPBody().addBodyElement(new QName(null, action, "m"));
        actionElement.addNamespaceDeclaration("m", serviceType);

        for (Pair<String, String> param : params) {
            SOAPElement paramElement = actionElement.addChildElement(QName.valueOf(param.getKey()));
            paramElement.setValue(param.getValue());
        }

        soapMessage.getSOAPPart().setXmlStandalone(true);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(baos));

        return baos.toByteArray();
    } catch (IllegalArgumentException | SOAPException | TransformerException | DOMException e) {
        throw new IllegalStateException(e); // should never happen
    }
}

From source file:org.apache.axis.message.SOAPBody.java

public SOAPElement addChildElement(String localName, String prefix, String uri) throws SOAPException {
    SOAPBodyElement child = new SOAPBodyElement(uri, localName);
    child.setPrefix(prefix);/*from  w  w w .ja va  2s. c o  m*/
    child.addNamespaceDeclaration(prefix, uri);
    addChildElement(child);
    return child;
}

From source file:org.apache.ws.scout.transport.SaajTransport.java

private SOAPMessage createSOAPMessage(Element elem) throws Exception {
    String prefix = "";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPFactory factory = SOAPFactory.newInstance();

    SOAPMessage message = msgFactory.createMessage();
    message.getSOAPHeader().detachNode();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPBody soapBody = soapPart.getEnvelope().getBody();
    //Create the outer body element
    Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE);
    SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
    bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE);
    appendAttributes(bodyElement, elem.getAttributes(), factory);
    appendElements(bodyElement, elem.getChildNodes(), factory);
    return message;
}

From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java

private SOAPMessage createSOAPMessage(Element elem) throws Exception {
    String prefix = "uddi";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPFactory factory = SOAPFactory.newInstance();

    SOAPMessage message = msgFactory.createMessage();
    message.getSOAPHeader().detachNode();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPBody soapBody = soapPart.getEnvelope().getBody();
    //Create the outer body element
    String uddins = IRegistry.UDDI_V2_NAMESPACE;
    Name bodyName = factory.createName(elem.getNodeName(), prefix, uddins);
    SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
    bodyElement.addNamespaceDeclaration(prefix, uddins);
    appendAttributes(bodyElement, elem.getAttributes(), factory);
    appendElements(bodyElement, elem.getChildNodes(), factory);
    return message;
}