Package javax.xml.soap

Examples of javax.xml.soap.SOAPException


   
    public void testMarshalSystemFaults() throws Exception {
        //Test The InputMessage of GreetMe Operation
        soapContext.put(ObjectMessageContext.MESSAGE_INPUT, false);

        SOAPException se = new SOAPException("SAAJ Exception");
        objContext.setException(se);

        binding.marshalFault(objContext,
                             soapContext,
                             new JAXBDataBindingCallback(objContext.getMethod(),
                                                         DataBindingCallback.Mode.PARTS,
                                                         null));
        SOAPMessage msg = soapContext.getMessage();
       
        assertNotNull(msg);
        Node xmlNode = msg.getSOAPBody();
        assertNotNull(xmlNode);
        assertEquals(1, xmlNode.getChildNodes().getLength());

        assertTrue(msg.getSOAPBody().hasFault());
        SOAPFault fault = msg.getSOAPBody().getFault();
        assertNotNull(fault);
        assertEquals(
                     getExceptionString(se, se.getMessage()),
                     fault.getFaultString());
        assertTrue(fault.hasChildNodes());
        NodeList list = fault.getChildNodes();
        assertEquals(2, list.getLength());        
    }
View Full Code Here


                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new SOAPException("Could not figure out how to marshal data");
                    }
                } else if (callback.getMode() == DataBindingCallback.Mode.PAYLOAD) {
                    // contains the contents of the SOAP:Body
                    boolean found = false;
                    Object src = isInputMsg ? objContext.getReturn() : objContext.getMessageObjects()[0];

                    for (Class<?> cls : callback.getSupportedFormats()) {
                        if (cls == DOMSource.class || cls == SAXSource.class || cls == StreamSource.class
                            || cls == Object.class) {
                            DataWriter<SOAPBody> writer = callback.createWriter(SOAPBody.class);
                            writer.write(src, msg.getSOAPBody());
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new SOAPException("Could not figure out how to marshal data");
                    }
                }
            } else {
                LOG.fine("Leaving soap message empty - no data binding callback");
            }
View Full Code Here

            return;
        }
        try {
            boolean isOutputMsg = (Boolean)mc.get(ObjectMessageContext.MESSAGE_INPUT);
            if (!SOAPMessageContext.class.isInstance(mc)) {
                throw new SOAPException("SOAPMessageContext not available");
            }

            SOAPMessageContext soapContext = SOAPMessageContext.class.cast(mc);
            SOAPMessage soapMessage = soapContext.getMessage();

            if (callback.getMode() == DataBindingCallback.Mode.PARTS) {
                // Assuming No Headers are inserted.
                Node soapEl = soapMessage.getSOAPBody();

                if (callback.getSOAPStyle() == Style.RPC) {
                    soapEl = NodeUtils.getChildElementNode(soapEl);
                }

                if (soapEl.hasChildNodes()) {
                    getParts(soapEl, callback, objContext, isOutputMsg);
                } else {
                    LOG.fine("Body of SOAP message is empty.");
                }

                getHeaderParts(soapMessage.getSOAPHeader(), callback, objContext, isOutputMsg);
            } else if (callback.getMode() == DataBindingCallback.Mode.MESSAGE) {
                boolean found = false;
                Object obj = null;
                for (Class<?> cls : callback.getSupportedFormats()) {
                    if (cls == SOAPMessage.class) {
                        obj = soapMessage;
                        found = true;
                        break;
                    } else if (cls == DOMSource.class
                        || cls == SAXSource.class
                        || cls == StreamSource.class) {
                        DataReader<SOAPMessage> reader = callback.createReader(SOAPMessage.class);
                        obj = reader.read(0, soapMessage);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new SOAPException("Cannot unmarshal data");
                }

                if (isOutputMsg) {
                    objContext.setReturn(obj);
                } else {
                    objContext.setMessageObjects(obj);
                }

            } else if (callback.getMode() == DataBindingCallback.Mode.PAYLOAD) {
                boolean found = false;
                Object obj = null;
                for (Class<?> cls : callback.getSupportedFormats()) {
                    if (cls == DOMSource.class
                        || cls == SAXSource.class
                        || cls == StreamSource.class
                        || cls == Object.class) {
                        DataReader<SOAPBody> reader = callback.createReader(SOAPBody.class);
                        obj = reader.read(0, soapMessage.getSOAPBody());
                        found = true;
                        break;
                    }
                }
               
               
               
                if (!found) {
                    throw new SOAPException("Cannot unmarshal data");
                }

                if (isOutputMsg) {
                    objContext.setReturn(obj);
                } else {
View Full Code Here

    public void unmarshalFault(MessageContext context, ObjectMessageContext objContext,
                               DataBindingCallback callback) {
        try {
            if (!SOAPMessageContext.class.isInstance(context)) {
                throw new SOAPException("SOAPMessageContext not available");
            }

            SOAPMessageContext soapContext = SOAPMessageContext.class.cast(context);
            SOAPMessage soapMessage = soapContext.getMessage();
View Full Code Here

                break;
            }
        }

        if (reader == null) {
            throw new SOAPException("Could not figure out how to unmarshal data");
        }

        if (callback.getSOAPStyle() == Style.DOCUMENT
            && callback.getSOAPParameterStyle() == ParameterStyle.WRAPPED) {
            reader.readWrapper(objCtx, isOutBound, xmlNode);
            return;
        }

        Node childNode = NodeUtils.getChildElementNode(xmlNode);
        if (isOutBound && callback.getWebResult() != null && !callback.getWebResult().header()) {

            Object retVal = reader.read(callback.getWebResultQName(), -1, childNode);
            objCtx.setReturn(retVal);
            childNode = childNode.getNextSibling();
        }

        WebParam.Mode ignoreParamMode = isOutBound ? WebParam.Mode.IN : WebParam.Mode.OUT;
        int noArgs = callback.getParamsLength();

        // Unmarshal parts of mode that should notbe ignored and are not part of
        // the SOAP Headers
        Object[] methodArgs = objCtx.getMessageObjects();

        for (int idx = 0; idx < noArgs; idx++) {
            WebParam param = callback.getWebParam(idx);
            if ((param.mode() != ignoreParamMode) && !param.header()) {

                QName elName = (callback.getSOAPStyle() == Style.DOCUMENT)
                                ? new QName(param.targetNamespace(), param.name())
                                : new QName("", param.partName());

                Object obj = reader.read(elName, idx, childNode);
                if (param.mode() != WebParam.Mode.IN) {
                    try {
                        // TO avoid type safety warning the Holder
                        // needs tobe set as below.
                        methodArgs[idx].getClass().getField("value").set(methodArgs[idx], obj);
                    } catch (Exception ex) {
                        throw new SOAPException("Can not set the part value into the Holder field.");
                    }
                } else {
                    methodArgs[idx] = obj;
                }
                childNode = childNode.getNextSibling();
View Full Code Here

                // TODO - other formats to support?
                // StreamSource/DOMSource/STaX/etc..
            }
        }
        if (writer == null) {
            throw new SOAPException("Could not figure out how to marshal data");
        }

        if (callback.getSOAPStyle() == Style.DOCUMENT
            && callback.getSOAPParameterStyle() == ParameterStyle.WRAPPED) {
            writer.writeWrapper(objCtx, isOutBound, xmlNode);
View Full Code Here

                // StreamSource/DOMSource/STaX/etc..
            }
        }

        if (reader == null) {
            throw new SOAPException("Could not figure out how to marshal data");
        }

        if (isOutBound && callback.getWebResult() != null && callback.getWebResult().header()) {

            QName elName = callback.getWebResultQName();
            NodeList headerElems = header.getElementsByTagNameNS(elName.getNamespaceURI(), elName
                .getLocalPart());
            assert headerElems.getLength() == 1;
            Node childNode = headerElems.item(0);

            Object retVal = reader.read(elName, -1, childNode);
            objCtx.setReturn(retVal);
        }

        WebParam.Mode ignoreParamMode = isOutBound ? WebParam.Mode.IN : WebParam.Mode.OUT;
        int noArgs = callback.getParamsLength();

        // Unmarshal parts of mode that should notbe ignored and are not part of
        // the SOAP Headers
        Object[] methodArgs = (Object[])objCtx.getMessageObjects();
        for (int idx = 0; idx < noArgs; idx++) {
            WebParam param = callback.getWebParam(idx);
            if ((param.mode() != ignoreParamMode) && param.header()) {
                QName elName = new QName(param.targetNamespace(), param.name());
                NodeList headerElems = header.getElementsByTagNameNS(elName.getNamespaceURI(), elName
                    .getLocalPart());
                assert headerElems.getLength() == 1;
                Node childNode = headerElems.item(0);

                Object obj = reader.read(elName, idx, childNode);
                if (param.mode() != WebParam.Mode.IN) {
                    try {
                        // TO avoid type safety warning the Holder
                        // needs tobe set as below.
                        methodArgs[idx].getClass().getField("value").set(methodArgs[idx], obj);
                    } catch (Exception ex) {
                        throw new SOAPException("Can not set the part value into the Holder field.");
                    }
                } else {
                    methodArgs[idx] = obj;
                }
            }
View Full Code Here

                // TODO - other formats to support?
                // StreamSource/DOMSource/STaX/etc..
            }
        }
        if (writer == null) {
            throw new SOAPException("Could not figure out how to marshal data");
        }

        if (isOutBound && callback.getWebResult() != null && callback.getWebResult().header()) {
            SOAPHeader header = envelope.getHeader();
            wroteHeader = true;
View Full Code Here

    }
   
    static Object find(String factoryPropertyName) throws SOAPException {
        String factoryClassName = getFactoryClass(factoryPropertyName);
        if (factoryClassName == null) {
            throw new SOAPException(
                    "Provider for " + factoryPropertyName + " cannot be found",
                    null);
        } else {
            return newInstance(factoryClassName);
        }       
View Full Code Here

            } catch (ClassNotFoundException cnfe) {
                factory = SAAJFactoryFinder.class.getClassLoader().loadClass(factoryClassName);
            }
            return factory.newInstance();
        } catch (ClassNotFoundException e) {
            throw new SOAPException("Provider " + factoryClassName + " not found", e);
        } catch (Exception e) {
            throw new SOAPException("Provider " + factoryClassName + " could not be instantiated: "
                                    + e.getMessage(), e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.soap.SOAPException

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.