Accessing Polarion WebServices via Python : Issues

Description
teropes
Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI
Contact:

Accessing Polarion WebServices via Python : Issues

Postby teropes » Tue Dec 13, 2011 9:00 am

Greetings Polarion users!

I'm having problems accessing Polarion WebServices via Python scripts. I'm using Python 2.5.4 with suds 0.4 as a SOAP Client.

The following quick and dirty snippet is trying to access a WorkItem from our Polarion server:

Code: Select all

from suds.client import Client

## CONFIGURATION
# WSDL URL's
tracker_url = 'http://our_server/polarion/ws/services/TrackerWebService?wsdl'
session_url = 'http://our_server/polarion/ws/services/SessionWebService?wsdl'

# Session auth
username = "user"
password = "password"

# Init Client objects
session = Client(session_url)
tracker = Client(tracker_url)

## LOGIN AND TEST
try:
    # Session login
    session.service.logIn(username, password)
    # session.service.beginTransaction()

    fields = ['id', 'title', 'description']
    wi = tracker.service.getWorkItemById("dev", "WI-42")
    print wi

except:
    print "Failure"


It results in:
(WorkItem){
_unresolvable = True
_uri = "subterra:data-service:objects:/default/dev${WorkItem}WI-42"
}


What exactly does this _unresolvable indicate? I checked the logs from server and it shows my attempt as:
2011-12-13 10:43:29,272 [TP-Processor7] INFO com.polarion.alm.ws.handlers.SessionHandler - Session -5001506165221371995 created.
2011-12-13 10:43:29,272 [TP-Processor7] INFO com.polarion.alm.ws.services.SessionWebService - Logging in user admin into Session[-5001506165221371995]
2011-12-13 10:43:29,272 [TP-Processor7] INFO com.polarion.platform.internal.security.SecurityService - User admin tries to log in from webservices
2011-12-13 10:43:29,272 [TP-Processor7] INFO com.polarion.platform.internal.security.SecurityService - User admin logged in from webservices
2011-12-13 10:43:29,506 [TP-Processor7] INFO com.polarion.alm.ws.handlers.SessionHandler - Session 3387853522455761297 created.
2011-12-13 10:43:29,506 [TP-Processor7] INFO com.polarion.platform.persistence.internal.pe.ObjectAccessor - LocalId[prototype WorkItem, object WI-42] (com.polarion.subterra.persistence.identification.UnknownObjectException)
2011-12-13 10:43:29,506 [TP-Processor7] INFO TXLOGGER - Tx 4d0da5d06370f_0_4d0da5d06370f_0_: finished. Time total: [ TIME 0,004986389 s. ], svn time total: [ TIME 0 s. ][] (0x), processed revs: [], write: false, rollback: false


My goal is simply to access WorkItem as an object, so that I can use the methods of the WorkItem class. Like "print wi.getName()". Once i get that function to work, I can do alot more fun with this WebServices thingy ;)

I also have question: Do i need to begin transaction <-> end transaction between actions such as query of workitems? My attempts of endTransaction(false) always leads to Java NullPointerException...?

I have seen some examples written in C# environment but I'm not interested in C#. Our automated test suite is written in Python and so that would be obviously our choice to interact with Polarion aswell.

Please comment, suggest, advice anything!

BR,
Tero Pesonen

NickEntin
Posts: 472
Joined: Tue Oct 24, 2006 10:27 am
Location: Polarion Software GmbH, Stuttgart
Contact:

Re: Accessing Polarion WebServices via Python : Issues

Postby NickEntin » Wed Dec 14, 2011 8:45 am

Hi Tero,

I'm not an expert in Python, I'd recommend you to take a look on the SDK example in Java, make sure it works, and then translate it to Python, being sure that the logic is correct.

And no, for read operations you don't need transactions.

Best regards,
Nick

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: Accessing Polarion WebServices via Python : Issues

Postby martins » Wed Dec 14, 2011 1:23 pm

I had the same problems when I tried to implement a webservice connection in PHP :-)

It's necessary to retrieve the sessionID from the answer of the login-request and use this sessionID in header of all following requests.

The extract from the log looks like your second request ("tracker.service.getWorkItemById...") is using another session then the first (login) request.

I don't know how to implement this in Python, in PHP I implemented it as follows:

Code: Select all

$wsSession  = new SoapClient($p_fqn."/polarion/ws/services/SessionWebService?wsdl",  array('trace' => 1));
$wsTracker  = new SoapClient($p_fqn."/polarion/ws/services/TrackerWebService?wsdl",  array('trace' => 1));

$wsSession->logIn(array("userName"=>$p_user, "password"=>$p_password));

$xResponse = new DOMDocument();
$xResponse->loadXML($wsSession->__getLastResponse());

$header = new SoapHeader("http://ws.polarion.com/session", "sessionID", $xResponse->getElementsByTagName('sessionID')->item(0)->nodeValue, "0", "http://schemas.xmlsoap.org/soap/actor/next");
$wsSession->__setSoapHeaders($header);
$wsTracker->__setSoapHeaders($header);

After adding the header to the $wsTracker everything works fine.

Maybe you can "translate" this from PHP to Python.

Martin

teropes
Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI
Contact:

Re: Accessing Polarion WebServices via Python : Issues

Postby teropes » Thu Dec 15, 2011 1:26 pm

Thanks for your response martins.

How does the PHP function __setSoapHeaders() format the given array of data? It generates the Header tags of XML or what?

What is the exact content of your $header variable? Is it the SOAP-ENV:Header tag with the sessionID tag in it or some kind of an array of data? I'm confused here..

I have been playing around with my script now and got to the point where I can parse the sessionID from the login response envelope. Now I'm trying to format the header which i would set with client.set_option(soapheaders=<my_header>) but no luck so far. Still gettin the unresolvable = True response.

Is the proper format for session related soap header documented somewhere?

teropes
Posts: 6
Joined: Tue Dec 13, 2011 8:48 am
Location: Valtra Inc. FI-44200 SUOLAHTI
Contact:

Re: Accessing Polarion WebServices via Python : Issues

Postby teropes » Fri Dec 16, 2011 1:30 pm

I have resolved this issue, thanks for the examples provided!

For future reference I will paste the working copy.

Format proper SOAP header with Python 2.5.4 and suds 0.4 -> Polarion WebServices API:

Code: Select all

# SessionService URL
ws_session_url = 'http://agfinaps152/polarion/ws/services/SessionWebService?wsdl'

# Init SOAP Client
session = Client(ws_session_url)

# Login
session.service.logIn(username, password)

 # parse sessionID from the login response envelope and format header
ssnid = login_response.getChild("soapenv:Envelope").getChild("soapenv:Header").getChild("ns1:sessionID").getText()
sid = Element('sessionID', ns=('ns1','http://ws.polarion.com/session')).setText(ssnid)
must_understand = Attribute("SOAP-ENV:mustUnderstand", "0")
actor = Attribute("SOAP-ENV:actor", "http://schemas.xmlsoap.org/soap/actor/next")
sid.append(must_understand)
sid.append(actor)

# set SOAP header
session.set_options(soapheaders=sid)


print sid (confirmed as working header):

Code: Select all

<ns1:sessionID xmlns:ns1="http://ws.polarion.com/session" SOAP-ENV:mustUnderstand="0" SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">4404955032591469296</ns1:sessionID>
<SOAP-ENV:Header>
   <ns1:session xmlns:ns1="http://ws.polarion.com/session" SOAP-ENV:mustUnderstand="0">-2719686666748149143</ns1:session>
</SOAP-ENV:Header>


BR,
Tero Pesonen


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: BrianPrick, walterun3 and 10 guests