Problem in getting attributes from webservice to servlet when d return type String[]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sundhas
    New Member
    • Dec 2009
    • 13

    Problem in getting attributes from webservice to servlet when d return type String[]

    I made a Webservice Operation whose return type is STRING [] Following is the code

    Code:
    @WebMethod(operationName = "authorize") public String [] authorize(@WebParam(name = "Username") String Username) 
    { 
      CAuthorization CA = new CAuthorization(); 
      String [] Result= null; 
      try {
        Result = CA.CheckAuthorization(Username); 
      } catch (SQLException ex) {
        Logger.getLogger(WS_Authentication.class.getName()).log(Level.SEVERE, null, ex); 
      }
      return Result;
    }
    And then i made a Servlet The code of the servlet thing is :
    Code:
    try { // Call Web Service Operation
      java.lang.String result = null;
      result =  port.authorize(Username);
      out.println("Result = "+result);
    } catch (Exception ex) {
      // TODO handle custom exceptions here
    }
    Problem is in my WEbservice Code in RETURN STATEMENT i have attributes of any table and i want to take these attributes to servlet so that i can see them on my front end but what im getting here is the only the LAST ATTRIBUTE

    I WANT TO HAVE ALL THE ATTRIBUTES HERE ; so that i can print them in my front end

    HELP!
    Last edited by Frinavale; Dec 9 '09, 08:54 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    The authorize-method interface is defined to pass an array of strings (all attributes) back, but you are only assigning a single String (one attribute) for the return value.
    "... public String [] authorize(..." --> "..String result = port.authorize( ..."

    Solution:
    "..String[] resultArray = port.authorize( ..."

    Please be so kind and don't shout in your answer, my ears are still ringing and my eyes are tingling. There is a (B)old-button on the top, please use it.

    Comment

    • Sundhas
      New Member
      • Dec 2009
      • 13

      #3
      Hey thanks for the reply
      i tried this too what u sugested already but actually it doen't let me it says " That Result is STRING [] and port.authorize (... is SIMPLE string...

      any other way to do it in your mind?

      what i did i converted STRING [] into string separated with ", " in webservices so that i can get the attributes on servlet... But its not the cool way i want to know how do we get STRING [] in servlet..

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        Sorry, I don't know much about webservices, but can you return other objects than simple strings?
        If yes then you can try with Vector() or ArrayList()

        Comment

        • Sundhas
          New Member
          • Dec 2009
          • 13

          #5
          Right! Yes we can use ArrayList ( )
          Thankyou :)

          Comment

          • deepakdsharma
            New Member
            • Mar 2010
            • 2

            #6
            Pls help

            Hi Sundhas,

            Did u solve the problem.
            Give you give some example how u finally did it?

            Please help!!

            Thnx

            Comment

            • Sundhas
              New Member
              • Dec 2009
              • 13

              #7
              This is the way u can handle Webservice Operation of String Return type

              @WebMethod(oper ationName = "authorize" )
              public String authorize(@WebP aram(name = "Username")
              String Username) {

              CAuthorization CA = new CAuthorization( );
              StringBuffer result = new StringBuffer();
              try {
              if (CA.CheckAuthor ization(Usernam e).length > 0) {
              result.append(C A.CheckAuthoriz ation(Username)[0]);
              for (int i = 1; i < CA.CheckAuthori zation(Username ).length; i++) {
              result.append(" ,");
              result.append(C A.CheckAuthoriz ation(Username)[i]);
              }
              }
              } catch (SQLException ex) {
              Logger.getLogge r(WS_Authentica tion.class.getN ame()).log(Leve l.SEVERE, null, ex);
              }
              //TODO write your implementation code here:
              return result.toString ();
              }

              Comment

              • deepakdsharma
                New Member
                • Mar 2010
                • 2

                #8
                Thanks for reply. Basically i wanted to query database and send the multiple rows to client. Java web service should return multiple rows and columns.
                Last edited by deepakdsharma; Mar 29 '10, 04:59 AM. Reason: adding sentence

                Comment

                • Sundhas
                  New Member
                  • Dec 2009
                  • 13

                  #9
                  Yes.. Previously i was trying to do so but somehow wasnt able to.. So i figured this out.
                  Sorry can't help more

                  Regards
                  Sundhas

                  Comment

                  Working...