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



Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to