4 Replies Latest reply: Jul 9, 2013 9:35 PM by user10070648 RSS

    java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement

    user10070648

      Hi I'm getting cast error.

       

          org.apache.axis.client.Call _call = createCall();
          _call.setOperation(_operations[2]);
          _call.setUseSOAPAction(true);
          _call.setSOAPActionURI("urn:ReconReport");
          _call.setEncodingStyle(null);
          _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
          _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
          _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
         

      _call.setOperationName(new javax.xml.namespace.QName("http://paymentGateway.celcom.com", "ReconReport"));

       

      SOAPEnvelope env = new SOAPEnvelope(_call.getMessageContext().getSOAPConstants(),_call.getMessageContext().getSchemaVersion());

      java.lang.Object[] pr = new java.lang.Object[] {login, pass, filename, desc, null};

          env.addBodyElement((SOAPBodyElement) pr[0]);
         env.addBodyElement((SOAPBodyElement) pr[1]);
         env.addBodyElement((SOAPBodyElement) pr[2]);
         env.addBodyElement((SOAPBodyElement) pr[3]);

       

         

       

      Im getting the exception at line


      env.addBodyElement((SOAPBodyElement) pr[0]);



      Exception is


      Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement





      In fact,  im doing some implementation of  invok(). Please any advice ?


      Regards

        • 1. Re: java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement
          aksarben

          Well, the error message is pretty clear: A String and a SOAPBodyElement aren't interchangeable. Are you saying you don't understand what a  ClassCastException is?

          • 2. Re: java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement
            user10070648

            Actually, i know what is the classCastEcecption. but I want to know why here is getting.

             

             

            Please see the invoke() method in org.apache.axis.client, it is also same thing doing

             

             

               public Object invoke(Object[] params) throws java.rmi.RemoteException {

                    long t0=0, t1=0;

                    if( tlog.isDebugEnabled() ) {

                        t0=System.currentTimeMillis();

                    }

                    /* First see if we're dealing with Messaging instead of RPC.        */

                    /* If ALL of the params are SOAPBodyElements then we're doing       */

                    /* Messaging, otherwise just fall through to normal RPC processing. */

                    /********************************************************************/

                    SOAPEnvelope  env = null ;

                    int i ;

             

                    for ( i = 0 ; params != null && i < params.length ; i++ )

                        if ( !(params[i] instanceof SOAPBodyElement) ) break ;

             

                    if ( params != null && params.length > 0 && i == params.length ) {

                        /* ok, we're doing Messaging, so build up the message */

                        /******************************************************/

                        isMsg = true ;

                        env = new SOAPEnvelope(msgContext.getSOAPConstants(),

                                               msgContext.getSchemaVersion());

             

                        for (i = 0; i < params.length; i++) {

                            env.addBodyElement((SOAPBodyElement) params[i]);

                        }

             

                        Message msg = new Message( env );

                        setRequestMessage(msg);

             

                        invoke();

             

                        msg = msgContext.getResponseMessage();

                        if (msg == null) {

                          if (msgContext.isPropertyTrue(FAULT_ON_NO_RESPONSE, false)) {

                            throw new AxisFault(Messages.getMessage("nullResponse00"));

                          } else {

                            return null;

                          }

                        }

             

                        env = msg.getSOAPEnvelope();

                        return( env.getBodyElements() );

                    }

             

             

                    if ( operationName == null ) {

                        throw new AxisFault( Messages.getMessage("noOperation00") );

                    }

                    try {

                        Object res=this.invoke(operationName.getNamespaceURI(),

                                operationName.getLocalPart(), params);

                        if( tlog.isDebugEnabled() ) {

                            t1=System.currentTimeMillis();

                            tlog.debug("axis.Call.invoke: " + (t1-t0)  + " " + operationName);

                        }

                        return res;

                    }

                    catch( AxisFault af) {

                        if(af.detail != null && af.detail instanceof RemoteException) {

                            throw ((RemoteException)af.detail);

                        }

                        throw af;

                    }

                    catch( Exception exp ) {

                        entLog.debug(Messages.getMessage("toAxisFault00"), exp);

                        throw AxisFault.makeFault(exp);

                    }

                }

             

             

             

            I think you understand my problem

             

            Thanks

            • 3. Re: java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement
              jtahlborn

              No, that code is not doing the same thing.  That code is taking an array of Objects, and testing to see if they are instances of SOAPBodyElement, and, if they are, casting them to SOAPBodyElement.  Your code, however, is taking String instances and trying to cast them to SOAPBodyElements, which is never going to work.

              • 4. Re: java.lang.String cannot be cast to org.apache.axis.message.SOAPBodyElement
                user10070648

                So, I follow up the same as in invoke(--) method but still same error,

                 

                 

                SOAPEnvelope env = new SOAPEnvelope(_call.getMessageContext().getSOAPConstants(),_call.getMessageContext().getSchemaVersion());

                 

                java.lang.Object[] pr = new java.lang.Object[] {login, pass, filename, desc, null};

                int i ;

                 

                 

                 

                    for ( i = 0 ; params != null && i < params.length ; i++ )

                 

                        if ( !(params[i] instanceof SOAPBodyElement) ) break ;

                 

                 

                 

                    if ( params != null && params.length > 0 && i == params.length ) {

                 

                        env = new SOAPEnvelope(msgContext.getSOAPConstants(),

                 

                                               msgContext.getSchemaVersion());

                 

                 

                 

                        for (i = 0; i < params.length; i++) {

                 

                            env.addBodyElement((SOAPBodyElement) params[i]);

                 

                        }

                 

                 

                 

                        Message msg = new Message( env );

                 

                        setRequestMessage(msg);

                 

                 

                 

                However, it's working when calling invoke(Object[] params) as bellow

                 

                java.lang.Object _resp = _call.invoke(new java.lang.Object[] {login, pass, filename, desc, source});

                 

                 

                 

                So, let me know that why it's different behaviour ?

                 

                Regards