Help needed regarding RPC::XML return value

Discussion in 'Perl Misc' started by Darcy, Nov 26, 2007.

  1. Darcy

    Darcy Guest

    I am trying to write an XML-RPC server method in perl using RPC::XML,
    and I am having a rather perplexing problem when I attempt to return a
    data structure to the caller (a Java app). I am told that the caller
    is expecting an array of structs as the result.

    I have tried many things, but have ended up with the same problem. as
    an example, and as an attempt to simplify things, this is what my
    method is returning:

    return [({'SELL_LINE_NUMBER' => '1', 'ERROR_CODE' => "0",
    'MESSAGE' => "test", 'CURRENT_TOTAL' => "1"})];

    This is the error that the Java app is generating when it receives the
    response:

    ERROR 26 Nov 2007 16:56:50
    (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    java.lang.ClassCastException: java.lang.Integer


    I have even tried this code snippet:

    my @status;
    my $record;
    $record->{SELL_LINE_NUMBER} = $parts1;
    $record->{ERROR_CODE} = "0";
    $record->{MESSAGE} = "test";
    $record->{CURRENT_TOTAL} = "1";
    push(@status,$record);
    return \@status;

    with the same error being generated. I am at my wit's end trying to
    figure out what is going on, and get it working. I also am not having
    much luck finding other discussions of this problem elsewhere on the
    internet.

    I appreciate any and all help that you can supply.

    Darcy
    Darcy, Nov 26, 2007
    #1
    1. Advertising

  2. Darcy

    Ben Morrow Guest

    Quoth Darcy <>:
    > I am trying to write an XML-RPC server method in perl using RPC::XML,
    > and I am having a rather perplexing problem when I attempt to return a
    > data structure to the caller (a Java app). I am told that the caller
    > is expecting an array of structs as the result.
    >
    > I have tried many things, but have ended up with the same problem. as
    > an example, and as an attempt to simplify things, this is what my
    > method is returning:
    >
    > return [({'SELL_LINE_NUMBER' => '1', 'ERROR_CODE' => "0",
    > 'MESSAGE' => "test", 'CURRENT_TOTAL' => "1"})];
    >
    > This is the error that the Java app is generating when it receives the
    > response:
    >
    > ERROR 26 Nov 2007 16:56:50
    > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > java.lang.ClassCastException: java.lang.Integer


    Just a completely random guess: have you tried using numbers instead of
    strings? That is,

    return [{
    SELL_LINE_NUMBER => 1, # note absence of quotes
    ERROR_CODE => 0,
    MESSAGE => 'test',
    CURRENT_TOTAL => 1,
    }];

    Ben
    Ben Morrow, Nov 26, 2007
    #2
    1. Advertising

  3. Darcy

    J. Gleixner Guest

    Darcy wrote:
    [...]
    > ERROR 26 Nov 2007 16:56:50
    > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > java.lang.ClassCastException: java.lang.Integer
    >
    >
    > I have even tried this code snippet:
    >
    > my @status;
    > my $record;
    > $record->{SELL_LINE_NUMBER} = $parts1;
    > $record->{ERROR_CODE} = "0";
    > $record->{MESSAGE} = "test";
    > $record->{CURRENT_TOTAL} = "1";
    > push(@status,$record);
    > return \@status;
    >
    > with the same error being generated. I am at my wit's end trying to
    > figure out what is going on, and get it working. I also am not having
    > much luck finding other discussions of this problem elsewhere on the
    > internet.
    >
    > I appreciate any and all help that you can supply.


    Just a guess..

    Why are you quoting 0 and 1?

    Given that the exception points to an Integer problem, remove
    the quotes so Java will see it as an Integer instead of a string.
    J. Gleixner, Nov 26, 2007
    #3
  4. Darcy

    Darcy Guest

    On Nov 26, 5:22 pm, Ben Morrow <> wrote:
    > Quoth Darcy <>:
    >
    >
    >
    > > I am trying to write an XML-RPC server method in perl using RPC::XML,
    > > and I am having a rather perplexing problem when I attempt to return a
    > > data structure to the caller (a Java app). I am told that the caller
    > > is expecting an array of structs as the result.

    >
    > > I have tried many things, but have ended up with the same problem. as
    > > an example, and as an attempt to simplify things, this is what my
    > > method is returning:

    >
    > > return [({'SELL_LINE_NUMBER' => '1', 'ERROR_CODE' => "0",
    > > 'MESSAGE' => "test", 'CURRENT_TOTAL' => "1"})];

    >
    > > This is the error that the Java app is generating when it receives the
    > > response:

    >
    > > ERROR 26 Nov 2007 16:56:50
    > > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > > java.lang.ClassCastException: java.lang.Integer

    >
    > Just a completely random guess: have you tried using numbers instead of
    > strings? That is,
    >
    > return [{
    > SELL_LINE_NUMBER => 1, # note absence of quotes
    > ERROR_CODE => 0,
    > MESSAGE => 'test',
    > CURRENT_TOTAL => 1,
    > }];
    >
    > Ben


    The reason for quoting the numbers, is because, the specs for the
    return list all four as "string". I did try as straight numbers, but
    got the same error.
    Darcy, Nov 27, 2007
    #4
  5. Darcy

    Todd Wade Guest

    On Nov 26, 7:19 pm, Darcy <> wrote:
    > On Nov 26, 5:22 pm, Ben Morrow <> wrote:
    > > Quoth Darcy <>:

    >
    > > > I am trying to write an XML-RPC server method in perl using RPC::XML,
    > > > and I am having a rather perplexing problem when I attempt to return a
    > > > data structure to the caller (a Java app). I am told that the caller
    > > > is expecting an array of structs as the result.

    <snip/>
    > > > This is the error that the Java app is generating when it receives the
    > > > response:

    >
    > > > ERROR 26 Nov 2007 16:56:50
    > > > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > > > java.lang.ClassCastException: java.lang.Integer

    >
    > > Just a completely random guess: have you tried using numbers instead of
    > > strings? That is,

    >
    > > return [{
    > > SELL_LINE_NUMBER => 1, # note absence of quotes
    > > ERROR_CODE => 0,
    > > MESSAGE => 'test',
    > > CURRENT_TOTAL => 1,
    > > }];

    >
    > The reason for quoting the numbers, is because, the specs for the
    > return list all four as "string". I did try as straight numbers, but
    > got the same error.


    What does the XML that client sending to the server look like? Thats
    what you need to be looking at. For example, you said the spec expects
    strings for each value. Chances are that "quoting" the numbers isn't
    going to suffice RPC::XML's purposes.

    You can coerce a value to a specific type by passing RPC::XML data
    objects instead of scalars:

    return [{
    SELL_LINE_NUMBER => RPC::XML::string->new(1),
    ERROR_CODE => RPC::XML::string->new(0),
    MESSAGE => 'test',
    CURRENT_TOTAL => RPC::XML::string->new(1),
    }];

    This will format the value as a <string> instead of an <int> in the
    XML.

    Regards,

    trwww
    Todd Wade, Nov 27, 2007
    #5
  6. Darcy

    Darcy Guest

    On Nov 26, 10:31 pm, Todd Wade <> wrote:
    > On Nov 26, 7:19 pm, Darcy <> wrote:
    >
    >
    >
    > > On Nov 26, 5:22 pm, Ben Morrow <> wrote:
    > > > Quoth Darcy <>:

    >
    > > > > I am trying to write an XML-RPC server method in perl using RPC::XML,
    > > > > and I am having a rather perplexing problem when I attempt to return a
    > > > > data structure to the caller (a Java app). I am told that the caller
    > > > > is expecting an array of structs as the result.

    > <snip/>
    > > > > This is the error that the Java app is generating when it receives the
    > > > > response:

    >
    > > > > ERROR 26 Nov 2007 16:56:50
    > > > > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > > > > java.lang.ClassCastException: java.lang.Integer

    >
    > > > Just a completely random guess: have you tried using numbers instead of
    > > > strings? That is,

    >
    > > > return [{
    > > > SELL_LINE_NUMBER => 1, # note absence of quotes
    > > > ERROR_CODE => 0,
    > > > MESSAGE => 'test',
    > > > CURRENT_TOTAL => 1,
    > > > }];

    >
    > > The reason for quoting the numbers, is because, the specs for the
    > > return list all four as "string". I did try as straight numbers, but
    > > got the same error.

    >
    > What does the XML that client sending to the server look like? Thats
    > what you need to be looking at. For example, you said the spec expects
    > strings for each value. Chances are that "quoting" the numbers isn't
    > going to suffice RPC::XML's purposes.
    >
    > You can coerce a value to a specific type by passing RPC::XML data
    > objects instead of scalars:
    >
    > return [{
    > SELL_LINE_NUMBER => RPC::XML::string->new(1),
    > ERROR_CODE => RPC::XML::string->new(0),
    > MESSAGE => 'test',
    > CURRENT_TOTAL => RPC::XML::string->new(1),
    > }];
    >
    > This will format the value as a <string> instead of an <int> in the
    > XML.
    >
    > Regards,
    >
    > trwww


    Thanks. I will try that tomorrow. I do not know what the XML that is
    being generated, though, since I currently do not have access to
    that. I could try and "fudge" the request, so I can see the result,
    unless there is a trick in perl where I could save a copy to file as
    well as send to the requestor.
    Darcy, Nov 27, 2007
    #6
  7. Darcy

    Darcy Guest

    On Nov 26, 11:31 pm, Todd Wade <> wrote:
    > On Nov 26, 7:19 pm, Darcy <> wrote:
    >
    >
    >
    > > On Nov 26, 5:22 pm, Ben Morrow <> wrote:
    > > > Quoth Darcy <>:

    >
    > > > > I am trying to write an XML-RPC server method in perl using RPC::XML,
    > > > > and I am having a rather perplexing problem when I attempt to return a
    > > > > data structure to the caller (a Java app). I am told that the caller
    > > > > is expecting an array of structs as the result.

    > <snip/>
    > > > > This is the error that the Java app is generating when it receives the
    > > > > response:

    >
    > > > > ERROR 26 Nov 2007 16:56:50
    > > > > (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
    > > > > java.lang.ClassCastException: java.lang.Integer

    >
    > > > Just a completely random guess: have you tried using numbers instead of
    > > > strings? That is,

    >
    > > > return [{
    > > > SELL_LINE_NUMBER => 1, # note absence of quotes
    > > > ERROR_CODE => 0,
    > > > MESSAGE => 'test',
    > > > CURRENT_TOTAL => 1,
    > > > }];

    >
    > > The reason for quoting the numbers, is because, the specs for the
    > > return list all four as "string". I did try as straight numbers, but
    > > got the same error.

    >
    > What does the XML that client sending to the server look like? Thats
    > what you need to be looking at. For example, you said the spec expects
    > strings for each value. Chances are that "quoting" the numbers isn't
    > going to suffice RPC::XML's purposes.
    >
    > You can coerce a value to a specific type by passing RPC::XML data
    > objects instead of scalars:
    >
    > return [{
    > SELL_LINE_NUMBER => RPC::XML::string->new(1),
    > ERROR_CODE => RPC::XML::string->new(0),
    > MESSAGE => 'test',
    > CURRENT_TOTAL => RPC::XML::string->new(1),
    > }];
    >
    > This will format the value as a <string> instead of an <int> in the
    > XML.
    >
    > Regards,
    >
    > trwww


    Thanks. That worked like a charm. I will remember from now on that I
    need to force those that are to be strings in this manner, or else
    rather cryptic errors could result.

    Darcy
    Darcy, Nov 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. milicic.marko

    Apache XML-RPC help needed

    milicic.marko, Mar 12, 2006, in forum: Java
    Replies:
    0
    Views:
    442
    milicic.marko
    Mar 12, 2006
  2. Pere Montolio

    XML RPC to ONC XDR RPC

    Pere Montolio, Aug 11, 2004, in forum: XML
    Replies:
    0
    Views:
    695
    Pere Montolio
    Aug 11, 2004
  3. Ymtrader
    Replies:
    1
    Views:
    568
    Adam Tauno Williams
    Mar 15, 2011
  4. Shirish Joshi

    Ruby and Sun-RPC or ONC-RPC ?

    Shirish Joshi, Apr 7, 2004, in forum: Ruby
    Replies:
    0
    Views:
    170
    Shirish Joshi
    Apr 7, 2004
  5. Vladimir Konrad

    rpc (not xml-rpc)

    Vladimir Konrad, Sep 2, 2005, in forum: Ruby
    Replies:
    5
    Views:
    123
    Austin Ziegler
    Sep 3, 2005
Loading...

Share This Page