Package org.apache.axis2.jaxws.message

Examples of org.apache.axis2.jaxws.message.XMLFault


     * @return XMLFault
     */
    public static XMLFault createXMLFaultFromSystemException(Throwable t) {

        try {
            XMLFault xmlfault = null;
            if (t instanceof SOAPFaultException) {
                if (log.isErrorEnabled()) {
                    log.debug("Marshal SOAPFaultException");
                }
                // Category C: SOAPFaultException
                // Construct the xmlFault from the SOAPFaultException's Fault
                SOAPFaultException sfe = (SOAPFaultException)t;
                SOAPFault soapFault = sfe.getFault();
                if (soapFault == null) {
                    // No fault ?  I will treat this like category E
                    xmlfault =
                        new XMLFault(null,       // Use the default XMLFaultCode
                                     new XMLFaultReason(
                                     t.toString()))// Assumes text lang of current Locale
                } else {
                    xmlfault = XMLFaultUtils.createXMLFault(soapFault);
                }

            } else if (t instanceof WebServiceException) {
                if (log.isErrorEnabled()) {
                    log.debug("Marshal as a WebServiceException");
                }
                // Category D: WebServiceException
                // The reason is constructed with the getMessage of the exception. 
                // There is no detail
                WebServiceException wse = (WebServiceException)t;

                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
                String text = wse.getMessage();
                if (text == null || text.length() == 0) {
                    text = wse.toString();
                }
                xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
                                        new XMLFaultReason(
                                             text))// Assumes text lang of current Locale
            } else {
                if (log.isErrorEnabled()) {
                    log.debug("Marshal as a unchecked System Exception");
                }
                // Category E: Other System Exception
                // The reason is constructed with the toString of the exception. 
                // This places the class name of the exception in the reason
                // There is no detail.
                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
                String text = t.getMessage();
                if (text == null || text.length() == 0) {
                    text = t.toString();
                }
                xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
                                        new XMLFaultReason(
                                                text))// Assumes text lang of current Locale
            }
            return xmlfault;
        } catch (Throwable e) {
            try {
                // If an exception occurs while demarshalling an exception,
                // then rinse and repeat with a webservice exception
                if (log.isDebugEnabled()) {
                    log.debug("An exception (" + e + ") occurred while marshalling exception (" +
                            t + ")");
                }
                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
                String text = e.getMessage();
                if (text == null || text.length() == 0) {
                    text = e.toString();
                }
                WebServiceException wse = ExceptionFactory.makeWebServiceException(e);

                return new XMLFault(null,       // Use the default XMLFaultCode
                                    new XMLFaultReason(
                                            text))// Assumes text lang of current Locale
            } catch (Exception e2) {
                // Exception while creating Exception for Exception
                throw ExceptionFactory.makeWebServiceException(e2);
View Full Code Here


            NoSuchMethodException {

        Throwable exception = null;
       
        // Get the fault from the message and get the detail blocks (probably one)
        XMLFault xmlfault = message.getXMLFault();
        Block[] detailBlocks = xmlfault.getDetailBlocks();

        // If there is only one block, get the element name of that block.
        QName elementQName = null;
        if (detailBlocks != null && detailBlocks.length >= 1) {
            elementQName = detailBlocks[0].getQName();
            if (log.isDebugEnabled()) {
                if (detailBlocks.length > 1) {
                    log.debug("The detail element has multiple child elements.  " +
                            "Only the first child is examined to determine if this is a service exception.  " +
                            "If this first detail child is mapped to a service exception, " +
                            "the information in other detail children may be ignored.  " +
                            "The most common scenario is that the second child is a " +
                            "{http://jax-ws.dev.java.net/}exception element, which is used " +
                            "by some vendors for debugging. ");
                }
            }
        }
       
        if (log.isDebugEnabled()) {
            log.debug("element QName which will be used to find a service exception = " + elementQName);
            log.debug("XMLFault Dump = " +xmlfault.dump(""));
            log.debug("OperationDesc Dump =" + operationDesc);
        }

        // Use the element name to find the matching FaultDescriptor
        FaultDescription faultDesc = null;
        if (elementQName != null) {
            for (int i = 0; i < operationDesc.getFaultDescriptions().length && faultDesc == null;
                 i++) {
                FaultDescription fd = operationDesc.getFaultDescriptions()[i];
                FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(fd);

        if (faultBeanDesc != null) {
          QName tryQName = new QName(faultBeanDesc.getFaultBeanNamespace(),
              faultBeanDesc.getFaultBeanLocalName());
          if (log.isErrorEnabled()) {
            log.debug("  FaultDescription qname is (" + tryQName +
                ") and detail element qname is (" + elementQName + ")");
          }

          if (elementQName.equals(tryQName)) {
            faultDesc = fd;
          }
        }
            }
        }

        if (faultDesc == null && elementQName != null) {
            // If not found, retry the search using just the local name
            for (int i = 0; i < operationDesc.getFaultDescriptions().length && faultDesc == null;
                 i++) {
                FaultDescription fd = operationDesc.getFaultDescriptions()[i];
                FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(fd);
                if (faultBeanDesc != null) {
                  String tryName = faultBeanDesc.getFaultBeanLocalName();
                  if (elementQName.getLocalPart().equals(tryName)) {
                    faultDesc = fd;
                  }
                }
            }
        }


        if (faultDesc == null) {
            // This is a system exception if the method does not throw a checked exception or if
            // the detail block is missing or contains multiple items.
            exception = createSystemException(xmlfault, message);
        } else {
            if (log.isErrorEnabled()) {
                log.debug("Ready to demarshal service exception.  The detail entry name is " +
                        elementQName);
            }
            FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(faultDesc);
            boolean isLegacy =
                    (faultDesc.getFaultInfo() == null || faultDesc.getFaultInfo().length() == 0);

            // Get the JAXB object from the block
            JAXBBlockContext blockContext = new JAXBBlockContext(marshalDesc.getPackages());

            // Note that faultBean may not be a bean, it could be a primitive
            Class faultBeanFormalClass;
            try {
                faultBeanFormalClass = loadClass(faultBeanDesc.getFaultBeanClassName());
            } catch (ClassNotFoundException e){
                faultBeanFormalClass = loadClass(faultBeanDesc.getFaultBeanClassName(), operationDesc.getEndpointInterfaceDescription().getEndpointDescription().getAxisService().getClassLoader());
            }

            // Use "by java type" marshalling if necessary
            if (blockContext.getConstructionType() !=
                JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH &&
                    isNotJAXBRootElement(faultBeanFormalClass, marshalDesc)) {
                blockContext.setProcessType(faultBeanFormalClass);
            }

            // Get the jaxb block and business object
            Block jaxbBlock = factory.createFrom(detailBlocks[0], blockContext);
            Object faultBeanObject = jaxbBlock.getBusinessObject(true);

            // At this point, faultBeanObject is an object that can be rendered as an
            // element.  We want the object that represents the type.
            if (faultBeanObject instanceof JAXBElement) {
                faultBeanObject = ((JAXBElement)faultBeanObject).getValue();
            }

            if (log.isErrorEnabled()) {
                log.debug("Unmarshalled the detail element into a JAXB object");
            }

            // Construct the JAX-WS generated exception that holds the faultBeanObject
            Class exceptionClass;
            try {
                exceptionClass = loadClass(faultDesc.getExceptionClassName());
            } catch (ClassNotFoundException e){
                exceptionClass = loadClass(faultDesc.getExceptionClassName(), operationDesc.getEndpointInterfaceDescription().getEndpointDescription().getAxisService().getClassLoader());
            }
            if (log.isErrorEnabled()) {
                log.debug("Found FaultDescription.  The exception name is " +
                        exceptionClass.getName());
            }
            exception = createServiceException(xmlfault.getReason().getText(),
                                               exceptionClass,
                                               faultBeanObject,
                                               faultBeanFormalClass,
                                               marshalDesc,
                                               isLegacy);
View Full Code Here

                        SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE :
                        SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;

                // The following set of instructions is used to avoid
                // some unimplemented methods in the Axis2 SAAJ implementation
                XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(e);
                javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
                SOAPMessage message = mf.createMessage();
                SOAPBody body = message.getSOAPBody();
                SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
View Full Code Here

            lang = reasonText.getLang();
        }
        XMLFaultReason reason = new XMLFaultReason(text, lang);

        // Construct the XMLFault from the required information (code, reason, detail blocks)
        XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);

        // Add the secondary fault information

        // Get the SubCodes
        SOAPFaultSubCode soapSubCode = soapCode.getSubCode();
        if (soapSubCode != null) {
            List<QName> list = new ArrayList<QName>();

            // Walk the nested sub codes and collect the qnames
            while (soapSubCode != null) {
                SOAPFaultValue soapSubCodeValue = soapSubCode.getValue();
                QName qName = soapSubCodeValue.getTextAsQName();
                list.add(qName);
                soapSubCode = soapSubCode.getSubCode();
            }

            // Put the collected sub code qnames onto the xmlFault
            QName[] qNames = new QName[list.size()];
            xmlFault.setSubCodes(list.toArray(qNames));
        }

        // Get the secondary Reasons...the first reason was already saved as the primary reason
        if (soapTexts != null && soapTexts.size() > 1) {
            XMLFaultReason[] secondaryReasons = new XMLFaultReason[soapTexts.size() - 1];
            for (int i = 1; i < soapTexts.size(); i++) {
                SOAPFaultText soapReasonText = (SOAPFaultText)soapTexts.get(i);
                secondaryReasons[i - 1] = new XMLFaultReason(soapReasonText.getText(),
                                                             soapReasonText.getLang());
            }
            xmlFault.setSecondaryReasons(secondaryReasons);
        }

        // Get the Node
        SOAPFaultNode soapNode = soapFault.getNode();
        if (soapNode != null) {
            xmlFault.setNode(soapNode.getText());
        }

        // Get the Role
        SOAPFaultRole soapRole = soapFault.getRole();
        if (soapRole != null) {
            xmlFault.setRole(soapRole.getText());
        }
        return xmlFault;
    }
View Full Code Here

        String text = soapFault.getFaultString();
        Locale locale = soapFault.getFaultStringLocale();
        XMLFaultReason reason = new XMLFaultReason(text, localeToXmlLang(locale));

        // Construct the XMLFault from the required information (code, reason, detail blocks)
        XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);


        boolean isSOAP12 =
                soapFault.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);

        // Add the secondary fault information

        // Get the SubCodes
        if (isSOAP12) {
            Iterator it = soapFault.getFaultSubcodes();
            List<QName> list = new ArrayList<QName>();
            while (it.hasNext()) {
                QName qName = (QName)it.next();
                list.add(qName);
            }
            if (list.size() > 0) {
                QName[] subCodes = new QName[list.size()];
                subCodes = list.toArray(subCodes);
                xmlFault.setSubCodes(subCodes);
            }
        }

        // Get the secondary Reasons...the first reason was already saved as the primary reason
        if (isSOAP12) {
            try {
                Iterator it = soapFault.getFaultReasonLocales();
                boolean first = true;
                List<XMLFaultReason> list = new ArrayList<XMLFaultReason>();
                while (it.hasNext()) {
                    locale = (Locale)it.next();
                    if (first) {
                        first = false;
                    } else {
                        text = soapFault.getFaultReasonText(locale);
                        list.add(new XMLFaultReason(text, localeToXmlLang(locale)));
                    }
                }
                if (list.size() > 0) {
                    XMLFaultReason[] secondaryReasons = new XMLFaultReason[list.size()];
                    secondaryReasons = list.toArray(secondaryReasons);
                    xmlFault.setSecondaryReasons(secondaryReasons);
                }
            } catch (SOAPException se) {
                throw ExceptionFactory.makeWebServiceException(se);
            }
        }

        // Get the Node
        if (isSOAP12) {
            String soapNode = soapFault.getFaultNode();
            if (soapNode != null) {
                xmlFault.setNode(soapNode);
            }
        }

        // Get the Role
        String soapRole = soapFault
                .getFaultActor()// getFaultActor works for both SOAP 1.1 and SOAP 1.2 per spec
        if (soapRole != null) {
            xmlFault.setRole(soapRole);
        }

        return xmlFault;
    }
View Full Code Here

    /* (non-Javadoc)
      * @see org.apache.axis2.jaxws.message.XMLPart#getXMLFault()
      */
    public XMLFault getXMLFault() throws WebServiceException {

        XMLFault xmlFault = null;

        if (isFault()) {
            // An XMLFault represents the detail elements as Blocks, so
            // it makes sense to convert the representation to a Spine since
            // that is what we do in other situations where we need a Block.
            // Of course there is some additional optimization that could be done.
            // If we can determine that there are no detail elements, then we could
            // build the fault from an OM or SOAPEnvelope. 
            XMLSpine spine = getContentAsXMLSpine();
            xmlFault = spine.getXMLFault();

            // For each block in the xmlfault, set the message
            Block[] blocks = xmlFault.getDetailBlocks();
            if (blocks != null) {
                for (int i = 0; i < blocks.length; i++) {
                    blocks[i].setParent(getParent());
                }
            }
View Full Code Here

       
        Message m;
        try {
            EndpointDescription endpointDesc = request.getEndpointDescription();
            Service.Mode mode = endpointDesc.getServiceMode();
            XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(fault);
            m = createMessageFromValue(xmlFault, request.getMessage().getProtocol(), mode);
        } catch (Exception e) {
            throw ExceptionFactory.makeWebServiceException(e);
        }
       
View Full Code Here

                blocks[i] = this._getBlockFromOMElement(om, null, obf, false);

            }
        }

        XMLFault xmlFault = XMLFaultUtils.createXMLFault(root.getBody().getFault(), blocks);
        return xmlFault;
    }
View Full Code Here

        }
    }
   
    public static MessageContext createFaultMessage(MessageContext mc, String msg) {
        try {
            XMLFault xmlfault =
                    new XMLFault(XMLFaultCode.VERSIONMISMATCH, new XMLFaultReason(msg));
            MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
            Message message = mf.create(Protocol.soap11);
            message.setXMLFault(xmlfault);
           
            MessageContext responseMsgCtx = MessageContextUtils.createFaultMessageContext(mc);
View Full Code Here

            lang = reasonText.getLang();
        }
        XMLFaultReason reason = new XMLFaultReason(text, lang);

        // Construct the XMLFault from the required information (code, reason, detail blocks)
        XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);

        // Add the secondary fault information

        // Get the SubCodes
        SOAPFaultSubCode soapSubCode = soapCode.getSubCode();
        if (soapSubCode != null) {
            List<QName> list = new ArrayList<QName>();

            // Walk the nested sub codes and collect the qnames
            while (soapSubCode != null) {
                SOAPFaultValue soapSubCodeValue = soapSubCode.getValue();
                QName qName = soapSubCodeValue.getTextAsQName();
                list.add(qName);
                soapSubCode = soapSubCode.getSubCode();
            }

            // Put the collected sub code qnames onto the xmlFault
            QName[] qNames = new QName[list.size()];
            xmlFault.setSubCodes(list.toArray(qNames));
        }

        // Get the secondary Reasons...the first reason was already saved as the primary reason
        if (soapTexts != null && soapTexts.size() > 1) {
            XMLFaultReason[] secondaryReasons = new XMLFaultReason[soapTexts.size() - 1];
            for (int i = 1; i < soapTexts.size(); i++) {
                SOAPFaultText soapReasonText = (SOAPFaultText)soapTexts.get(i);
                secondaryReasons[i - 1] = new XMLFaultReason(soapReasonText.getText(),
                                                             soapReasonText.getLang());
            }
            xmlFault.setSecondaryReasons(secondaryReasons);
        }

        // Get the Node
        SOAPFaultNode soapNode = soapFault.getNode();
        if (soapNode != null) {
            xmlFault.setNode(soapNode.getText());
        }

        // Get the Role
        SOAPFaultRole soapRole = soapFault.getRole();
        if (soapRole != null) {
            xmlFault.setRole(soapRole.getText());
        }
        return xmlFault;
    }
View Full Code Here

TOP

Related Classes of org.apache.axis2.jaxws.message.XMLFault

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.