Package org.apache.cxf.binding.soap

Examples of org.apache.cxf.binding.soap.SoapFault


        greeter.greetMe("one");
        try {
            greeter.greetMe("two");
            fail("Expected fault.");
        } catch (WebServiceException ex) {
            SoapFault sf = (SoapFault)ex.getCause();
            assertEquals("Unexpected fault code.", Soap11.getInstance().getReceiver(), sf.getFaultCode());
            assertNull("Unexpected sub code.", sf.getSubCode());
            assertTrue("Unexpected reason.", sf.getReason().endsWith("has already been delivered."));
        }
       
        // wait for resend to occur
       
        awaitMessages(3, 3, 5000);
View Full Code Here


      
        try {
            greeter.greetMe("one");
            fail("Expected fault.");
        } catch (WebServiceException ex) {
            SoapFault sf = (SoapFault)ex.getCause();
            assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
            assertNull("Unexpected sub code.", sf.getSubCode());
            assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
        }  
       
        // the third inbound message has a SequenceFault header
        MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages());
        mf.verifySequenceFault(RMConstants.getUnknownSequenceFaultCode(), false, 1);
View Full Code Here

       
        try {
            greeter.greetMe("two");
            fail("Expected fault.");
        } catch (WebServiceException ex) {
            SoapFault sf = (SoapFault)ex.getCause();
            assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
            assertNull("Unexpected sub code.", sf.getSubCode());
            assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
        }  
       
        awaitMessages(3, 3, 5000);
       
        MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages());
View Full Code Here

            String actor = (String)getOption(WSHandlerConstants.ACTOR);

            SOAPMessage doc = msg.getContent(SOAPMessage.class);

            if (doc == null) {
                throw new SoapFault(new Message("NO_SAAJ_DOC", LOG), version.getReceiver());
            }

            CallbackHandler cbHandler = getCallback(reqData, doAction);

            /*
             * Get and check the Signature specific parameters first because
             * they may be used for encryption too.
             */
            doReceiverAction(doAction, reqData);

            Vector wsResult = null;
            if (doTimeLog) {
                t1 = System.currentTimeMillis();
            }

            try {
                wsResult = secEngine.processSecurityHeader(doc.getSOAPPart(), actor, cbHandler, reqData
                    .getSigCrypto(), reqData.getDecCrypto());
            } catch (WSSecurityException ex) {
                LOG.log(Level.WARNING, "", ex);
                throw new SoapFault(new Message("SECURITY_FAILED", LOG), ex, version.getSender());
            }

            if (doTimeLog) {
                t2 = System.currentTimeMillis();
            }

            if (wsResult == null) { // no security header found
                if (doAction == WSConstants.NO_SECURITY) {
                    return;
                } else {
                    LOG.warning("Request does not contain required Security header");
                    throw new SoapFault(new Message("NO_SECURITY", LOG), version.getSender());
                }
            }

            if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
                checkSignatureConfirmation(reqData, wsResult);
            }

            /*
             * Now we can check the certificate used to sign the message. In the
             * following implementation the certificate is only trusted if
             * either it itself or the certificate of the issuer is installed in
             * the keystore. Note: the method verifyTrust(X509Certificate)
             * allows custom implementations with other validation algorithms
             * for subclasses.
             */

            // Extract the signature action result from the action vector
            WSSecurityEngineResult actionResult = WSSecurityUtil
                .fetchActionResult(wsResult, WSConstants.SIGN);

            if (actionResult != null) {
                X509Certificate returnCert = actionResult.getCertificate();

                if (returnCert != null && !verifyTrust(returnCert, reqData)) {
                    LOG.warning("The certificate used for the signature is not trusted");
                    throw new SoapFault(new Message("UNTRUSTED_CERT", LOG), version.getSender());
                }
                msg.put(SIGNATURE_RESULT, actionResult);
            }

            /*
             * Perform further checks on the timestamp that was transmitted in
             * the header. In the following implementation the timestamp is
             * valid if it was created after (now-ttl), where ttl is set on
             * server side, not by the client. Note: the method
             * verifyTimestamp(Timestamp) allows custom implementations with
             * other validation algorithms for subclasses.
             */

            // Extract the timestamp action result from the action vector
            actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.TS);

            if (actionResult != null) {
                Timestamp timestamp = actionResult.getTimestamp();

                if (timestamp != null && !verifyTimestamp(timestamp, decodeTimeToLive(reqData))) {
                    LOG.warning("The timestamp could not be validated");
                    throw new SoapFault(new Message("INVALID_TIMESTAMP", LOG), version.getSender());
                }
                msg.put(TIMESTAMP_RESULT, actionResult);
            }

            /*
             * now check the security actions: do they match, in right order?
             */
            if (!checkReceiverResults(wsResult, actions)) {
                LOG.warning("Security processing failed (actions mismatch)");
                throw new SoapFault(new Message("ACTION_MISMATCH", LOG), version.getSender());

            }

            doResults(msg, actor, doc, wsResult);

            if (doTimeLog) {
                t3 = System.currentTimeMillis();
                TIME_LOG.fine("Receive request: total= " + (t3 - t0)
                        + " request preparation= " + (t1 - t0)
                        + " request processing= " + (t2 - t1)
                        + " header, cert verify, timestamp= " + (t3 - t2) + "\n");
            }

            if (doDebug) {
                LOG.fine("WSS4JInHandler: exit invoke()");
            }

        } catch (WSSecurityException e) {
            LOG.log(Level.WARNING, "", e);
            throw new SoapFault(new Message("WSSECURITY_EX", LOG), e, version.getSender());
        } catch (XMLStreamException e) {
            throw new SoapFault(new Message("STAX_EX", LOG), e, version.getSender());
        } catch (SOAPException e) {
            throw new SoapFault(new Message("SAAJ_EX", LOG), e, version.getSender());
        } finally {
            reqData.clear();
            reqData = null;
        }
    }
View Full Code Here

        if (action == null) {
            action = (String)msg.get(WSHandlerConstants.ACTION);
        }
        if (action == null) {
            LOG.warning("No security action was defined!");
            throw new SoapFault("No security action was defined!", version.getReceiver());
        }
        return action;
    }
View Full Code Here

             * Get the action first.
             */
            Vector actions = new Vector();
            String action = getString(WSHandlerConstants.ACTION, mc);
            if (action == null) {
                throw new SoapFault(new Message("NO_ACTION", LOG), version
                        .getReceiver());
            }

            int doAction = WSSecurityUtil.decodeAction(action, actions);
            if (doAction == WSConstants.NO_SECURITY) {
                return;
            }

            /*
             * For every action we need a username, so get this now. The
             * username defined in the deployment descriptor takes precedence.
             */
            reqData.setUsername((String) getOption(WSHandlerConstants.USER));
            if (reqData.getUsername() == null
                    || reqData.getUsername().equals("")) {
                String username = (String) getProperty(reqData.getMsgContext(),
                        WSHandlerConstants.USER);
                if (username != null) {
                    reqData.setUsername(username);
                }
            }

            /*
             * Now we perform some set-up for UsernameToken and Signature
             * functions. No need to do it for encryption only. Check if
             * username is available and then get a passowrd.
             */
            if ((doAction & (WSConstants.SIGN | WSConstants.UT | WSConstants.UT_SIGN)) != 0
                    && (reqData.getUsername() == null
                    || reqData.getUsername().equals(""))) {
                /*
                 * We need a username - if none throw an SoapFault. For
                 * encryption there is a specific parameter to get a username.
                 */
                throw new SoapFault(new Message("NO_USERNAME", LOG), version
                        .getReceiver());
            }
            if (doDebug) {
                LOG.fine("Action: " + doAction);
                LOG.fine("Actor: " + reqData.getActor());
            }
            /*
             * Now get the SOAP part from the request message and convert it
             * into a Document. This forces CXF to serialize the SOAP request
             * into FORM_STRING. This string is converted into a document.
             * During the FORM_STRING serialization CXF performs multi-ref of
             * complex data types (if requested), generates and inserts
             * references for attachements and so on. The resulting Document
             * MUST be the complete and final SOAP request as CXF would send it
             * over the wire. Therefore this must shall be the last (or only)
             * handler in a chain. Now we can perform our security operations on
             * this request.
             */
            SOAPMessage saaj = mc.getContent(SOAPMessage.class);

            if (saaj == null) {
                LOG.warning("SAAJOutHandler must be enabled for WS-Security!");
                throw new SoapFault(new Message("NO_SAAJ_DOC", LOG), version
                        .getReceiver());
            }

            Document doc = saaj.getSOAPPart();
            /**
             * There is nothing to send...Usually happens when the provider
             * needs to send a HTTP 202 message (with no content)
             */
            if (mc == null) {
                return;
            }

            if (doTimeDebug) {
                t1 = System.currentTimeMillis();
            }

            doSenderAction(doAction, doc, reqData, actions, !Boolean.TRUE
                    .equals(getProperty(mc, org.apache.cxf.message.Message.REQUESTOR_ROLE)));

            if (doTimeDebug) {
                t2 = System.currentTimeMillis();
                TIME_LOG.fine("Send request: total= " + (t2 - t0)
                        + " request preparation= " + (t1 - t0)
                        + " request processing= " + (t2 - t1)
                        + "\n");
            }

            if (doDebug) {
                LOG.fine("WSDoAllSender: exit invoke()");
            }
        } catch (WSSecurityException e) {
            throw new SoapFault(new Message("SECURITY_FAILED", LOG), e, version
                    .getSender());
        } finally {
            reqData.clear();
            reqData = null;
        }
View Full Code Here

                setUpMessageProperty(message,
                                     REQUESTOR_ROLE,
                                     Boolean.FALSE);
               
                if (fault) {
                    message.setContent(Exception.class, new SoapFault("blah",
                            (Throwable) new Exception(), Fault.FAULT_CODE_SERVER));
                    expectedAction = "http://foo/bar/SEI/op/Fault/Exception";
                } else {
                    expectedAction = "http://foo/bar/SEI/opResponse";
                }
View Full Code Here

    }

    public static SoapVersion readVersion(XMLStreamReader xmlReader, SoapMessage message) {
        String ns = xmlReader.getNamespaceURI();
        if (ns == null || "".equals(ns)) {
            throw new SoapFault(new Message("NO_NAMESPACE", LOG, xmlReader.getLocalName()),
                                Soap11.getInstance().getVersionMismatch());
        }
       
        SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
        if (soapVersion == null) {
            throw new SoapFault(new Message("INVALID_VERSION", LOG, ns, xmlReader.getLocalName()),
                                    Soap11.getInstance().getVersionMismatch());
        }
        message.setVersion(soapVersion);
        return soapVersion;
    }
View Full Code Here

               
                SoapVersion soapVersion = readVersion(xmlReader, message);
                if (soapVersion == Soap12.getInstance()
                    && version == Soap11.getInstance()) {
                    message.setVersion(version);
                    throw new SoapFault(new Message("INVALID_11_VERSION", LOG),
                                        version.getVersionMismatch());                   
                }

                XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, message.getVersion()
                    .getBody());

                Node nd = message.getContent(Node.class);
                Document doc = null;
                if (nd instanceof Document) {
                    doc = (Document)nd;
                    StaxUtils.readDocElements(doc, doc, filteredReader, false, false);
                } else {
                    doc = StaxUtils.read(filteredReader);
                    message.setContent(Node.class, doc);
                }

                // Find header
                // TODO - we could stream read the "known" headers and just DOM read the
                // unknown ones
                Element element = doc.getDocumentElement();
                QName header = soapVersion.getHeader();               
                List<Element> elemList =
                    DOMUtils.findAllElementsByTagNameNS(element,
                                                        header.getNamespaceURI(),
                                                        header.getLocalPart());
                for (Element elem : elemList) {
                    Element hel = DOMUtils.getFirstElement(elem);
                    while (hel != null) {
                        // Need to add any attributes that are present on the parent element
                        // which otherwise would be lost.
                        if (elem.hasAttributes()) {
                            NamedNodeMap nnp = elem.getAttributes();
                            for (int ct = 0; ct < nnp.getLength(); ct++) {
                                Node attr = nnp.item(ct);
                                Node headerAttrNode = hel.hasAttributes()
                                        ?  hel.getAttributes().getNamedItemNS(
                                                        attr.getNamespaceURI(), attr.getLocalName())
                                        : null;
                               
                                if (headerAttrNode == null) {
                                    Attr attribute = hel.getOwnerDocument().createAttributeNS(
                                            attr.getNamespaceURI(),
                                            attr.getNodeName());
                                    attribute.setNodeValue(attr.getNodeValue());
                                    hel.setAttributeNodeNS(attribute);
                                }
                            }
                        }
                       
                        HeaderProcessor p = bus == null ? null : bus.getExtension(HeaderManager.class)
                            .getHeaderProcessor(hel.getNamespaceURI());

                        Object obj;
                        DataBinding dataBinding = null;
                        if (p == null || p.getDataBinding() == null) {
                            obj = hel;
                        } else {
                            dataBinding = p.getDataBinding();
                            obj = dataBinding.createReader(Node.class).read(hel);
                        }
                        //TODO - add the interceptors
                       
                        SoapHeader shead = new SoapHeader(new QName(hel.getNamespaceURI(),
                                                                    hel.getLocalName()),
                                                           obj,
                                                           dataBinding);
                        String mu = hel.getAttributeNS(soapVersion.getNamespace(),
                                                      soapVersion.getAttrNameMustUnderstand());
                        String act = hel.getAttributeNS(soapVersion.getNamespace(),
                                                        soapVersion.getAttrNameRole());

                        if (!StringUtils.isEmpty(act)) {
                            shead.setActor(act);
                        }
                        shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
                        //mark header as inbound header.(for distinguishing between the  direction to
                        //avoid piggybacking of headers from request->server->response.
                        shead.setDirection(SoapHeader.Direction.DIRECTION_IN);
                        message.getHeaders().add(shead);
                       
                        hel = DOMUtils.getNextElement(hel);
                    }
                }
                if (MessageUtils.getContextualBoolean(message,
                                                      SoapMessage.SCHEMA_VALIDATION_ENABLED,
                                                      false)) {
                    message.getInterceptorChain().add(new CheckClosingTagsInterceptor());
                }
            }
        } catch (XMLStreamException e) {
            throw new SoapFault(new Message("XML_STREAM_EXC", LOG), e, message.getVersion().getSender());
        } finally {
            if (closeNeeded) {
                StaxUtils.close(xmlReader);
            }
        }
View Full Code Here

                        if (xmlReader.next() == XMLStreamReader.END_DOCUMENT) {
                            return;
                        }
                    }
                } catch (XMLStreamException e) {
                    throw new SoapFault(e.getMessage(), e,
                                        message.getVersion().getSender());
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.cxf.binding.soap.SoapFault

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.