Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to remeber login information while connecting by XmlRpc api?

540 views
Skip to first unread message

Rana Banerjee

unread,
Sep 25, 2012, 4:49:43 AM9/25/12
to
Hi,

I am using Apache Xml-Rpc 3.1.3 api to connect to Bugzilla 4.2.3. Once I successfully login to Bugzilla, all subsequent rpc calls are throwing XmlRpcException : You must log in before using this part of Bugzilla.

Here's my code:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class Test
{
public static final String BUGZILLA_URI = "http://******/Bugzilla/";
public static final String RPC_PATH = "xmlrpc.cgi";
public static final String USER_NAME = "****";
public static final String PASSWORD = "****";

public static void main(String[] args)
{
XmlRpcClient rpcClient = null;
XmlRpcClientConfigImpl config = null;

List<Object> loginParams = new ArrayList<Object>();
Map<String, Object> loginData = new HashMap<String, Object>();
loginData.put("login", USER_NAME);
loginData.put("password", PASSWORD);
loginData.put("remember", true);
loginParams.add(loginData);

try
{
config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL(BUGZILLA_URI + RPC_PATH));
rpcClient = new XmlRpcClient();
rpcClient.setConfig(config);

// Login
Object loginResult = rpcClient.execute("User.login", loginParams);
System.out.println("loginResult :::" + loginResult);

}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (XmlRpcException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
//Logout
Object logoutResult = null;
try
{
logoutResult = rpcClient.execute("User.logout", loginParams);
}
catch (XmlRpcException e)
{
e.printStackTrace();
}
System.out.println("logoutResult :::" + logoutResult);

}

}
}


And here's the stack trace :

loginResult :::{id=2}
org.apache.xmlrpc.XmlRpcException: You must log in before using this part of Bugzilla.
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at com.rs.bugzilla.Test.main(Test.java:64)
logoutResult :::null

The Bugzilla parameter "rememberlogin" in Bugzilla installation is set to "defaulton", as mentioned in the api.

Can anybody explain what is wrong here? Or, what should I do to resolve this issue?

Regards,
Rana Banerjee

Thorsten Schöning

unread,
Sep 25, 2012, 5:19:19 AM9/25/12
to support-...@lists.mozilla.org
Guten Tag Rana Banerjee,
am Dienstag, 25. September 2012 um 10:49 schrieben Sie:

> Can anybody explain what is wrong here? Or, what should I do to resolve this issue?

You either have to provide user credentials to each of your calls,
resulting in Bugzilla always logging in the user internally, or after
User.login you must get the sent HTTP cookies and provide them as
such to each call. Remember, this is HTTP level, not arguments to
Bugzilla's methods.

http://www.bugzilla.org/docs/4.2/en/html/api/Bugzilla/WebService.html#LOGGING_IN

Mit freundlichen Grüßen,

Thorsten Schöning

--
Thorsten Schöning E-Mail:Thorsten....@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/

Telefon.............030-2 1001-310
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow

Rana Banerjee

unread,
Sep 25, 2012, 7:27:36 AM9/25/12
to support-...@lists.mozilla.org
Thanks Thorsten for your prompt reply. However, I'm not sure how to get the cookies from the User.login rpc call. Upon successful login, it returns an Object of type Map (id=xxx).

Could you provide my any sample code?

Thanks again,
Rana Banerjee

Thorsten Schöning

unread,
Sep 25, 2012, 8:47:07 AM9/25/12
to support-...@lists.mozilla.org
Guten Tag Rana Banerjee,
am Dienstag, 25. September 2012 um 13:27 schrieben Sie:

> Thanks Thorsten for your prompt reply. However, I'm not sure how to
> get the cookies from the User.login rpc call. Upon successful login,
> it returns an Object of type Map (id=xxx).

> Could you provide my any sample code?

No, sorry, but you need access to the underlying HTTP object for your
call, there surely is one somewhere which lets you access the plain
HTTP response from which you get the cookies. On requests you need
access to the HTTP request object and set those cookies again.

I searched a bit and found that XmlRpcClient gives you access to the
used TransportFactory which gives you access to transports or directly
HttpClient-objects

org.apache.xmlrpc.client.XmlRpcClient.getTransportFactory
org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory.getHttpClient
org.apache.xmlrpc.client.XmlRpcCommonsTransport.setRequestHeader

http://ws.apache.org/xmlrpc/apidocs/index.html?org/apache/xmlrpc/client/XmlRpcClientConfigImpl.html
http://ws.apache.org/xmlrpc/apidocs/index.html?org/apache/xmlrpc/client/XmlRpcClientConfigImpl.html

You may even implement your own transport using the following example:

http://stackoverflow.com/questions/9679719/logging-input-output-xml-in-apache-xmlrpc-client

NabbleBabble

unread,
Nov 2, 2012, 9:57:57 AM11/2/12
to support-...@lists.mozilla.org



Rana Banerjee-2 wrote:
>
> rpcClient.setConfig(config);
>

I am curious as to why this line is not producing an error for you.
According to Netbeans, the setConfig method only takes an Object of
XmlRpcClientConfig, and not XmlRpcClientConfigImpl.
--
View this message in context: http://old.nabble.com/How-to-remeber-login-information-while-connecting-by-XmlRpc-api--tp34476328p34633134.html
Sent from the Bugzilla - Users mailing list archive at Nabble.com.

Thorsten Schöning

unread,
Nov 2, 2012, 2:03:16 PM11/2/12
to support-...@lists.mozilla.org
Guten Tag NabbleBabble,
am Freitag, 2. November 2012 um 14:57 schrieben Sie:

> I am curious as to why this line is not producing an error for you.
> According to Netbeans, the setConfig method only takes an Object of
> XmlRpcClientConfig, and not XmlRpcClientConfigImpl.

XmlRpcClientConfig is an interface and XmlRpcClientConfigImpl
implements it, therefore wherever the interface is needed you can pass
the implementation and the called method only uses what it needs from
the interface.

http://ws.apache.org/xmlrpc/apidocs/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.html

Mit freundlichen Grüßen,

Thorsten Schöning

--
Thorsten Schöning E-Mail:Thorsten....@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/

Telefon...........05151- 9468- 55
0 new messages