Package org.apache.cxf.binding.soap

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


        }
        public void handleMessage(SoapMessage message) throws Fault {   
            XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
            Fault f = (Fault) message.getContent(Exception.class);
   
            SoapFault fault = SoapFault.createFault(f, message.getVersion());
   
            try {
                Map<String, String> namespaces = fault.getNamespaces();
                for (Map.Entry<String, String> e : namespaces.entrySet()) {
                    writer.writeNamespace(e.getKey(), e.getValue());
                }
   
                String ns = message.getVersion().getNamespace();           
                String defaultPrefix = writer.getPrefix(ns);
                if (defaultPrefix == null) {
                    defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false);
                    writer.writeStartElement(defaultPrefix, "Fault", ns);
                    writer.writeNamespace(defaultPrefix, ns);
                } else {
                    writer.writeStartElement(defaultPrefix, "Fault", ns);
                }
   
                writer.writeStartElement("faultcode");
   
                String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()),
                        defaultPrefix);
   
                writer.writeCharacters(codeString);
                writer.writeEndElement();
   
                writer.writeStartElement("faultstring");
                if (fault.getMessage() != null) {
                    writer.writeCharacters(fault.getMessage());
                } else {
                    writer.writeCharacters("Fault occurred while processing.");
                }
                writer.writeEndElement();
                String config = (String)message.getContextualProperty(
                        org.apache.cxf.message.Message.FAULT_STACKTRACE_ENABLED);
                if (config != null && Boolean.valueOf(config).booleanValue() && fault.getCause() != null) {
                    StringBuilder sb = new StringBuilder();
                    for (StackTraceElement ste : fault.getCause().getStackTrace()) {                   
                        sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" + ste.getFileName() 
                                + "!" + ste.getLineNumber() + "\n");
                    }
                    Element detail = fault.getDetail();
                    if (detail == null) {
                        Document doc = XMLUtils.newDocument();
                        Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
                        stackTrace.setTextContent(sb.toString());
                        detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
                        fault.setDetail(detail);
                        detail.appendChild(stackTrace);
                    } else {
                        Element stackTrace = detail.getOwnerDocument().createElementNS(
                                Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
                        stackTrace.setTextContent(sb.toString());
                        detail.appendChild(stackTrace);
                    }                   
                }
   
                if (fault.hasDetails()) {
                    Element detail = fault.getDetail();
                    writer.writeStartElement("detail");
                   
                    Node node = detail.getFirstChild();
                    while (node != null) {
                        StaxUtils.writeNode(node, writer, true);
                        node = node.getNextSibling();
                    }
   
                    // Details
                    writer.writeEndElement();
                }
   
                if (fault.getRole() != null) {
                    writer.writeStartElement("faultactor");
                    writer.writeCharacters(fault.getRole());
                    writer.writeEndElement();
                }
   
                // Fault
                writer.writeEndElement();
View Full Code Here


                                   serviceRoles, ultimateReceiverHeaders);
       
        checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
       
        if (!notUnderstandHeaders.isEmpty()) {
            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders),
                            soapVersion.getMustUnderstand());
        }
        if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
            checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
        }
View Full Code Here

        if (!ultimateReceiverHeaders.isEmpty()) {
            Set<QName> notFound = new HashSet<QName>();
            for (Header h : ultimateReceiverHeaders) {
                notFound.add(h.getName());
            }
            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
                                soapMessage.getVersion().getMustUnderstand());
        }
    }
View Full Code Here

                }
            }
           
           
            if (!notFound.isEmpty()) {
                throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
                                soapVersion.getMustUnderstand());
            }           
        }
View Full Code Here

                // is written to the wire
                //
                saaj.getSOAPPart().getEnvelope().addHeader();
            }
        } catch (SOAPException e) {
            throw new SoapFault(new Message("SOAPEXCEPTION", BUNDLE),
                                e,
                                message.getVersion().getSender());
        }   

        if (saaj == null) {
            SoapVersion version = message.getVersion();
            try {
                MessageFactory factory = getFactory(message);
                SOAPMessage soapMessage = factory.createMessage();

                SOAPPart soapPart = soapMessage.getSOAPPart();
               
                XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
                message.put(ORIGINAL_XML_WRITER, origWriter);
                W3CDOMStreamWriter writer = new W3CDOMStreamWriter(soapPart);
                // Replace stax writer with DomStreamWriter
                message.setContent(XMLStreamWriter.class, writer);
                message.setContent(SOAPMessage.class, soapMessage);
                message.setContent(Node.class, soapMessage.getSOAPPart());
               
               
            } catch (SOAPException e) {
                throw new SoapFault(new Message("SOAPEXCEPTION", BUNDLE), e, version.getSender());
            }
        } else if (!message.containsKey(ORIGINAL_XML_WRITER)) {
            //as the SOAPMessage already has everything in place, we do not need XMLStreamWriter to write
            //anything for us, so we just set XMLStreamWriter's output to a dummy output stream.        
            XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
View Full Code Here

            }
            msg.put(SECURITY_PROCESSED, Boolean.TRUE);

        } catch (WSSecurityException e) {
            LOG.log(Level.WARNING, "", e);
            SoapFault fault = createSoapFault(version, e);
            throw fault;
        } 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

     * Otherwise set the Fault/Code/Value to env:Sender and the Fault/Code/Subcode/Value
     * as the fault code from the WSSecurityException.
     */
    private SoapFault
    createSoapFault(SoapVersion version, WSSecurityException e) {
        SoapFault fault;
        javax.xml.namespace.QName faultCode = e.getFaultCode();
        if (version.getVersion() == 1.1 && faultCode != null) {
            fault = new SoapFault(e.getMessage(), e, faultCode);
        } else {
            fault = new SoapFault(e.getMessage(), e, version.getSender());
            if (version.getVersion() != 1.1 && faultCode != null) {
                fault.setSubCode(faultCode);
            }
        }
        return fault;
    }
View Full Code Here

                        || (aicNonAnon2 != null && !aicNonAnon2.isEmpty());
               
            if (hasAnonymous && hasNonAnon && !hasAnon) {
                message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
                if (isSOAP12(message)) {
                    SoapFault soap12Fault = new SoapFault(
                                                          "Found anonymous address but non-anonymous required",
                                                          Soap12.getInstance().getSender());
                    soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME,
                                                     "OnlyNonAnonymousAddressSupported"));
                    throw soap12Fault;
                }
                throw new SoapFault("Found anonymous address but non-anonymous required",
                                    new QName(Names.WSA_NAMESPACE_NAME,
                                              "OnlyNonAnonymousAddressSupported"));
            } else if (!onlyAnonymous && !hasNonAnon && hasAnon) {
                message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
                if (isSOAP12(message)) {
                    SoapFault soap12Fault = new SoapFault(
                                                          "Found non-anonymous address but only anonymous supported",
                                                          Soap12.getInstance().getSender());
                    soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME,
                                                     "OnlyAnonymousAddressSupported"));
                    throw soap12Fault;
                }
                throw new SoapFault("Found non-anonymous address but only anonymous supported",
                                    new QName(Names.WSA_NAMESPACE_NAME,
                                              "OnlyAnonymousAddressSupported"));
            }
        }
       
View Full Code Here

                // validation failure => dispatch is aborted, response MAPs
                // must be aggregated
                //isFault = true;
                //aggregate(message, isFault);
                if (isSOAP12(message)) {
                    SoapFault soap12Fault = new SoapFault(ContextUtils.retrieveMAPFaultReason(message),
                                                          Soap12.getInstance().getSender());
                    soap12Fault.setSubCode(new QName(Names.WSA_NAMESPACE_NAME, ContextUtils
                        .retrieveMAPFaultName(message)));
                    throw soap12Fault;
                }
                throw new SoapFault(ContextUtils.retrieveMAPFaultReason(message),
                                    new QName(Names.WSA_NAMESPACE_NAME,
                                              ContextUtils.retrieveMAPFaultName(message)));
            }
        } else {
            AddressingPropertiesImpl theMaps =
                ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
            if (null != theMaps) {           
                assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
            }
            // If the wsa policy is enabled , but the client sets the
            // WSAddressingFeature.isAddressingRequired to false , we need to assert all WSA assertion to true
            if (!ContextUtils.isOutbound(message) && ContextUtils.isRequestor(message)
                && getWSAddressingFeature(message) != null
                && !getWSAddressingFeature(message).isAddressingRequired()) {
                assertAddressing(message);
            }
            //CXF-3060 :If wsa policy is not enforced, AddressingProperties map is null and
            // AddressingFeature.isRequired, requestor checks inbound message and throw exception
            if (null == theMaps
                && !ContextUtils.isOutbound(message)
                && ContextUtils.isRequestor(message)
                && getWSAddressingFeature(message) != null
                && getWSAddressingFeature(message).isAddressingRequired()) {
                boolean missingWsaHeader = false;
                AssertionInfoMap aim = message.get(AssertionInfoMap.class);
                if (aim == null || aim.size() == 0) {
                    missingWsaHeader = true;
                }
                if (aim != null && aim.size() > 0) {
                    missingWsaHeader = true;
                    QName[] types = new QName[] {
                        MetadataConstants.ADDRESSING_ASSERTION_QNAME,
                        MetadataConstants.USING_ADDRESSING_2004_QNAME,
                        MetadataConstants.USING_ADDRESSING_2005_QNAME,
                        MetadataConstants.USING_ADDRESSING_2006_QNAME
                    };
                    for (QName type : types) {
                        for (AssertionInfo assertInfo : aim.getAssertionInfo(type)) {
                            if (assertInfo.isAsserted()) {
                                missingWsaHeader = false;
                            }
                        }
                    }
                }
                if (missingWsaHeader) {
                    throw new SoapFault("MISSING_ACTION_MESSAGE", BUNDLE,
                                        new QName(Names.WSA_NAMESPACE_NAME,
                                                  Names.HEADER_REQUIRED_NAME));
                }
            }
            if (MessageUtils.isPartialResponse(message)
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.