Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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"
// jazzServerURL is "https://localhost:7443/jazz/"
String workitemURLRelative = Location.namedLocation(newState, getPublicRepositoryURL()).toRelativeUri().toString();
String workitemURLAbsolute = Location.namedLocation(newState, getPublicRepositoryURL()).toAbsoluteUri().toString();
IServerDescriptionService descriptionService = getService(IServerDescriptionService.class);
String jazzServerURL = descriptionService.getJazzTeamServerURI();
ProtocolSocketFactory factory = new SSLProtocolSocketFactory();
Protocol https = new Protocol("https", factory, 443);
Protocol.registerProtocol("https", https);

@SuppressWarnings("static-access")
OAuthServiceProviderInfo oAuthServiceProviderInfo = oauthHttpclient.createProviderInfo(jazzServerURL);

try {
oauthHttpclient = new OAuthHttpClient(oAuthServiceProviderInfo, factory);
} catch (HttpException e1) {
e1.printStackTrace();
}
String output = "";
try {
      GetMethod methodGet = new GetMethod(workitemURLRelative);
methodGet.addRequestHeader("accept", "application/rdf+xml");
methodGet.addRequestHeader("OSLC-Core-Version", "2.0");
oauthHttpclient.executeMethod(methodGet);
output = methodGet.getResponseBodyAsString();
methodGet.releaseConnection();
} catch (final Exception e) {
e.printStackTrace();
}
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"/>
<title>Error 404 Not Found</title>
...

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

0 votes

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.

I have not done this myself, but I know for a fact that there is stuff in the EWM SDK that should allow you to use Authentication or OAuth to do this.
I have searched the EWM (client and server) SDK for HTTPClient and found other references. e.g. com.ibm.team.jfs.app.http.client.JazzHttpClient . So there might be a service layer you can use that inherits the authentication, or you have to set up some OAuth based mechanism. Fort API other then the one you use there are at least some unit tests.

showing 5 of 6 show 1 more comments

Be the first one to answer this question!

Register or log in to post your answer.

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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,030

Question asked: Mar 08 '22, 10:32 a.m.

Question was seen: 1,583 times

Last updated: Mar 09 '22, 7:51 a.m.

Confirmation Cancel Confirm