Example usage for javax.xml.soap SOAPElement getLocalName

List of usage examples for javax.xml.soap SOAPElement getLocalName

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:com.polivoto.networking.SoapClient.java

public String start() throws SOAPException, IOException {
    String resp = "NaN";
    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    // Send SOAP Message to SOAP Server
    String url = "http://" + host
            + "/FistVotingServiceBank/services/ServAvailableVoteProcesses.ServAvailableVoteProcessesHttpSoap11Endpoint/";
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

    SOAPBody body = soapResponse.getSOAPBody();
    java.util.Iterator updates = body.getChildElements();
    // El siguiente ciclo funciona slo porque el cuerpo contiene 
    // un elemento y ste a suvez nicamente contiene un elemento.
    while (updates.hasNext()) {
        System.out.println();/*from  www  .  j  a  v  a2 s.  c o m*/
        // The listing and its ID
        SOAPElement update = (SOAPElement) updates.next();
        java.util.Iterator i = update.getChildElements();
        while (i.hasNext()) {
            SOAPElement e = (SOAPElement) i.next();
            String name = e.getLocalName();
            String value = e.getValue();
            resp = value; // Am I getting last response?
            System.out.println(name + ": " + value);
        }
    }
    soapConnection.close();
    return resp;
}

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleInboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (null == soapHeader) {
        return;//from w w  w  .ja v a  2  s .  co  m
    }
    Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements();
    while (headerIterator.hasNext()) {
        SOAPHeaderElement soapHeaderElement = headerIterator.next();
        if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) {
            continue;
        }
        if (false == "Security".equals(soapHeaderElement.getLocalName())) {
            continue;
        }
        Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements();
        while (securityElementIterator.hasNext()) {
            SOAPElement securityElement = securityElementIterator.next();
            if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) {
                continue;
            }
            if (false == "Assertion".equals(securityElement.getLocalName())) {
                continue;
            }
            LOG.debug("putting SAML token on JAX-WS context");
            context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement);
            context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION);
        }
    }
}

From source file:com.jkoolcloud.tnt4j.streams.custom.inputs.CastIronWsStream.java

/**
 * Appends SOAP request message with {@code "sessionId"} header having token received from scenario {@code "login"}
 * step and saved in streams cache.// w ww.j av  a2 s .  c  om
 *
 * @param soapRequest
 *            SOAP request message instance
 * @throws javax.xml.soap.SOAPException
 *             if there was an error adding the SOAP message header
 */
@Override
protected void addSoapHeaders(SOAPMessage soapRequest) throws SOAPException {
    SOAPFactory soapFactory = SOAPFactory.newInstance();
    SOAPElement sessionIdElem = soapFactory.createElement("sessionId", "sec", // NON-NLS
            "http://www.approuter.com/schemas/2008/1/security"); // NON-NLS

    String cachedToken = String.valueOf(StreamsCache.getValue(tokenCacheKey));
    logger().log(OpLevel.DEBUG, StreamsResources.getBundle(WsStreamConstants.RESOURCE_BUNDLE_NAME),
            "CastIronStream.adding.req.header", sessionIdElem.getLocalName(), cachedToken);
    sessionIdElem.setTextContent(cachedToken);
    soapRequest.getSOAPHeader().addChildElement(sessionIdElem);
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from  w w  w .j  a  va 2 s  .co m*/
public void testAddChildElementFromLocalNameAndPrefix() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addNamespaceDeclaration("p", "urn:test");
    SOAPElement child = element.addChildElement("child", "p");
    assertEquals("urn:test", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("child", child.getLocalName());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test// w ww .  j a  v  a2s  .c o m
public void testAddChildElementWithDeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns");
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    assertEquals(0, child.getAttributes().getLength());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test// w  w  w  .j  a v a2  s .co  m
public void testAddChildElementWithUndeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    Attr nsDecl = child.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

public Object __buildOutputData(Context context, Object convertigoResponse) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response...");

    SOAPMessage responseMessage = null;
    String sResponseMessage = "";
    String encodingCharSet = "UTF-8";
    if (context.requestedObject != null)
        encodingCharSet = context.requestedObject.getEncodingCharSet();

    if (convertigoResponse instanceof Document) {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document.");
        Document document = (Document) convertigoResponse;

        //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        MessageFactory messageFactory = MessageFactory.newInstance();
        responseMessage = messageFactory.createMessage();

        responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet);

        SOAPPart sp = responseMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();

        sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");

        String targetNamespace = context.project.getTargetNamespace();
        String prefix = getPrefix(context.projectName, targetNamespace);

        //se.addNamespaceDeclaration(prefix, targetNameSpace);
        se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
        se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");

        // Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail 
        se.getHeader().detachNode();/*from  w  w w.j av a  2 s  . c  o m*/

        // Add the method response element
        SOAPElement soapMethodResponseElement = null;
        String soapElementName = context.sequenceName != null ? context.sequenceName
                : context.connectorName + "__" + context.transactionName;
        soapElementName += "Response";

        soapMethodResponseElement = sb.addChildElement(se.createName(soapElementName, prefix, targetNamespace));

        if (XsdForm.qualified == context.project.getSchemaElementForm()) {
            soapMethodResponseElement.addAttribute(se.createName("xmlns"), targetNamespace);
        }

        // Add a 'response' root child element or not
        SOAPElement soapResponseElement;
        if (context.sequenceName != null) {
            Sequence sequence = (Sequence) context.requestedObject;
            if (sequence.isIncludeResponseElement()) {
                soapResponseElement = soapMethodResponseElement.addChildElement("response");
            } else {
                soapResponseElement = soapMethodResponseElement;
            }
        } else {
            soapResponseElement = soapMethodResponseElement.addChildElement("response");
        }

        if (soapResponseElement.getLocalName().equals("response")) {
            if (document.getDocumentElement().hasAttributes()) {
                addAttributes(responseMessage, se, context, document.getDocumentElement().getAttributes(),
                        soapResponseElement);
            }
        }

        NodeList childNodes = document.getDocumentElement().getChildNodes();
        int len = childNodes.getLength();
        org.w3c.dom.Node node;
        for (int i = 0; i < len; i++) {
            node = childNodes.item(i);
            if (node instanceof Element) {
                addElement(responseMessage, se, context, (Element) node, soapResponseElement);
            }
        }

        sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet);

        // Correct missing "xmlns" (Bug AXA POC client .NET)
        //sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\"");
    } else {
        Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document.");
        sResponseMessage = convertigoResponse.toString();
    }

    if (Engine.logBeans.isDebugEnabled()) {
        Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage);
    }

    return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage;
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

private void _fixFaultElements(SOAPEnvelope env) {
    try {//from www.j  a  v  a 2  s.com
        // If we have a SOAP 1.2 envelope, then there's nothing to do.
        if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            return;
        }

        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("No fault found.  No conversion necessary.");
            }
            return;
        } else if (body != null && body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("A fault was found.  Converting the fault child elements to SOAP 1.1 format");
            }

            SOAPFault fault = body.getFault();

            Iterator itr = fault.getChildElements();
            while (itr.hasNext()) {
                SOAPElement se = (SOAPElement) itr.next();
                if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultcode");
                    }
                    // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: detail");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultstring");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                    // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                }
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("An error occured while converting fault elements: " + e.getMessage());
        }
        throw ExceptionFactory.makeWebServiceException(e);
    }
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

private Operation determineOperation(SOAPMessage soapMessage) throws SOAPException {
    Binding binding = formatter.getBinding();

    SOAPBinding soapBinding = (SOAPBinding) WsdlUtil.getExtension(binding.getExtensibilityElements(),
            com.ibm.wsdl.extensions.soap.SOAPConstants.Q_ELEM_SOAP_BINDING);

    String style = soapBinding.getStyle();
    if (style == null) {
        // wsdlsoap:binding does not specify any style, assume 'document'
        style = SoapBindConstants.DOCUMENT_STYLE;
    }//w  ww . j  a  v a2 s  .  c o m

    PortType portType = binding.getPortType();
    SOAPElement bodyElement = SoapUtil.getElement(soapMessage.getSOAPBody());

    if (style.equals(SoapBindConstants.RPC_STYLE)) {
        String operationName = bodyElement.getLocalName();
        return portType.getOperation(operationName, null, null);
    }

    List operations = portType.getOperations();
    for (int i = 0, n = operations.size(); i < n; i++) {
        Operation operation = (Operation) operations.get(i);
        Message inputMessage = operation.getInput().getMessage();
        QName docLitElementName = WsdlUtil.getDocLitElementName(inputMessage);

        if (XmlUtil.nodeNameEquals(bodyElement, docLitElementName))
            return operation;
    }
    return null;
}