You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Simson Garfinkel <si...@acm.org> on 2007/11/22 02:09:41 UTC

Basic Authentication with xmlrpc-3.1

Greetings. I've spent about 20 hours trying to get basic  
authentication (username & password) to work with xmlrpc-3.1.  No  
luck. My demo program works with no username & password (if  
authentication on the server is disabled) but fails with a 401 error  
if authentication is enabled.

This has been very frustrating. I've scanned the Internet, Google, and  
this website, but I can't find any successful examples of Basic  
Authentication being used with xmlrpc. (I did find some email messages  
saying it was broken in the 2.0 release.)

Any help that you could give me would be greatly appreciated.  
Honestly, I think that there needs to be example code included in the  
release that shows this...


Here is my test program:

/* From http://wiki.rpath.com/wiki/rPath_Appliance_Platform_Agent:XML-RPC_Java_Client 
  */

import java.net.URL;
import java.util.HashMap;

import org.apache.xmlrpc.client.*;


public class Test4 {
     public static void call(String url, String user, String pass)  
throws Exception {
     }

     public static void main(String[] args) throws Exception {

         XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
         config.setServerURL(new URL("http://example.org/query.cgi"));
         config.setBasicUserName("username");
         config.setBasicPassword("password");
         XmlRpcClient client = new XmlRpcClient();
         client.setConfig(config);

         Object[] ag = new Object[1];
         ag[0] = "0093J1AK132486";

         Integer result =  (Integer) client.execute(config,"query_sn",  
ag);
         System.out.println("Returned: " + result);
         System.out.println("Finished.");
     }
}


And here are the stack trace:

Exception in thread "main" org.apache.xmlrpc.XmlRpcException: Failed  
to create input stream: Server returned HTTP response code: 401 for  
URL: http://example.org/query.cgi
	at  
org 
.apache 
.xmlrpc 
.client 
.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:65)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java: 
141)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java: 
44)
	at  
org 
.apache 
.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
	at Test4.main(Test4.java:25)
Caused by: java.io.IOException: Server returned HTTP response code:  
401 for URL: http://example.org/query.cgi
	at  
sun 
.net 
.www 
.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java: 
1241)
	at  
org 
.apache 
.xmlrpc 
.client 
.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
	... 7 more
Caused by:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://example.org/query.cgi
	at  
sun 
.net 
.www 
.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java: 
1241)
	at  
org 
.apache 
.xmlrpc 
.client 
.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java: 
141)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
	at  
org 
.apache 
.xmlrpc 
.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java: 
44)
	at  
org 
.apache 
.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
	at Test4.main(Test4.java:25)
make: *** [Test4] Error 1




Re: Basic Authentication with xmlrpc-3.1

Posted by Simson Garfinkel <si...@acm.org>.
You are right. It works just fine.  I coded up an example in python  
and found my problem.
I still think that it would be useful to have an example added to the  
documentation, however.

Also, the python implementation allows specifying a username &  
password in the URL, a practice which is available in both browsers  
and specified in RFC 1738 (December 1994). If this class is going to  
receive further development, that would be a useful feature.


On Nov 22, 2007, at 11:58 PM, Jochen Wiedmann wrote:

> On Nov 22, 2007 7:16 PM, Simson Garfinkel <si...@acm.org> wrote:
>
>> I have no problem with the username & password using either my  
>> browser
>> or using my XML-RPC implementation in python. Is there any chance  
>> that
>> this code just doesn't work?
>
> Unlikely. I am myself using it in more than one project and it is
> checked in the test suite.
>
>
> -- 
> Look, that's why there's rules, understand? So that you think before
> you break 'em.
>
>    -- (Terry Pratchett, Thief of Time)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org
>


Re: Basic Authentication with xmlrpc-3.1

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Nov 22, 2007 7:16 PM, Simson Garfinkel <si...@acm.org> wrote:

> I have no problem with the username & password using either my browser
> or using my XML-RPC implementation in python. Is there any chance that
> this code just doesn't work?

Unlikely. I am myself using it in more than one project and it is
checked in the test suite.


-- 
Look, that's why there's rules, understand? So that you think before
you break 'em.

    -- (Terry Pratchett, Thief of Time)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org


Re: Basic Authentication with xmlrpc-3.1

Posted by Simson Garfinkel <si...@acm.org>.
Hi, Jochen. Thanks for responding to my questions.

I have no problem with the username & password using either my browser  
or using my XML-RPC implementation in python. Is there any chance that  
this code just doesn't work?


On Nov 22, 2007, at 12:48 AM, Jochen Wiedmann wrote:

> On Nov 22, 2007 2:09 AM, Simson Garfinkel <si...@acm.org> wrote:
>
>> Greetings. I've spent about 20 hours trying to get basic
>> authentication (username & password) to work with xmlrpc-3.1.  No
>> luck. My demo program works with no username & password (if
>> authentication on the server is disabled) but fails with a 401 error
>> if authentication is enabled.
>
> Assuming that you picked the right user name and password, my guess is
> that the problem is more likely on the server side?
>
> Jochen


Re: Basic Authentication with xmlrpc-3.1

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Nov 22, 2007 2:09 AM, Simson Garfinkel <si...@acm.org> wrote:

> Greetings. I've spent about 20 hours trying to get basic
> authentication (username & password) to work with xmlrpc-3.1.  No
> luck. My demo program works with no username & password (if
> authentication on the server is disabled) but fails with a 401 error
> if authentication is enabled.

Assuming that you picked the right user name and password, my guess is
that the problem is more likely on the server side?

Jochen

-- 
Look, that's why there's rules, understand? So that you think before
you break 'em.

    -- (Terry Pratchett, Thief of Time)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org