Package org.apache.axis.message

Examples of org.apache.axis.message.SOAPBodyElement


        Call     call    = (Call) service.createCall();

        call.setTargetEndpointAddress( new URL(opts.getURL()) );
        SOAPBodyElement[] input = new SOAPBodyElement[3];

        input[0] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
                                                                "e1", "Hello"));
        input[1] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
                                                                "e1", "World"));

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc            = builder.newDocument();  
        Element cdataElem       = doc.createElementNS("urn:foo", "e3");
        CDATASection cdata      = doc.createCDATASection("Text with\n\tImportant  <b>  whitespace </b> and tags! ");     
        cdataElem.appendChild(cdata);
   
        input[2] = new SOAPBodyElement(cdataElem);
       
        Vector          elems = (Vector) call.invoke( input );
        SOAPBodyElement elem  = null ;
        Element         e     = null ;

        elem = (SOAPBodyElement) elems.get(0);
        e    = elem.getAsDOM();

        String str = "Res elem[0]=" + XMLUtils.ElementToString(e);

        elem = (SOAPBodyElement) elems.get(1);
        e    = elem.getAsDOM();
        str = str + "Res elem[1]=" + XMLUtils.ElementToString(e);

        elem = (SOAPBodyElement) elems.get(2);
        e    = elem.getAsDOM();
        str = str + "Res elem[2]=" + XMLUtils.ElementToString(e);
       
        return( str );
    }
View Full Code Here


       msgContext.setHighFidelity(true);
       String request = header + request2 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);
       SOAPEnvelope envelope = message.getSOAPEnvelope();
       SOAPBodyElement bodyElement = (SOAPBodyElement)envelope.getBodyElements().elementAt(0);
       MessageElement me = (MessageElement) bodyElement.getChildren().get(0);
       org.xml.sax.Attributes atts = me.getCompleteAttributes();
       assertTrue(atts.getLength()==2);
    }
View Full Code Here

       assertTrue(atts.getLength()==2);
    }

    public void testEmptyNode() throws Exception
    {
        SOAPBodyElement body = new SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
        assertEquals("<tmp/>",body.toString());
    }
View Full Code Here

    public void testNodeWithAttribute() throws Exception
    {
        org.w3c.dom.Element element = XMLUtils.newDocument().createElement("tmp");
        element.setAttribute("attrib", "foo");
        SOAPBodyElement body = new SOAPBodyElement(element);
        assertEquals("<tmp attrib=\"foo\"/>",body.toString());
    }
View Full Code Here

            return null;
          }
        }

        resEnv = resMsg.getSOAPEnvelope();
        SOAPBodyElement bodyEl = resEnv.getFirstBody();
        if (bodyEl instanceof RPCElement) {
            try {
                resArgs = ((RPCElement) bodyEl).getParams();
            } catch (Exception e) {
                log.error(Messages.getMessage("exception00"), e);
                throw AxisFault.makeFault(e);
            }

            if (resArgs != null && resArgs.size() > 0) {

                // If there is no return, then we start at index 0 to create the outParams Map.
                // If there IS a return, then we start with 1.
                int outParamStart = 0;

                // If we have resArgs and the returnType is specified, then the first
                // resArgs is the return.  If we have resArgs and neither returnType
                // nor paramXMLTypes are specified, then we assume that the caller is
                // following the non-JAX-RPC AXIS shortcut of not having to specify
                // the return, in which case we again assume the first resArgs is
                // the return.
                // NOTE 1:  the non-JAX-RPC AXIS shortcut allows a potential error
                // to escape notice.  If the caller IS NOT following the non-JAX-RPC
                // shortcut but instead intentionally leaves returnType and params
                // null (ie., a method that takes no parameters and returns nothing)
                // then, if we DO receive something it should be an error, but this
                // code passes it through.  The ideal solution here is to require
                // this caller to set the returnType to void, but there's no void
                // type in XML.
                // NOTE 2:  we should probably verify that the resArgs element
                // types match the expected returnType and paramXMLTypes, but I'm not
                // sure how to do that since the resArgs value is a Java Object
                // and the returnType and paramXMLTypes are QNames.

                // GD 03/15/02 : We're now checking for invalid metadata
                // config at the top of this method, so don't need to do it
                // here.  Check for void return, though.

                boolean findReturnParam = false;
                QName returnParamQName = null;
                if (operation != null) operation.getReturnQName();

                if (!XMLType.AXIS_VOID.equals(getReturnType())) {
                    if (returnParamQName == null) {
                        // Assume the first param is the return
                        RPCParam param = (RPCParam)resArgs.get(0);
                        result = param.getValue();
                        outParamStart = 1;
                    } else {
                        // If the QName of the return value was given to us, look
                        // through the result arguments to find the right name
                        findReturnParam = true;
                    }
                }

                // The following loop looks at the resargs and
                // converts the value to the appropriate return/out parameter
                // value.  If the return value is found, is value is
                // placed in result.  The remaining resargs are
                // placed in the outParams list (note that if a resArg
                // is found that does not match a operation parameter qname,
                // it is still placed in the outParms list).
                for (int i = outParamStart; i < resArgs.size(); i++) {
                    RPCParam param = (RPCParam) resArgs.get(i);

                    Class javaType = getJavaTypeForQName(param.getQName());
                    Object value = param.getValue();

                    // Convert type if needed
                    if (javaType != null && value != null &&
                           !javaType.isAssignableFrom(value.getClass())) {
                        value = JavaUtils.convert(value, javaType);
                    }

                    // Check if this parameter is our return
                    // otherwise just add it to our outputs
                    if (findReturnParam &&
                          returnParamQName.equals(param.getQName())) {
                        // found it!
                        result = value;
                        findReturnParam = false;
                    } else {
                        outParams.put(param.getQName(), value);
                        outParamsList.add(value);
                    }
                }

                // added by scheu:
                // If the return param is still not found, that means
                // the returned value did not have the expected qname.
                // The soap specification indicates that this should be
                // accepted (and we also fail interop tests if we are strict here).
                // Look through the outParms and find one that
                // does not match one of the operation parameters.
                if (findReturnParam) {
                    Iterator it = outParams.keySet().iterator();
                    while (it.hasNext() && findReturnParam) {
                        QName qname = (QName) it.next();
                        ParameterDesc paramDesc =
                            operation.getOutputParamByQName(qname);
                        if (paramDesc == null) {
                            // Doesn't match a paramter, so use this for the return
                            findReturnParam = false;
                            result = outParams.remove(qname);
                        }
                    }
                }

                // If we were looking for a particular QName for the return and
                // still didn't find it, throw an exception
                if (findReturnParam) {
                    String returnParamName = returnParamQName.toString();
                    throw new AxisFault(Messages.getMessage("noReturnParam",
                                                            returnParamName));
                }
            }
        } else {
            // This is a SOAPBodyElement, try to treat it like a return value
            try {
                result = bodyEl.getValueAsType(getReturnType());
            } catch (Exception e) {
                // just return the SOAPElement
                result = bodyEl;
            }
View Full Code Here

                reqMsg = msgContext.getRequestMessage();

                if (reqMsg != null) {
                    reqEnv = reqMsg.getSOAPEnvelope();

                    SOAPBodyElement body = reqEnv.getFirstBody();

                    // Does this make any sense to anyone?  If not, we should remove it.
                    // --Glen 03/16/02
                    //if ( body.getPrefix() == null )       body.setPrefix( "m" );
                    if ( body.getNamespaceURI() == null ) {
                        throw new AxisFault("Call.invoke",
                                            Messages.getMessage("cantInvoke00", body.getName()),
                                            null, null);
                    } else {
                        msgContext.setTargetService(body.getNamespaceURI());
                    }
                }
            }

            SOAPService svc = msgContext.getService();
View Full Code Here

         */
        resMsg.setMessageType(Message.RESPONSE);

        SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();

        SOAPBodyElement respBody = resEnv.getFirstBody();
        if (respBody instanceof SOAPFault) {
            if(returnJavaType == null || returnJavaType != javax.xml.soap.SOAPMessage.class)
                throw ((SOAPFault)respBody).getFault();
        }
    }
View Full Code Here

        Method   method = null ;
        Document doc = null ;
       
        if (bodyOnlyService) {
            // dig out just the body, and pass it with the MessageContext
            SOAPBodyElement reqBody = reqEnv.getFirstBody();
           
            doc = reqBody.getAsDOM().getOwnerDocument();

            /* If no methodName was specified during deployment then get it */
            /* from the root of the Body element                            */
            /* Hmmm, should we do this????                                  */
            /****************************************************************/
            if ( methodName == null || methodName.equals("") ) {
                Element root = doc.getDocumentElement();
                if ( root != null ) methodName = root.getLocalName();
            }

            // Try the the simplest case first - just Document as the param
            /////////////////////////////////////////////////////////////////
            argClasses = new Class[1];
            argObjects = new Object[1];
            argClasses[0] = msgContext.getClassLoader().loadClass("org.w3c.dom.Document");
            argObjects[0] = doc ;

            try {
              method = jc.getJavaClass().getMethod( methodName, argClasses );
            }
            catch( NoSuchMethodException exp ) {
              // Ok, no match - so now add MessageContext as the first param
              // and try it again
              ///////////////////////////////////////////////////////////////
              argClasses = new Class[2];
              argObjects = new Object[2];
              argClasses[0] = msgContext.getClassLoader().loadClass("org.apache.axis.MessageContext");
              argClasses[1] = msgContext.getClassLoader().loadClass("org.w3c.dom.Document");
              argObjects[0] = msgContext ;
              argObjects[1] = doc ;
              method = jc.getJavaClass().getMethod( methodName, argClasses );
            }

        } else {
            // pass *just* the MessageContext (maybe don't even parse!!!)
            argClasses = new Class[1];
            argObjects = new Object[1];
            argClasses[0] = msgContext.getClassLoader().loadClass("org.apache.axis.MessageContext");
            argObjects[0] = msgContext ;
            method = jc.getJavaClass().getMethod( methodName, argClasses );
        }
       
       
        // !!! WANT TO MAKE THIS SAX-CAPABLE AS WELL.  Some people will
        //     want DOM, but our examples should mostly lean towards the
        //     SAX side of things....
       
        Document retDoc = (Document) method.invoke( obj, argObjects );
       
        if ( retDoc != null ) {
            SOAPBodyElement el = new SOAPBodyElement(retDoc.getDocumentElement());
            resEnv.addBodyElement(el);
        }
    }
View Full Code Here

               .setServiceDescription(new ServiceDescription("Admin", false));
           
            input.close();
            SOAPEnvelope envelope =
                                   (SOAPEnvelope) outMsg.getAsSOAPEnvelope();
            SOAPBodyElement body = envelope.getFirstBody();
            StringWriter writer = new StringWriter();
            client.addOption(AxisEngine.PROP_XML_DECL, new Boolean(false));
            SerializationContext ctx = new SerializationContext(writer,
                                                  client.getMessageContext());
            ctx.setPretty(true);
            body.output(ctx);
            sb.append(writer.toString());
            sb.append('\n');
        }
       
        return sb.toString();
View Full Code Here

            return null;
          }
        }

        resEnv = (SOAPEnvelope)resMsg.getSOAPEnvelope();
        SOAPBodyElement bodyEl = resEnv.getFirstBody();
        if (bodyEl instanceof RPCElement) {
            try {
                resArgs = ((RPCElement) bodyEl).getParams();
            } catch (Exception e) {
                log.error(Messages.getMessage("exception00"), e);
                throw AxisFault.makeFault(e);
            }

            if (resArgs != null && resArgs.size() > 0) {

                // If there is no return, then we start at index 0 to create the outParams Map.
                // If there IS a return, then we start with 1.
                int outParamStart = 0;

                // If we have resArgs and the returnType is specified, then the first
                // resArgs is the return.  If we have resArgs and neither returnType
                // nor paramXMLTypes are specified, then we assume that the caller is
                // following the non-JAX-RPC AXIS shortcut of not having to specify
                // the return, in which case we again assume the first resArgs is
                // the return.
                // NOTE 1:  the non-JAX-RPC AXIS shortcut allows a potential error
                // to escape notice.  If the caller IS NOT following the non-JAX-RPC
                // shortcut but instead intentionally leaves returnType and params
                // null (ie., a method that takes no parameters and returns nothing)
                // then, if we DO receive something it should be an error, but this
                // code passes it through.  The ideal solution here is to require
                // this caller to set the returnType to void, but there's no void
                // type in XML.
                // NOTE 2:  we should probably verify that the resArgs element
                // types match the expected returnType and paramXMLTypes, but I'm not
                // sure how to do that since the resArgs value is a Java Object
                // and the returnType and paramXMLTypes are QNames.

                // GD 03/15/02 : We're now checking for invalid metadata
                // config at the top of this method, so don't need to do it
                // here.  Check for void return, though.
                boolean findReturnParam = false;
                if (!XMLType.AXIS_VOID.equals(returnType)) {
                    if (operation.getReturnQName() == null) {
                        // Assume the first param is the return
                        RPCParam param = (RPCParam)resArgs.get(0);
                        result = param.getValue();
                        outParamStart = 1;
                    } else {
                        // If the QName of the return value was given to us, look
                        // through the result arguments to find the right name
                        findReturnParam = true;
                    }
                }

                for (int i = outParamStart; i < resArgs.size(); i++) {
                    RPCParam param = (RPCParam) resArgs.get(i);

                    Class javaType = getJavaTypeForQName(param.getQName());
                    Object value = param.getValue();

                    // Convert type if needed
                    if (javaType != null && value != null &&
                           !javaType.isAssignableFrom(value.getClass())) {
                        value = JavaUtils.convert(value, javaType);
                    }

                    // Check if this parameter is our return
                    // otherwise just add it to our outputs
                    if (findReturnParam &&
                          operation.getReturnQName().equals(param.getQName())) {
                        // found it!
                        result = value;
                        findReturnParam = false;
                    } else {
                        outParams.put(param.getQName(), value);
                        outParamsList.add(value);
                    }
                }
            }
        } else {
            // This is a SOAPBodyElement, try to treat it like a return value
            try {
                result = bodyEl.getValueAsType(returnType);
            } catch (Exception e) {
                // just return the SOAPElement
                result = bodyEl;
            }
View Full Code Here

TOP

Related Classes of org.apache.axis.message.SOAPBodyElement

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.