Problem with basic authentication using XML-RPC

327 views
Skip to first unread message

IBWT

unread,
Nov 11, 2011, 7:54:12 AM11/11/11
to Trac Users
Hello.

I downloaded the examples zip from the XML-RPC Trac plugin site and I
am trying to access my Trac repository using XML-RPC. This is my code:

package es.modelum.migration.mylyn.trac;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.lustin.trac.xmlprc.Ticket;
import org.lustin.trac.xmlprc.TrackerDynamicProxy;

import tasks.Task;

public class TracInitializer {
XmlRpcClient rpcClient = new XmlRpcClient();
TrackerDynamicProxy rpcProxy;

public TracInitializer(String serverURL, String username,
String
password) throws MalformedURLException {
XmlRpcClientConfigImpl rpcConf = new
XmlRpcClientConfigImpl();
rpcConf.setBasicUserName(username);
rpcConf.setBasicPassword(password);
rpcConf.setServerURL(new URL(serverURL));

rpcClient.setConfig(rpcConf);
rpcProxy = new TrackerDynamicProxy(rpcClient);
}

public void getTicket(int ticketID) {
Ticket ticket =
(Ticket)rpcProxy.newInstance(Ticket.class);
System.err.println(ticket.getTicketFields());
}

public void createTicket(Task task) {

}

static public void main(String[] args) {
try {
TracInitializer tracInitializer = new
TracInitializer("http://modelum.es/trac/mylyntest", "user", "pass");
tracInitializer.getTicket(2);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

When the request ticket.getTicketFields() is called, I get the
following exception:

Exception in thread "main"
java.lang.reflect.UndeclaredThrowableException
at $Proxy0.getTicketFields(Unknown Source)
at
es.modelum.migration.mylyn.trac.TracInitializer.getTicket(TracInitializer.java:
29)
at
es.modelum.migration.mylyn.trac.TracInitializer.main(TracInitializer.java:
39)
Caused by: org.apache.xmlrpc.XmlRpcException: Failed to create input
stream: Server returned HTTP response code: 401 for URL:
http://modelum.es/trac/mylyntest
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:
60)
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:
39)
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
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at org.lustin.trac.xmlprc.TrackerDynamicProxy
$1.invoke(TrackerDynamicProxy.java:125)
... 3 more

User and password are correct and the Trac serves XML-RPC requests
correctly from the Mylyn Trac connector.

What am I doing wrong?

osimons

unread,
Nov 12, 2011, 4:21:51 AM11/12/11
to Trac Users

On Nov 11, 2:54 pm, IBWT <inbasswetr...@gmail.com> wrote:

[snip]

>        static public void main(String[] args) {
>                try {
>                        TracInitializer tracInitializer = new
> TracInitializer("http://modelum.es/trac/mylyntest", "user", "pass");
>                        tracInitializer.getTicket(2);
>                } catch (MalformedURLException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }

[snip]

> Caused by: org.apache.xmlrpc.XmlRpcException: Failed to create input
> stream: Server returned HTTP response code: 401 for URL:http://modelum.es/trac/mylyntest

Your URL seems bad. It gets a 401 (not authorized), and I then doubt
that that URL challenges for authentication - and even if it does it
still lacks a call to the actual RPC handler. The URL should look
something like this (assuming "mylyntest" is a your project):

http://modelum.es/trac/mylyntest/login/rpc


:::simon

IBWT

unread,
Nov 14, 2011, 4:36:40 AM11/14/11
to Trac Users
Hello Simon thanks for your response.

My URL works properly with the Ruby XML-RPC implementation (trac4r).
The URL you provide is not recognized by the server, an exception is
thrown by the client saying that no input stream can be created.
Reply all
Reply to author
Forward
0 new messages