views:

383

answers:

1

I am getting this error from a PostMethod using commons-httpclient

No credentials available for DIGEST 'realm'@localhost

and a 401 back from the server.

I followed the example from this post java client program to send digest authentication request using HttpClient API (2)

However, it still seems to fail.

I am trying to connect to a XML-RPC service, we use digest authentication. I tried using the Apache xmlrpc library but it seems to not support digest authentication.

Any ideas?

Thanks.

A: 

Hi, I'm trying to do the exact same thing. I have my XML-RPC client working fine now:

    public static short connectToBugTrackingXmlRpcServer() {
    try {
        XmlRpcClientConfigImpl xmlRpcClientConfig = new XmlRpcClientConfigImpl();
        xmlRpcClientConfig.setServerURL(new URL(CStudioGlobals.bugTrackingConfProperties.getUrlXmlRpcServer()));
        xmlRpcClientConfig.setBasicUserName(CStudioGlobals.bugTrackingConfProperties.getUsername());
        xmlRpcClientConfig.setBasicPassword(CStudioGlobals.bugTrackingConfProperties.getPassword());
        xmlRpcClientConfig.setEncoding("UTF-8");

        XmlRpcClient xmlRpcClient = new XmlRpcClient();
        xmlRpcClient.setConfig(xmlRpcClientConfig);

        CTrackerDynamicProxy xmlRpcProxy = new CTrackerDynamicProxy(xmlRpcClient);

        Ticket ticket = (Ticket)xmlRpcProxy.newInstance(Ticket.class);
        ticket.query(); // query some tickets

        return CONNECTION_SUCCESS;
    } catch (Throwable t) {
        t.printStackTrace();
        displayError(CStudioGlobals.localization.getTerm("error.title.Sql_error"),
                     CStudioGlobals.localization.getTerm("error.content._Invalid_connection"),
                     CStudioGlobals.localization.getTerm("error.resolution.Check_your_connection_settings"));
        return CONNECTION_RETRY;
    }
}

but I'd like to use http digest authentication. Could you explain ho you did it ? Thanks,

egavaldo
Yeah it wasn't so tricky, You need to set You have to create an AuthScope Object and Also UsernamePasswpordCredentials Object. See the docs for exact usage, but it will work, it works in many enivironments I tested.httpclient.getState().setProxyCredentials(authscope, upc); httpclient.getState().setCredentials(authscope, upc);
Dave