RTC Java server side extension - performing Http Request
Hello everyone,
I am working on a server extension for EWM using Java API (RTC SDK) and try to solve a basic issue (as I thought).
After saving a work item in a follow-up action I want to perform Http requests. As a starting point I try to get a Http response for a GET request using the URI of the work item. Looks like that:
// workitemURLRelative is "resource/itemName/com.ibm.team.workitem.WorkItem/26" // workitemURLAbsolute is "https://localhost:7443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/26" String workitemURLRelative = Location.namedLocation(newState, getPublicRepositoryURL()).toRelativeUri().toString(); String workitemURLAbsolute = Location.namedLocation(newState, getPublicRepositoryURL()).toAbsoluteUri().toString(); ProtocolSocketFactory factory = new SSLProtocolSocketFactory(); Protocol https = new Protocol("https", factory, 443); try { GetMethod methodGet = new GetMethod(workitemURLRelative);
Unfortunately, I get the following error message indicating that the URI shall be relative instead of absolute.
java.lang.UnsupportedOperationException: Only host relative URIs can be used. at com.ibm.team.repository.common.oauth.OAuthHttpClient.executeMethod(OAuthHttpClient.java:113)
Using the absolute URI (workitemURLAbsolute), the request string can not be found. (However, in another REST tool I get proper responses for the used absolute request string.)
... <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
Do you have any hints how I can use absolute URIs or what the relative URI should look like?
In a client application performing Http requests worked fine, also with absolute URIs.
For the server extension I can not use the same client libraries but changed to common libs.
Are you aware of another solution to perform a simple Http GET request in a server side extension, being logged in already and without the use of client libs?
Thanks in advance
showing 5 of 6
show 1 more comments
|
Be the first one to answer this question!
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
I can find 3 lines where the com.ibm.team.repository.common.oauth.OAuthHttpClient is used and 3 where IOAuthHttpClient is used in the whole EWM server SDK. I can not see how that class is used, for what it is used and if it should be used or where.
Does it mean, you suggest to use another approach?
I just point out the obvious. As I have not tried something like that yet and there is little information about what this is all about, so I am not in a position to suggest anything.
I would likely search the EWM SDK for HttpClient and have a look around if there are examples and test cases using those.
I have tried out the org.apache.commons.httpclient.HttpClient before. Since the Http requests need to be send as a logged in user, I need to consider authorization in some way. I can not provide username and password. I guessed that the OAuthHttpClient is supposed to handle that situation.