Posting Credentials using LWP To WebMethods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mdh

    Posting Credentials using LWP To WebMethods

    I have an application written for mod_perl and Apache that needs to be
    able to send some XML queries to a WebMethods server for access to
    corporate systems. I have been attempting to use LWP to POST my XML
    query to the target WebMethods server and find I only get 401s
    (authorization errors) from the WebMethods server when it is
    configured for username/password authentication. If credentials are
    turned off on the WM server, I can get my expected XML replies.
    Here's what I've tried:

    1) WORKS: my basic PERL code hitting a local Apache server
    (1.3.29 or 2.0.48) simulating WebMethods by sending
    canned XML replies and requiring a username/password
    credential in a known realm of "webMethods "
    2) WORKS: the same PERL code hitting a real WebMethods
    server that has authentication turned off
    3) WORKS: using a browser to surf to a second real WebMethods
    server with authentication turned on that requires:
    username: myuser
    password: mypasswd
    realm: webMethods
    4) BROKE: the same PERL code hitting that second WM server
    using the credentials in bullet #3 using base64 encoding
    of username and password

    When the admin of the WebMethods server looks at his logs, he sees the
    hit coming from LWP trying to perform the post as default/default (or
    no authentication) . Seems to indicate LWP doesn't recognize something
    unique coming back from WebMethods when it wants credentials to be
    supplied for a realm. Obvious things I HAVE confirmed are:

    QUESTIONS:

    1) has anyone else ever gotten a PERL script to post XML to a
    WebMethods server with credentials using LWP?
    2) is there a special agent string I can use that WebMethods
    might like?
    3) WebMethods provides a client.jar class library to write
    Java scripts to access the server -- am I just going to
    have to invoke a Java wrapper script and solve the problem
    with more indirection (smile)?

    Any insight would be greatly appreciated. THANKS


    stratfan@mindsp ring.com

    =========CODE SNIPPET BELOW========== ====

    # IMPORTANT - documentation for the LWP::UserAgent: :credentials
    # function is slightly out of date regarding the net
    # location parameter (the first one) - it must
    # be of the form "host.domain.co m:port" even if you
    # are using the default default 80 for http or 443
    # for https

    my $WEBMETHODSUSER ID = 'myuser';
    my $WEBMETHODSPASS WORD = 'mypasswd';
    $WEBMETHODSUSER ID = MIME::Base64::e ncode($WEBMETHO DSUSERID);
    $WEBMETHODSPASS WORD = MIME::Base64::e ncode($WEBMETHO DSPASSWORD);
    $WEBMETHODSUSER ID =~ tr/\n//d; # strip trailing LF (???)
    $WEBMETHODSPASS WORD =~ tr/\n//d;

    my $WEBMETHODSREAL M;
    my $WEBMETHODSNETL OCATION;
    my $WEBMETHODS_GET ACCOUNTINFO_URL ;

    $WEBMETHODS_GET ACCOUNTINFO_URL =
    "http://192.168.29.41:5 555/invoke/myServices.Tran saction:Custome rLookup";
    $WEBMETHODSNETL OCATION = "192.168.29.41: 5555";
    $WEBMETHODSREAL M = "webMethods "; # has to match Realm name
    # displayed in browser prompt


    my $ua = LWP::UserAgent->new();
    $ua->credentials($W EBMETHODSNETLOC ATION, $WEBMETHODSREAL M,
    $WEBMETHODSUSER ID, $WEBMETHODSPASS WORD);
    $ua->agent('Mozil la/5.0');
    my $req = HTTP::Request->new(POST => $WEBMETHODS_GET ACCOUNTINFO_URL );
    $req->content_type(' text/xml');
    $req->content($webme thodsQuery);
    my $response = $ua->request($req );

    #----------------------------------------------------------
    # upon return, we either have:
    # a) an error indicated by a response code other than 200
    # b) a reply from WebMethods with <Response>xxx </Response>
    # indicating success
    # c) a reply from WebMethods with no <Response> but with
    # <FailureReasonI D> and other error tags
    #-----------------------------------------------------------
    if ($response->code() != 200) {
    %result = ( errorcode => $response->code(),
    errormsg => 'ERROR: unexpected reply from WebMethods
    in GetAccountInfo' );
    }
    else {
    # if we got a reply from WebMethods, it will either have
    <Response>xxx </Response> data
    # or the following XML values below the <MyAppMessage > level:
    # <FailureReasonI D>ERROR OCCURRED</FailureReasonID >
    # <ErrorNumber>10 0</ErrorNumber>
    # <ErrorMessage>T imeout</ErrorMessage>
    my $entireXMLreply = $response->content(); # get the whole
    convoluted XML structure
Working...