Search in sources :

Example 41 with SOAPException

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

the class CeliAnalyzedTextLemmatizerEngine method computeEnhancements.

@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
    AnalysedText at = getAnalysedText(this, ci, true);
    String language = getLanguage(this, ci, true);
    isLangaugeConfigured(this, languageConfig, language, true);
    List<LexicalEntry> terms;
    try {
        terms = this.client.performMorfologicalAnalysis(at.getSpan(), language);
    } catch (IOException e) {
        throw new EngineException("Error while calling the CELI Lemmatizer" + " service (configured URL: " + serviceURL + ")!", e);
    } catch (SOAPException e) {
        throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI lemmatizer service!", e);
    }
    Map<LexicalCategory, Double> tokenLexCats = new EnumMap<LexicalCategory, Double>(LexicalCategory.class);
    for (LexicalEntry term : terms) {
        if (term.getTermReadings().isEmpty()) {
            //ignore terms without readings
            continue;
        }
        //Add the LexicalEntry as Token to the Text. NOTE that if a
        //Token with the same start/end positions already exist this
        //Method returns the existing instance
        Token token = at.addToken(term.getFrom(), term.getTo());
        //Now try to get POS annotations for the Token
        for (Value<PosTag> posAnno : token.getAnnotations(NlpAnnotations.POS_ANNOTATION)) {
            if (posAnno.value().isMapped()) {
                for (LexicalCategory cat : posAnno.value().getCategories()) {
                    if (!tokenLexCats.containsKey(cat)) {
                        //do not override with lover prob
                        tokenLexCats.put(cat, posAnno.probability());
                    }
                }
            }
        }
        for (Reading reading : term.getTermReadings()) {
            MorphoFeatures mf = CeliMorphoFeatures.parseFrom(reading, language);
            //add the readings (MorphoFeatures)
            if (mf != null) {
                //use the POS tags of the morpho analysis and compare it
                //with existing POS tags.
                double posProbability = -1;
                Set<LexicalCategory> mfCats = EnumSet.noneOf(LexicalCategory.class);
                for (PosTag mfPos : mf.getPosList()) {
                    mfCats.addAll(mfPos.getCategories());
                }
                for (LexicalCategory mfCat : mfCats) {
                    Double prob = tokenLexCats.get(mfCat);
                    if (prob != null && posProbability < prob) {
                        posProbability = prob;
                    }
                }
                //add the morpho features with the posProbabiliy
                Value<MorphoFeatures> value = Value.value(mf, posProbability < 0 ? Value.UNKNOWN_PROBABILITY : posProbability);
                token.addAnnotation(NlpAnnotations.MORPHO_ANNOTATION, value);
            }
        }
    }
}
Also used : EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) Token(org.apache.stanbol.enhancer.nlp.model.Token) IOException(java.io.IOException) LexicalCategory(org.apache.stanbol.enhancer.nlp.pos.LexicalCategory) NlpEngineHelper.getAnalysedText(org.apache.stanbol.enhancer.nlp.utils.NlpEngineHelper.getAnalysedText) AnalysedText(org.apache.stanbol.enhancer.nlp.model.AnalysedText) PosTag(org.apache.stanbol.enhancer.nlp.pos.PosTag) SOAPException(javax.xml.soap.SOAPException) MorphoFeatures(org.apache.stanbol.enhancer.nlp.morpho.MorphoFeatures) CeliMorphoFeatures(org.apache.stanbol.enhancer.engines.celi.CeliMorphoFeatures) EnumMap(java.util.EnumMap)

Example 42 with SOAPException

use of javax.xml.soap.SOAPException in project tomee by apache.

the class SaajMetaFactoryImpl method callFactoryMethod.

private Object callFactoryMethod(String methodName, String arg) throws SOAPException {
    SAAJMetaFactory factory = (SAAJMetaFactory) SaajFactoryFinder.find("javax.xml.soap.MetaFactory");
    try {
        Method method = factory.getClass().getDeclaredMethod(methodName, new Class[] { String.class });
        boolean accessibility = method.isAccessible();
        try {
            method.setAccessible(true);
            Object result = method.invoke(factory, new Object[] { arg });
            return result;
        } catch (InvocationTargetException e) {
            if (e.getTargetException() instanceof SOAPException) {
                throw (SOAPException) e.getTargetException();
            } else {
                throw new SOAPException("Error calling factory method: " + methodName, e);
            }
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new SOAPException("Error calling factory method: " + methodName, e);
        } finally {
            method.setAccessible(accessibility);
        }
    } catch (NoSuchMethodException e) {
        throw new SOAPException("Factory method not found: " + methodName, e);
    }
}
Also used : SAAJMetaFactory(javax.xml.soap.SAAJMetaFactory) SOAPException(javax.xml.soap.SOAPException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 43 with SOAPException

use of javax.xml.soap.SOAPException in project cxf by apache.

the class SAAJInInterceptor method handleMessage.

@SuppressWarnings("unchecked")
public void handleMessage(SoapMessage message) throws Fault {
    if (isGET(message)) {
        return;
    }
    Boolean bodySet = (Boolean) message.get(BODY_FILLED_IN);
    if (Boolean.TRUE.equals(bodySet)) {
        return;
    }
    message.put(BODY_FILLED_IN, Boolean.TRUE);
    try {
        SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
        if (soapMessage == null) {
            MessageFactory factory = preInterceptor.getFactory(message);
            soapMessage = factory.createMessage();
            message.setContent(SOAPMessage.class, soapMessage);
        }
        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
        if (xmlReader == null) {
            return;
        }
        final SOAPPart part = soapMessage.getSOAPPart();
        Document node = (Document) message.getContent(Node.class);
        if (node != part && node != null) {
            StaxUtils.copy(node, new SAAJStreamWriter(part));
        } else {
            SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
            if (node == null) {
                adjustPrefixes(env, (String) message.get(ReadHeadersInterceptor.ENVELOPE_PREFIX), (String) message.get(ReadHeadersInterceptor.BODY_PREFIX));
            }
            List<XMLEvent> events = (List<XMLEvent>) message.get(ReadHeadersInterceptor.ENVELOPE_EVENTS);
            applyEvents(events, env);
            SOAPBody body = soapMessage.getSOAPBody();
            events = (List<XMLEvent>) message.get(ReadHeadersInterceptor.BODY_EVENTS);
            applyEvents(events, body);
        }
        message.setContent(Node.class, soapMessage.getSOAPPart());
        Collection<Attachment> atts = message.getAttachments();
        if (atts != null) {
            for (Attachment a : atts) {
                if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) {
                    try {
                        ((AttachmentDataSource) a.getDataHandler().getDataSource()).cache(message);
                    } catch (IOException e) {
                        throw new Fault(e);
                    }
                }
                AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
                Iterator<String> i = a.getHeaderNames();
                while (i != null && i.hasNext()) {
                    String h = i.next();
                    String val = a.getHeader(h);
                    ap.addMimeHeader(h, val);
                }
                if (StringUtils.isEmpty(ap.getContentId())) {
                    ap.setContentId(a.getId());
                }
                soapMessage.addAttachmentPart(ap);
            }
        }
        // replace header element if necessary
        if (message.hasHeaders()) {
            replaceHeaders(soapMessage, message);
        }
        if (soapMessage.getSOAPPart().getEnvelope().getHeader() == null) {
            soapMessage.getSOAPPart().getEnvelope().addHeader();
        }
        // If we have an xmlReader that already is counting the attributes and such
        // then we don't want to rely on the system level defaults in StaxUtils.copy
        // CXF-6173
        boolean secureReader = StaxUtils.isSecureReader(xmlReader, message);
        StaxUtils.copy(xmlReader, new SAAJStreamWriter(soapMessage.getSOAPPart(), soapMessage.getSOAPPart().getEnvelope().getBody()), true, !secureReader);
        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
        xmlReader = StaxUtils.createXMLStreamReader(bodySource);
        xmlReader.nextTag();
        // move past body tag
        xmlReader.nextTag();
        message.setContent(XMLStreamReader.class, xmlReader);
    } catch (SOAPException soape) {
        throw new SoapFault(new org.apache.cxf.common.i18n.Message("SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape, message.getVersion().getSender());
    } catch (XMLStreamException e) {
        throw new SoapFault(new org.apache.cxf.common.i18n.Message("SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e, message.getVersion().getSender());
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamReader(javax.xml.stream.XMLStreamReader) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) Node(org.w3c.dom.Node) AttachmentDataSource(org.apache.cxf.attachment.AttachmentDataSource) Attachment(org.apache.cxf.message.Attachment) SoapFault(org.apache.cxf.binding.soap.SoapFault) Fault(org.apache.cxf.interceptor.Fault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) List(java.util.List) ArrayList(java.util.ArrayList) MessageFactory(javax.xml.soap.MessageFactory) AttachmentPart(javax.xml.soap.AttachmentPart) IOException(java.io.IOException) SOAPBody(javax.xml.soap.SOAPBody) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 44 with SOAPException

use of javax.xml.soap.SOAPException in project cxf by apache.

the class SAAJStreamWriter method createElementNS.

@Override
protected Element createElementNS(String ns, String pfx, String local) {
    Element cur = getCurrentNode();
    if (cur instanceof SOAPBody) {
        try {
            if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
                Element el = ((SOAPBody) cur).addBodyElement(new QName(local));
                cur.removeChild(el);
                return el;
            }
            Element el = ((SOAPBody) cur).addBodyElement(new QName(ns, local, pfx == null ? "" : pfx));
            cur.removeChild(el);
            return el;
        } catch (SOAPException e) {
        // ignore
        }
    } else if (cur instanceof SOAPHeader) {
        try {
            Element el = ((SOAPHeader) cur).addHeaderElement(new QName(ns, local, pfx == null ? "" : pfx));
            cur.removeChild(el);
            return el;
        } catch (SOAPException e) {
        // ignore
        }
    } else if (cur instanceof SOAPElement) {
        try {
            Element el = null;
            if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
                el = ((SOAPElement) cur).addChildElement(local, "", "");
            } else {
                el = ((SOAPElement) cur).addChildElement(local, pfx == null ? "" : pfx, ns);
                adjustPrefix(el, pfx);
            }
            cur.removeChild(el);
            return el;
        } catch (SOAPException e) {
        // ignore
        }
    }
    return super.createElementNS(ns, pfx, local);
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 45 with SOAPException

use of javax.xml.soap.SOAPException in project cxf by apache.

the class HandlerChainInvokerTest method testHandleMessageThrowsProtocolExceptionOutbound.

@Test
public void testHandleMessageThrowsProtocolExceptionOutbound() {
    message = new SoapMessage(message);
    lmc = new LogicalMessageContextImpl(message);
    pmc = new WrappedMessageContext(message);
    ProtocolException pe = new ProtocolException("banzai");
    protocolHandlers[2].setException(pe);
    invoker.setRequestor(true);
    assertTrue(invoker.isOutbound());
    boolean continueProcessing = true;
    invoker.setLogicalMessageContext(lmc);
    continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
    assertTrue(continueProcessing);
    // create an empty SOAP body for testing
    try {
        pmc = new SOAPMessageContextImpl(message);
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapMessage = factory.createMessage();
        ((SOAPMessageContext) pmc).setMessage(soapMessage);
    } catch (SOAPException e) {
    // do nothing
    }
    try {
        invoker.setProtocolMessageContext(pmc);
        continueProcessing = invoker.invokeProtocolHandlers(false, pmc);
        fail("did not get expected exception");
    } catch (ProtocolException e) {
        assertEquals("banzai", e.getMessage());
    }
    assertFalse((Boolean) pmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
    assertFalse((Boolean) lmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
    assertTrue(invoker.isInbound());
    // the message is replaced by fault message
    Source responseMessage = lmc.getMessage().getPayload();
    // System.out.println(getSourceAsString(responseMessage));
    assertTrue(getSourceAsString(responseMessage).indexOf("banzai") > -1);
    // assertFalse(continueProcessing);
    assertEquals(1, logicalHandlers[0].getHandleMessageCount());
    assertEquals(1, logicalHandlers[1].getHandleMessageCount());
    assertEquals(1, logicalHandlers[2].getHandleMessageCount());
    assertEquals(1, logicalHandlers[3].getHandleMessageCount());
    assertEquals(1, protocolHandlers[0].getHandleMessageCount());
    assertEquals(1, protocolHandlers[1].getHandleMessageCount());
    assertEquals(1, protocolHandlers[2].getHandleMessageCount());
    assertEquals(0, protocolHandlers[3].getHandleMessageCount());
    assertTrue(logicalHandlers[3].getInvokeOrderOfHandleMessage() < protocolHandlers[0].getInvokeOrderOfHandleMessage());
    assertTrue(protocolHandlers[1].getInvokeOrderOfHandleMessage() < protocolHandlers[2].getInvokeOrderOfHandleMessage());
    assertEquals(1, logicalHandlers[0].getCloseCount());
    assertEquals(1, logicalHandlers[1].getCloseCount());
    assertEquals(1, logicalHandlers[2].getCloseCount());
    assertEquals(1, logicalHandlers[3].getCloseCount());
    assertEquals(1, protocolHandlers[0].getCloseCount());
    assertEquals(1, protocolHandlers[1].getCloseCount());
    assertEquals(1, protocolHandlers[2].getCloseCount());
    assertEquals(0, protocolHandlers[3].getCloseCount());
    assertTrue(protocolHandlers[2].getInvokeOrderOfClose() < protocolHandlers[1].getInvokeOrderOfClose());
    assertTrue(protocolHandlers[0].getInvokeOrderOfClose() < logicalHandlers[3].getInvokeOrderOfClose());
    assertEquals(1, logicalHandlers[0].getHandleFaultCount());
    assertEquals(1, logicalHandlers[1].getHandleFaultCount());
    assertEquals(1, logicalHandlers[2].getHandleFaultCount());
    assertEquals(1, logicalHandlers[3].getHandleFaultCount());
    assertEquals(1, protocolHandlers[0].getHandleFaultCount());
    assertEquals(1, protocolHandlers[1].getHandleFaultCount());
    assertEquals(0, protocolHandlers[2].getHandleFaultCount());
    assertEquals(0, protocolHandlers[3].getHandleFaultCount());
    assertTrue(protocolHandlers[0].getInvokeOrderOfHandleFault() < logicalHandlers[3].getInvokeOrderOfHandleFault());
    assertTrue(protocolHandlers[2].getInvokeOrderOfHandleFault() < protocolHandlers[1].getInvokeOrderOfHandleFault());
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) MessageFactory(javax.xml.soap.MessageFactory) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) SOAPMessage(javax.xml.soap.SOAPMessage) Source(javax.xml.transform.Source) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessageContextImpl(org.apache.cxf.jaxws.handler.soap.SOAPMessageContextImpl) Test(org.junit.Test)

Aggregations

SOAPException (javax.xml.soap.SOAPException)120 SOAPMessage (javax.xml.soap.SOAPMessage)68 IOException (java.io.IOException)38 Element (org.w3c.dom.Element)36 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)24 QName (javax.xml.namespace.QName)22 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPElement (javax.xml.soap.SOAPElement)17 Node (org.w3c.dom.Node)17 SOAPFault (javax.xml.soap.SOAPFault)14 Fault (org.apache.cxf.interceptor.Fault)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)13 SOAPPart (javax.xml.soap.SOAPPart)12 XMLStreamException (javax.xml.stream.XMLStreamException)12 OutputStream (java.io.OutputStream)11 Iterator (java.util.Iterator)11 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)11 ServletException (javax.servlet.ServletException)10 List (java.util.List)9 MessageFactory (javax.xml.soap.MessageFactory)9