Package org.apache.axis.message

Examples of org.apache.axis.message.RPCElement


                                            ArrayList outs) throws Exception
    {
        String methodName = operation.getName();

        /* Now put the result in the result SOAPEnvelope */
        RPCElement resBody = new RPCElement(methodName + "Response");
        resBody.setPrefix(body.getPrefix());
        resBody.setNamespaceURI(body.getNamespaceURI());
        resBody.setEncodingStyle(msgContext.getEncodingStyle());
        try
        {
            // Return first
            if (operation.getMethod().getReturnType() != Void.TYPE)
            {
                QName returnQName = operation.getReturnQName();
                if (returnQName == null)
                {
                    String nsp = body.getNamespaceURI();
                    if (nsp == null || nsp.length() == 0)
                    {
                        nsp = serviceDesc.getDefaultNamespace();
                    }
                    returnQName = new QName(msgContext.isEncoded() ? "" : nsp, methodName + "Return");
                }

                RPCParam param = new RPCParam(returnQName, objRes);
                param.setParamDesc(operation.getReturnParamDesc());

                if (!operation.isReturnHeader())
                {
                    // For SOAP 1.2 rpc style, add a result
                    if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS
                        && (serviceDesc.getStyle().equals(Style.RPC)))
                    {
                        RPCParam resultParam = new RPCParam(Constants.QNAME_RPC_RESULT, returnQName);
                        resultParam.setXSITypeGeneration(Boolean.FALSE);
                        resBody.addParam(resultParam);
                    }
                    resBody.addParam(param);
                }
                else
                {
                    resEnv.addHeader(new RPCHeaderParam(param));
                }

            }

            // Then any other out params
            if (!outs.isEmpty())
            {
                for (Iterator i = outs.iterator(); i.hasNext();)
                {
                    // We know this has a holder, so just unwrap the value
                    RPCParam param = (RPCParam)i.next();
                    Holder holder = (Holder)param.getObjectValue();
                    Object value = JavaUtils.getHolderValue(holder);
                    ParameterDesc paramDesc = param.getParamDesc();

                    param.setObjectValue(value);
                    if (paramDesc != null && paramDesc.isOutHeader())
                    {
                        resEnv.addHeader(new RPCHeaderParam(param));
                    }
                    else
                    {
                        resBody.addParam(param);
                    }
                }
            }
        }
        catch (Exception e)
View Full Code Here


        bean.setMale(true);
        bean.company = "Majesty's Secret Service";
        bean.setName("James Bond");

        RPCParam arg = new RPCParam("", "struct", bean);
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg });
        msg.addBodyElement(body);
        body.setEncodingStyle(null);

        Writer stringWriter = new StringWriter();
        SerializationContext context = new SerializationContextImpl(stringWriter, msgContext);
        context.setDoMultiRefs(false)// no multirefs
        context.setPretty(false);

        // Create a TypeMapping and register the Bean serializer/deserializer
        TypeMappingRegistry reg = context.getTypeMappingRegistry();
        TypeMapping tm = (TypeMapping) reg.createTypeMapping();
        // The "" namespace is literal (no encoding).
        tm.setSupportedNamespaces(new String[] {Constants.URI_CURRENT_SOAP_ENC});
        reg.register(Constants.URI_CURRENT_SOAP_ENC, tm);

        QName beanQName = new QName("typeNS", "TheBean");
        tm.register(AttributeBean.class,
                    beanQName,
                    new BeanSerializerFactory(AttributeBean.class, beanQName),
                    new BeanDeserializerFactory(AttributeBean.class, beanQName));

        // Serialize the bean in to XML
        msg.output(context);
        // Get the XML as a string
        String msgString = stringWriter.toString();

        log.debug("---");
        log.debug(msgString);
        log.debug("---");

        Message message = new Message(msgString);
        message.setMessageContext(msgContext);
        SOAPEnvelope env = message.getSOAPPart().getAsSOAPEnvelope();
        RPCElement rpcEl = (RPCElement)env.getFirstBody();
        Vector params = rpcEl.getParams();
        assertEquals("Wrong # of params in deserialized message!",
                     1,
                     params.size());

        Object obj = ((RPCParam)params.get(0)).getValue();
View Full Code Here

        MessageContext msgContext = new MessageContext(new AxisServer(new BasicServerConfig()));
        SOAPEnvelope msg = new SOAPEnvelope();

        RPCParam arg = new RPCParam("", "simple", bean);
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg });
        msg.addBodyElement(body);
        body.setEncodingStyle(null);

        StringWriter writer = new StringWriter();
        SerializationContext context = new SerializationContextImpl(writer,
                                                                    msgContext);
        context.setDoMultiRefs(false);

        // Create a TypeMapping and register the Bean serializer/deserializer
        TypeMappingRegistry reg = context.getTypeMappingRegistry();
        TypeMapping tm = (TypeMapping) reg.createTypeMapping();
        // The "" namespace is literal (no encoding).
        tm.setSupportedNamespaces(new String[] {Constants.URI_CURRENT_SOAP_ENC});
        reg.register(Constants.URI_CURRENT_SOAP_ENC, tm);

        QName beanQName = new QName("typeNS", "Bean");
        tm.register(SimpleBean.class,
                    beanQName,
                    new SimpleNonPrimitiveSerializerFactory(SimpleBean.class, beanQName),
                    new SimpleDeserializerFactory(SimpleBean.class, beanQName));

        // Serialize the bean in to XML
        msg.output(context);
        // Get the XML as a string
        String msgString = writer.toString();

        Message message = new Message(msgString);
        message.setMessageContext(msgContext);
        SOAPEnvelope env = message.getSOAPPart().getAsSOAPEnvelope();
        RPCElement rpcEl = (RPCElement)env.getFirstBody();
        Vector params = rpcEl.getParams();
        assertEquals("Wrong # of params in deserialized message!",
                     1,
                     params.size());

        Object obj = ((RPCParam)params.get(0)).getValue();
View Full Code Here

        message.setMessageContext(new MessageContext(server));

        SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPPart().getAsSOAPEnvelope();
        assertNotNull("SOAP envelope should not be null", envelope);

        RPCElement body = (RPCElement) envelope.getFirstBody();
        assertNotNull("SOAP body should not be null", body);

        Vector arglist = body.getParams();
        assertNotNull("arglist", arglist);
        assertTrue("param.size()<=0 {Should be > 0}", arglist.size() > 0);

        RPCParam param = (RPCParam) arglist.get(0);
        assertNotNull("SOAP param should not be null", param);
View Full Code Here

        transport.setRemoteService("testOmittedValue");

        call.setTransport(transport);

        SOAPEnvelope resEnv = call.invoke(message.getSOAPEnvelope());
        RPCElement rpcElem = (RPCElement)resEnv.getFirstBody();
        RPCParam param = (RPCParam)rpcElem.getParams().get(0);
        assertEquals("OK!", param.getValue());
    }
View Full Code Here

       message.setMessageContext(new MessageContext(server));

       SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPPart().getAsSOAPEnvelope();
       assertNotNull("SOAP envelope should not be null", envelope);

       RPCElement body = (RPCElement)envelope.getFirstBody();
       assertNotNull("SOAP body should not be null", body);

       Vector arglist = body.getParams();
       assertNotNull("arglist", arglist);
       assertTrue("param.size()<=0 {Should be > 0}", arglist.size()>0);

       RPCParam param = (RPCParam) arglist.get(0);
       assertNotNull("SOAP param should not be null", param);
View Full Code Here

        if (returnType != null && args != null && args.length != 0
                && operation == null) {
            throw new AxisFault(JavaUtils.getMessage("mustSpecifyParms"));
        }

        RPCElement  body = new RPCElement(namespace, method, args);

        Object ret = invoke( body );

        if (log.isDebugEnabled()) {
            log.debug(JavaUtils.getMessage("exit00",
View Full Code Here

        /* Loop over each entry in the SOAPBody - each one is a different */
        /* RPC call.                                                      */
        /******************************************************************/
        for ( int bNum = 0 ; bNum < bodies.size() ; bNum++ ) {
            RPCElement   body;

            // If this is a regular old SOAPBodyElement, and it's a root,
            // we're probably a non-wrapped doc/lit service.  In this case,
            // we deserialize the element, and create an RPCElement "wrapper"
            // around it which points to the correct method.
            // FIXME : There should be a cleaner way to do this...
            if (!(bodies.get(bNum) instanceof RPCElement)) {
                SOAPBodyElement bodyEl = (SOAPBodyElement)bodies.get(bNum);
                // igors: better check if bodyEl.getID() != null
                // to make sure this loop does not step on SOAP-ENC objects
                // that follow the parameters! FIXME?
                if (bodyEl.isRoot() && operation != null) {
                    ParameterDesc param = operation.getParameter(bNum);
                    // at least do not step on non-existent parameters!
                    if(param != null) {
                        Object val = bodyEl.getValueAsType(param.getTypeQName());
                        body = new RPCElement("",
                                              operation.getName(),
                                              new Object [] { val });
                    }
                    else continue;
                } else {
                    continue;
                }
            } else {
                body = (RPCElement) bodies.get( bNum );
            }

            String methodName = body.getMethodName();
            Vector args = body.getParams();
            int numArgs = args.size();

            // This may have changed, so get it again...
            // FIXME (there should be a cleaner way to do this)
            operation = msgContext.getOperation();

            if (operation == null) {
                QName qname = new QName(body.getNamespaceURI(),
                                        body.getName());
                operation = serviceDesc.getOperationByElementQName(qname);
            }

            if (operation == null) {
                throw new AxisFault(JavaUtils.getMessage("noSuchOperation",
                                                         methodName));
            }

            // Create the array we'll use to hold the actual parameter
            // values.  We know how big to make it from the metadata.
            Object[]     argValues  =  new Object [operation.getNumParams()];

            // A place to keep track of the out params (INOUTs and OUTs)
            ArrayList outs = new ArrayList();

            // Put the values contained in the RPCParams into an array
            // suitable for passing to java.lang.reflect.Method.invoke()
            // Make sure we respect parameter ordering if we know about it
            // from metadata, and handle whatever conversions are necessary
            // (values -> Holders, etc)
            if ( args != null && args.size() > 0 ) {
                for ( int i = 0 ; i < numArgs ; i++ ) {
                    RPCParam rpcParam = (RPCParam)args.get(i);
                    Object value = rpcParam.getValue();
                    ParameterDesc paramDesc = rpcParam.getParamDesc();
                    if (paramDesc != null && paramDesc.getJavaType() != null) {
                        value = JavaUtils.convert(value,
                                                  paramDesc.getJavaType());
                        rpcParam.setValue(value);
                        if (paramDesc.getMode() == ParameterDesc.INOUT)
                            outs.add(rpcParam);
                    }
                    if (paramDesc == null || paramDesc.getOrder() == -1) {
                        argValues[i= value;
                    } else {
                        argValues[paramDesc.getOrder()] = value;
                    }

                    if (log.isDebugEnabled()) {
                        log.debug("  " + JavaUtils.getMessage("value00",
                            "" + argValues[i]) );
                    }
                }
            }

            // Check if we can find a Method by this name
            // FIXME : Shouldn't this type of thing have already occurred?
            checkMethodName(msgContext, allowedMethods, operation.getName());

            // Now create any out holders we need to pass in
            if (numArgs < argValues.length) {
                ArrayList outParams = operation.getOutParams();
                for (int i = 0; i < outParams.size(); i++) {
                    ParameterDesc param = (ParameterDesc)outParams.get(i);
                    Class holderClass = param.getJavaType();
                    if (Holder.class.isAssignableFrom(holderClass)) {
                        argValues[numArgs + i] = holderClass.newInstance();
                        // Store an RPCParam in the outs collection so we
                        // have an easy and consistent way to write these
                        // back to the client below
                        outs.add(new RPCParam(param.getQName(),
                                              argValues[numArgs + i]));
                    } else {
                        // !!! Throw a fault here?
                    }
                }
            }

            // OK!  Now we can invoke the method
            Object objRes = operation.getMethod().invoke(obj, argValues);

            /* Now put the result in the result SOAPEnvelope */
            /*************************************************/
            RPCElement resBody = new RPCElement(methodName + "Response");
            resBody.setPrefix( body.getPrefix() );
            resBody.setNamespaceURI( body.getNamespaceURI() );
            resBody.setEncodingStyle(msgContext.getEncodingStyle());

            // Return first
            if ( operation.getMethod().getReturnType() != Void.TYPE ) {
                QName returnQName = operation.getReturnQName();
                if (returnQName == null) {
                    returnQName = new QName("", methodName + "Return");
                }
                RPCParam param = new RPCParam(returnQName, objRes);
                resBody.addParam(param);
            }

            // Then any other out params
            if (!outs.isEmpty()) {
                for (Iterator i = outs.iterator(); i.hasNext();) {
                    // We know this has a holder, so just unwrap the value
                    RPCParam param = (RPCParam) i.next();
                    Holder holder = (Holder)param.getValue();
                    param.setValue(JavaUtils.getHolderValue(holder));
                    resBody.addParam(param);
                }
            }

            resEnv.addBodyElement(resBody);
        }
View Full Code Here

    protected void checkRoundTrip(String xml1) throws Exception {
        Message message = new Message(xml1);
        message.setMessageContext(new MessageContext(server));

        SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPPart().getAsSOAPEnvelope();
        RPCElement body = (RPCElement) envelope.getFirstBody();
        Vector arglist = body.getParams();
        Object ret1 = ((RPCParam) arglist.get(0)).getValue();

        String xml2 = message.getSOAPPart().getAsString();
        Message message2 = new Message(xml2);
        message2.setMessageContext(new MessageContext(server));

        SOAPEnvelope envelope2 = (SOAPEnvelope) message2.getSOAPPart().getAsSOAPEnvelope();
        RPCElement body2 = (RPCElement) envelope2.getFirstBody();
        Vector arglist2 = body2.getParams();
        Object ret2 = ((RPCParam) arglist2.get(0)).getValue();

        if (!equals(ret1, ret2)) {
            assertEquals("The result is not what is expected.", ret1, ret2);
        }
View Full Code Here

        Data data = new Data();
        data.stringMember = "String member";
        data.floatMember = new Float("4.54");
       
        RPCParam arg2 = new RPCParam("", "struct", data);
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg1, arg2 });
        msg.addBodyElement(body);
       
        Writer stringWriter = new StringWriter();
        SerializationContext context = new SerializationContextImpl(stringWriter, msgContext);
        context.setDoMultiRefs(multiref);
       
        // Create a TypeMapping and register the specialized Type Mapping
        TypeMappingRegistry reg = context.getTypeMappingRegistry();
        TypeMapping tm = (TypeMapping) reg.createTypeMapping();
        tm.setSupportedNamespaces(new String[] {Constants.URI_CURRENT_SOAP_ENC});
        reg.register(Constants.URI_CURRENT_SOAP_ENC, tm);

        QName dataQName = new QName("typeNS", "Data");
        tm.register(Data.class, dataQName, new DataSerFactory(), new DataDeserFactory());

        msg.output(context);
       
        String msgString = stringWriter.toString();
       
        log.debug("---");
        log.debug(msgString);
        log.debug("---");
       
        StringReader reader = new StringReader(msgString);
       
        DeserializationContext dser = new DeserializationContextImpl(
            new InputSource(reader), msgContext, org.apache.axis.Message.REQUEST);
        dser.parse();
       
        SOAPEnvelope env = dser.getEnvelope();
        RPCElement rpcElem = (RPCElement)env.getFirstBody();
        RPCParam struct = rpcElem.getParam("struct");
        assertNotNull("No <struct> param", struct);
       
        Data val = (Data)struct.getValue();
        assertNotNull("No value for struct param", val);
       
View Full Code Here

TOP

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

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.