Search in sources :

Example 6 with SOAPPart

use of javax.xml.soap.SOAPPart in project ddf by codice.

the class SoapRequestDecoder method decodeRelayState.

public String decodeRelayState(String samlRequest) {
    String relayState = null;
    try {
        SOAPPart soapMessage = SamlProtocol.parseSoapMessage(samlRequest);
        SOAPEnvelope envelope = soapMessage.getEnvelope();
        SOAPHeader header = envelope.getHeader();
        Iterator iterator = header.examineAllHeaderElements();
        while (iterator.hasNext()) {
            SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) iterator.next();
            if ("RelayState".equals(soapHeaderElement.getLocalName())) {
                relayState = soapHeaderElement.getValue();
                break;
            }
        }
    } catch (XMLStreamException e) {
        throw new IllegalArgumentException("Unable to convert parse SOAP request.");
    } catch (SOAPException e) {
        throw new IllegalArgumentException("Unable to get SOAP envelope.");
    }
    return relayState;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 7 with SOAPPart

use of javax.xml.soap.SOAPPart in project nhin-d by DirectProject.

the class RepositorySOAPHandler method handleMessage.

/**
     * This method handles the incoming and outgoing SOAP-Message. It's an
     * excellent point to manipulate the SOAP.
     * 
     * @param SOAPMessageContext
     *            The SOAPMessageContext object.
     * 
     * @return true if successful handling, false otherwise.
     */
@Override
public boolean handleMessage(SOAPMessageContext context) {
    //Inquire incoming or outgoing message.
    boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    try {
        if (outbound) {
            getHeaderData();
            SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
            // dumpSOAPMessage(msg);
            SOAPPart sp = msg.getSOAPPart();
            // edit Envelope
            SOAPEnvelope env = sp.getEnvelope();
            SOAPHeader sh = env.addHeader();
            @SuppressWarnings("unused") SOAPBody sb = env.getBody();
            if (action != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "Action");
                SOAPHeaderElement saction = sh.addHeaderElement(qname);
                boolean must = true;
                saction.setMustUnderstand(must);
                saction.setValue(action);
            }
            if (relatesTo != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "RelatesTo");
                SOAPHeaderElement relates = sh.addHeaderElement(qname);
                relates.setValue(relatesTo);
            }
            if (from != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "From");
                QName child = new QName("http://www.w3.org/2005/08/addressing", "Address");
                SOAPHeaderElement efrom = sh.addHeaderElement(qname);
                SOAPElement address = efrom.addChildElement(child);
                address.setValue(from);
            }
            if (messageId != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "MessageID");
                SOAPHeaderElement message = sh.addHeaderElement(qname);
                message.setValue(messageId);
            }
            if (to != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "To");
                SOAPHeaderElement sto = sh.addHeaderElement(qname);
                sto.setValue(to);
            }
        } else {
        //should not be any inbound
        }
    } catch (Exception e) {
        LOGGER.error("Error handling SOAP message", e);
        return false;
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SOAPBody(javax.xml.soap.SOAPBody) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 8 with SOAPPart

use of javax.xml.soap.SOAPPart in project Payara by payara.

the class BaseAuthConfig method getName.

private static Name getName(SOAPMessage message) {
    Name rvalue = null;
    SOAPPart soap = message.getSOAPPart();
    if (soap != null) {
        try {
            SOAPEnvelope envelope = soap.getEnvelope();
            if (envelope != null) {
                SOAPBody body = envelope.getBody();
                if (body != null) {
                    Iterator it = body.getChildElements();
                    while (it.hasNext()) {
                        Object o = it.next();
                        if (o instanceof SOAPElement) {
                            rvalue = ((SOAPElement) o).getElementName();
                            break;
                        }
                    }
                }
            }
        } catch (SOAPException se) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
            }
        }
    }
    return rvalue;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Name(javax.xml.soap.Name) QName(javax.xml.namespace.QName)

Example 9 with SOAPPart

use of javax.xml.soap.SOAPPart in project stanbol by apache.

the class LemmatizerClientHTTP method lemmatizeContents.

public String lemmatizeContents(String text, String lang) throws SOAPException, IOException {
    // create the POST request
    HttpURLConnection con = Utils.createPostRequest(serviceEP, requestHeaders, conTimeout);
    // write content
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), UTF8));
    // write the SOAP envelope, header and start the body
    writer.write(SOAP_REQUEST_PREFIX);
    writer.write("<mor:inputText lang=\"");
    writer.write(lang);
    writer.write("\" text=\"");
    StringEscapeUtils.escapeXml(writer, text);
    writer.write("\"/>");
    writer.write(SOAP_REQUEST_SUFFIX);
    writer.close();
    // Call the service
    long start = System.currentTimeMillis();
    InputStream stream = con.getInputStream();
    log.debug("Request to {} took {}ms", serviceEP, System.currentTimeMillis() - start);
    // Create SoapMessage
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage message = msgFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    // Load the SOAP text into a stream source
    StreamSource source = new StreamSource(stream);
    // Set contents of message
    soapPart.setContent(source);
    SOAPBody soapBody = message.getSOAPBody();
    StringBuilder buff = new StringBuilder();
    NodeList nlist = soapBody.getElementsByTagNameNS("*", "LexicalEntry");
    for (int i = 0; i < nlist.getLength(); i++) {
        Element result = (Element) nlist.item(i);
        NodeList lemmasList = result.getElementsByTagNameNS("*", "Lemma");
        if (lemmasList != null && lemmasList.getLength() > 0) {
            HashSet<String> lemmas = new HashSet<String>();
            for (int j = 0; j < lemmasList.getLength(); j++) {
                lemmas.add(lemmasList.item(j).getTextContent());
            }
            for (String lemma : lemmas) {
                buff.append(lemma).append(' ');
            }
        } else {
            buff.append(result.getAttributeNS("*", "WordForm")).append(' ');
        }
    }
    return buff.toString().trim();
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) SOAPMessage(javax.xml.soap.SOAPMessage) BufferedWriter(java.io.BufferedWriter) SOAPBody(javax.xml.soap.SOAPBody) HttpURLConnection(java.net.HttpURLConnection) SOAPPart(javax.xml.soap.SOAPPart) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 10 with SOAPPart

use of javax.xml.soap.SOAPPart in project stanbol by apache.

the class SentimentAnalysisServiceClientHttp method extractSentimentExpressions.

public List<SentimentExpression> extractSentimentExpressions(String text, String lang) throws SOAPException, IOException {
    if (text == null || text.isEmpty()) {
        // no text -> no extractions
        return Collections.emptyList();
    }
    // create the POST request
    HttpURLConnection con = Utils.createPostRequest(serviceEP, requestHeaders, connectionTimeout);
    // write content
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), UTF8));
    writer.write(SOAP_PREFIX);
    writer.write("<sen:analyzeText><arg0><![CDATA[" + text + "]]></arg0><arg1>" + lang + "</arg1></sen:analyzeText>");
    writer.write(SOAP_SUFFIX);
    writer.close();
    // Call the service
    long start = System.currentTimeMillis();
    InputStream stream = con.getInputStream();
    log.debug("Request to {} took {}ms", serviceEP, System.currentTimeMillis() - start);
    // Create SoapMessage and parse the results
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage message = msgFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    // Load the SOAP text into a stream source
    StreamSource source = new StreamSource(new InputStreamReader(stream, UTF8));
    // Set contents of message
    soapPart.setContent(source);
    SOAPBody soapBody = message.getSOAPBody();
    // extract the results
    List<SentimentExpression> sentExpressions = new Vector<SentimentExpression>();
    NodeList nlist = soapBody.getElementsByTagName("relation");
    String snippetStr = null;
    for (int i = 0; i < nlist.getLength(); i++) {
        Element relation = (Element) nlist.item(i);
        String sentimentType = relation.getAttribute("type");
        int startSnippet = Integer.parseInt(relation.getAttribute("start"));
        int endSnippet = Integer.parseInt(relation.getAttribute("end"));
        NodeList snippet = relation.getElementsByTagName("snippet");
        if (snippet.getLength() > 0) {
            snippetStr = snippet.item(0).getTextContent();
        }
        List<String> arguments = new Vector<String>();
        NodeList argsList = relation.getElementsByTagName("arguments");
        for (int x = 0; x < argsList.getLength(); x++) {
            NodeList lemmas = ((Element) argsList.item(x)).getElementsByTagName("lemma");
            for (int y = 0; y < lemmas.getLength(); y++) {
                Element lemma = (Element) lemmas.item(y);
                String lemmaStr = lemma.getAttribute("lemma");
                if (lemmaStr != null && lemmaStr.length() > 0)
                    arguments.add(lemmaStr);
            }
        }
        SentimentExpression expr = new SentimentExpression(sentimentType, snippetStr, startSnippet, endSnippet, arguments);
        sentExpressions.add(expr);
    }
    return sentExpressions;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) SOAPMessage(javax.xml.soap.SOAPMessage) BufferedWriter(java.io.BufferedWriter) SOAPBody(javax.xml.soap.SOAPBody) HttpURLConnection(java.net.HttpURLConnection) SOAPPart(javax.xml.soap.SOAPPart) OutputStreamWriter(java.io.OutputStreamWriter) Vector(java.util.Vector)

Aggregations

SOAPPart (javax.xml.soap.SOAPPart)45 SOAPMessage (javax.xml.soap.SOAPMessage)30 SOAPBody (javax.xml.soap.SOAPBody)28 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)26 SOAPException (javax.xml.soap.SOAPException)26 MessageFactory (javax.xml.soap.MessageFactory)17 SOAPElement (javax.xml.soap.SOAPElement)14 Iterator (java.util.Iterator)13 Element (org.w3c.dom.Element)13 StreamSource (javax.xml.transform.stream.StreamSource)12 QName (javax.xml.namespace.QName)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 Name (javax.xml.soap.Name)10 NodeList (org.w3c.dom.NodeList)9 BufferedWriter (java.io.BufferedWriter)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 OutputStreamWriter (java.io.OutputStreamWriter)7 HttpURLConnection (java.net.HttpURLConnection)7 SOAPHeader (javax.xml.soap.SOAPHeader)6