Package org.apache.axis.message

Examples of org.apache.axis.message.RPCElement


   public void invoke(MessageContext ctx) throws AxisFault {
      
       //XMLDispatcherClient xd = this.getXMLDispatcherClient();
       ClassInfoCache classInfoCache = new ClassInfoCache(this.xd);
      
      RPCElement body = null;
     
      // initialize some variables
      SOAPEnvelope reqEnv = ctx.getRequestMessage().getSOAPEnvelope();
      ServiceDesc serviceDesc = ctx.getService().getServiceDescription();

      // find the first 'root' body element, which is the RPC call
      Vector bodies = reqEnv.getBodyElements();
      for (int i = 0; body == null && i < bodies.size(); i++) {
         if (bodies.get(i) instanceof RPCElement) {
            body = (RPCElement) bodies.get(i);
         }
      }

      // if we didn't find anything, throw an exception
      if (body == null) {
         throw new AxisFault("No RPCElement found in SOAP message");
      }

      //extract the xmlstruct message
      String rqst = null;
      String instanceId = null;
      String sessionData = null;
      String webServiceNs = body.getNamespaceURI();
      for (Iterator iter = body.getChildElements(); iter.hasNext();) {
         MessageElement msg = (MessageElement) iter.next();
         // TODO what if xmlns is null?
         if (msg.getLocalName().equals("instanceId") && msg.getNamespaceURI().equals(webServiceNs)) {
            // TODO what if no child elements
            instanceId = ((Text) msg.getChildElements().next()).getData();
            continue;
         }
         else if (msg.getName().equals("sessionData") && msg.getNamespaceURI().equals(webServiceNs)) {
            // TODO what if no child elements
            sessionData = ((Text) msg.getChildElements().next()).getData();
            continue;
         }
         else {
            if (rqst == null) {
               rqst = msg.toString();
            }
            else {
               //TODO error because more than one "struct" element
               throw new AxisFault("error because more than one struct element");
            }
         }
      }

      // looks ok, get name of invoked operation on service
      String className = body.getMethodName().split("-")[0];
      String methodName = body.getMethodName().split("-")[1];

      String rply = null;
      short verb;
      try {
          verb = classInfoCache.getVerb(className, methodName);
         // if instanceId != null -> instanceMethod
         // else need to call getClassInfo to distinguish between classMethod and newInstanceMethod
         // EnvelopeConstants.verbDispatchClassMethodXML
         // classInfoRply = dispatchClassMethodXML(className,"getClassInfo",null,null);
        
           switch(verb) {
             case EnvelopeConstants.verbDispatchInstanceMethodXML:
                 rply = this.xd.dispatchInstanceMethodXML(className, methodName, instanceId, rqst);
                 break;
             case EnvelopeConstants.verbDispatchNewInstanceMethodXML:
                 rply = this.xd.dispatchNewInstanceMethodXML(className, methodName, rqst);
                 break;
             case EnvelopeConstants.verbDispatchClassMethodXML:
                 rply = this.xd.dispatchClassMethodXML(className, methodName, rqst);
                 break;
           }
      }
      catch (XMLDispatcherAppException e) {
         throw new AxisFault(e.getMessage());
      }
      catch (XMLDispatcherUserException e) {
         throw new AxisFault(e.getMessage());
      }
      catch (XMLDispatcherSystemException e) {
         throw new AxisFault(e.getMessage());
      }
      catch (XMLDispatcherCommException e) {
         throw new AxisFault(e.getMessage());
      }

      // set up a SOAP envelope with appropriate SOAP and schema versions
      SOAPEnvelope respEnv = new SOAPEnvelope();
      respEnv.setSoapConstants(ctx.getSOAPConstants());
      respEnv.setSchemaVersion(ctx.getSchemaVersion());

      // create the response message and put it into the message context
      ctx.setResponseMessage(new Message(respEnv));

      try {

         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(true);
         dbf.setIgnoringElementContentWhitespace(false);
         DocumentBuilder db = dbf.newDocumentBuilder();

         //TODO not beautiful..
         String newRply = "<" + body.getMethodName() + "-Response xmlns=\"" + webServiceNs + "\">";
         switch (verb) {
           case EnvelopeConstants.verbDispatchNewInstanceMethodXML:
               newRply += "<instanceId>" + rply + "</instanceId>";
               break;
           default:
               newRply += rply;
         }

         newRply += "<sessionData xmlns=\"" + webServiceNs + "\">" + sessionData + "</sessionData>";

         newRply += "</" + body.getMethodName() + "-Response>";

         BufferedReader br = new BufferedReader(new StringReader(newRply));

         InputSource inputSource = new InputSource(br);
         Document respBodyDoc = db.parse(inputSource);
View Full Code Here


        message.setMessageContext(context);

        SOAPEnvelope envelope = message.getSOAPEnvelope();
        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

       }

       SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope();
       assertNotNull("SOAP envelope should not be null"+ postfix, envelope);

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

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

       RPCParam param = (RPCParam) arglist.get(0);
       assertNotNull("SOAP param should not be null" + postfix, param);
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.setSupportedEncodings(new String[] {Constants.URI_DEFAULT_SOAP_ENC});
        reg.register(Constants.URI_DEFAULT_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

     */
    public void testRPCElement()
    {
        try {
            SOAPEnvelope env = new SOAPEnvelope();
            RPCElement method = new RPCElement("ns",
                                               "method",
                                               new Object [] { "argument" });
            env.addBodyElement(method);
            env.toString();
        } catch (Exception e) {
View Full Code Here

       
        SOAPEnvelope msg = new SOAPEnvelope();
        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", document.getFirstChild());
        arg1.setXSITypeGeneration(Boolean.FALSE);
       
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[] { arg1 });
        msg.addBodyElement(body);
        body.setEncodingStyle(Constants.URI_LITERAL_ENC);
       
        SerializationContext context = new SerializationContextImpl(stringWriter, msgContext);
        msg.output(context);
       
        msgString = stringWriter.toString();
View Full Code Here

       
        SOAPEnvelope msg = new SOAPEnvelope();
        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", document.getFirstChild());
        arg1.setXSITypeGeneration(Boolean.FALSE);
       
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[] { arg1 });
        msg.addBodyElement(body);
        body.setEncodingStyle(Constants.URI_LITERAL_ENC);
       
        SerializationContext context = new SerializationContextImpl(stringWriter, msgContext);
        msg.output(context);
       
        msgString = stringWriter.toString();
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug(Messages.getMessage("bodyElems00", "" + bodies.size()));
                log.debug(Messages.getMessage("bodyIs00", "" + bodies.get(0)));
            }

            RPCElement body = null;
           
            // Find the first "root" body element, which is the RPC call.
            for (int bNum = 0; body == null && bNum < bodies.size(); bNum++) {
                // 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 && bodyEl.getID() == 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 {
                    body = (RPCElement) bodies.get(bNum);
                }
            }

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

            Object[] argValues = new Object[numArgs];
           
            // 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)
            for (int i = 0; i < numArgs; i++) {
                RPCParam rpcParam = (RPCParam) args.get(i);
                Object value = rpcParam.getValue();

                // first check the type on the paramter
                ParameterDesc paramDesc = rpcParam.getParamDesc();

                // if we found some type info try to make sure the value type is
                // correct.  For instance, if we deserialized a xsd:dateTime in
                // to a Calendar and the service takes a Date, we need to convert
                if (paramDesc != null && paramDesc.getJavaType() != null) {

                    // Get the type in the signature (java type or its holder)
                    Class sigType = paramDesc.getJavaType();

                    // Convert the value into the expected type in the signature
                    value = JavaUtils.convert(value,
                            sigType);

                    rpcParam.setValue(value);
                }
                argValues[i] = value;
            }

            Script script = ScriptFactory.getScript();
            Object result = script.run(language, service.getName(), scriptStr, methodName, argValues);

            RPCElement resBody = new RPCElement(methodName + "Response");
            resBody.setPrefix(body.getPrefix());
            resBody.setNamespaceURI(body.getNamespaceURI());
            resBody.setEncodingStyle(msgContext.getEncodingStyle());

            Message resMsg = msgContext.getResponseMessage();
            SOAPEnvelope resEnv;

            // If we didn't have a response message, make sure we set one up
            if (resMsg == null) {
                resEnv = new SOAPEnvelope(msgContext.getSOAPConstants());

                resMsg = new Message(resEnv);
                msgContext.setResponseMessage(resMsg);
            } else {
                resEnv = resMsg.getSOAPEnvelope();
            }

            QName returnQName = operation.getReturnQName();
            if (returnQName == null) {
                returnQName = new QName("", methodName + "Return");
            }

            // For SOAP 1.2, add a result
            if (msgContext.getSOAPConstants() ==
                    SOAPConstants.SOAP12_CONSTANTS) {
                returnQName = Constants.QNAME_RPC_RESULT;
            }

            RPCParam param = new RPCParam(returnQName, result);
            param.setParamDesc(operation.getReturnParamDesc());
            if (!operation.isReturnHeader()) {
                resBody.addParam(param);
            } else {
                resEnv.addHeader(new RPCHeaderParam(param));
            }

            resEnv.addBodyElement(resBody);
View Full Code Here

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

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

        Object ret = invoke( body );

        if (log.isDebugEnabled()) {
            log.debug("Exit: Call::invoke(ns, meth, args)");
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug(Messages.getMessage("bodyElems00", "" + bodies.size()));
            log.debug(Messages.getMessage("bodyIs00", "" + bodies.get(0)));
        }

        RPCElement body = null;

        // Find the first "root" body element, which is the RPC call.
        for (int bNum = 0; body == null && bNum < bodies.size(); bNum++) {
            // 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 && bodyEl.getID() == 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 {
                body = (RPCElement) bodies.get(bNum);
            }
        }

        // special case code for a document style operation with no
        // arguments (which is a strange thing to have, but whatever)
        if (body == null) {
            // throw an error if this isn't a document style service
            if (!(serviceDesc.getStyle().equals(Style.DOCUMENT))) {
                throw new Exception(Messages.getMessage("noBody00"));
            }
           
            // look for a method in the service that has no arguments,
            // use the first one we find.
            ArrayList ops = serviceDesc.getOperations();
            for (Iterator iterator = ops.iterator(); iterator.hasNext();) {
                OperationDesc desc = (OperationDesc) iterator.next();
                if (desc.getNumInParams() == 0) {
                    // found one with no parameters, use it
                    msgContext.setOperation(desc);
                    // create an empty element
                    body = new RPCElement(desc.getName());
                    // stop looking
                    break;
                }
            }
           
            // If we still didn't find anything, report no body error.
            if (body == null) {
                throw new Exception(Messages.getMessage("noBody00"));
            }
        }

        String methodName = body.getMethodName();
        Vector args = null;
        try {
            args = body.getParams();
        } catch (SAXException e) {
            if(e.getException() != null)
                throw e.getException();
            throw e;
        }
        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) {
            SOAPConstants soapConstants = msgContext == null ?
                    SOAPConstants.SOAP11_CONSTANTS :
                    msgContext.getSOAPConstants();
            if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                AxisFault fault =
                        new AxisFault(Constants.FAULT_SOAP12_SENDER,
                                      Messages.getMessage("noSuchOperation",
                                                          methodName),
                                      null,
                                      null);
                fault.addFaultSubCode(Constants.FAULT_SUBCODE_PROC_NOT_PRESENT);
                throw new SAXException(fault);
            } else {
                throw new AxisFault(Messages.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)
        for (int i = 0; i < numArgs; i++) {
            RPCParam rpcParam = (RPCParam) args.get(i);
            Object value = rpcParam.getValue();
           
            // first check the type on the paramter
            ParameterDesc paramDesc = rpcParam.getParamDesc();
           
            // if we found some type info try to make sure the value type is
            // correct.  For instance, if we deserialized a xsd:dateTime in
            // to a Calendar and the service takes a Date, we need to convert
            if (paramDesc != null && paramDesc.getJavaType() != null) {

                // Get the type in the signature (java type or its holder)
                Class sigType = paramDesc.getJavaType();
               
                // Convert the value into the expected type in the signature
                value = JavaUtils.convert(value, sigType);

                rpcParam.setValue(value);
                if (paramDesc.getMode() == ParameterDesc.INOUT) {
                    outs.add(rpcParam);
                }
            }
           
            // Put the value (possibly converted) in the argument array
            // make sure to use the parameter order if we have it
            if (paramDesc == null || paramDesc.getOrder() == -1) {
                argValues[i] = value;
            } else {
                argValues[paramDesc.getOrder()] = value;
            }

            if (log.isDebugEnabled()) {
                log.debug("  " + Messages.getMessage("value00",
                        "" + argValues[i]));
            }
        }
       
        // See if any subclasses want a crack at faulting on a bad operation
        // FIXME : Does this make sense here???
        String allowedMethods = (String) service.getOption("allowedMethods");
        checkMethodName(msgContext, allowedMethods, operation.getName());

        // Now create any out holders we need to pass in
        int count = numArgs;
        for (int i = 0; i < argValues.length; i++) {
           
            // We are interested only in OUT/INOUT
            ParameterDesc param = operation.getParameter(i);
            if(param.getMode() == ParameterDesc.IN)
                continue;

            Class holderClass = param.getJavaType();
            if (holderClass != null &&
                    Holder.class.isAssignableFrom(holderClass)) {
                int index = count;
                // Use the parameter order if specified or just stick them to the end. 
                if (param.getOrder() != -1) {
                    index = param.getOrder();
                } else {
                    count++;
                }
                // If it's already filled, don't muck with it
                if (argValues[index] != null) {
                    continue;
                }
                argValues[index] = 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
                RPCParam p = new RPCParam(param.getQName(),
                        argValues[index]);
                p.setParamDesc(param);
                outs.add(p);
            } else {
                throw new AxisFault(Messages.getMessage("badOutParameter00",
                        "" + param.getQName(),
                        operation.getName()));
            }
        }
       
        // OK!  Now we can invoke the method
        Object objRes = null;
        try {
            objRes = invokeMethod(msgContext,
                                  operation.getMethod(),
                                  obj, argValues);
        } catch (IllegalArgumentException e) {
            String methodSig = operation.getMethod().toString();
            String argClasses = "";
            for (int i = 0; i < argValues.length; i++) {
                if (argValues[i] == null) {
                    argClasses += "null";
                } else {
                    argClasses += argValues[i].getClass().getName();
                }
                if (i + 1 < argValues.length) {
                    argClasses += ",";
                }
            }
            log.info(Messages.getMessage("dispatchIAE00",
                    new String[]{methodSig, argClasses}),
                    e);
            throw new AxisFault(Messages.getMessage("dispatchIAE00",
                    new String[]{methodSig, argClasses}),
                    e);
        }
       
        /* 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.getValue();
                    Object value = JavaUtils.getHolderValue(holder);
                    ParameterDesc paramDesc = param.getParamDesc();

                    param.setValue(value);
                    if (paramDesc != null && paramDesc.isOutHeader()) {
                        resEnv.addHeader(new RPCHeaderParam(param));
                    } else {
                        resBody.addParam(param);
                    }
                }
            }
        } catch (Exception e) {
            throw e;
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.