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
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 08 '22, 11:14 a.m.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.
K. Hartig
Mar 08 '22, 12:14 p.m.Does it mean, you suggest to use another approach?
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 2:02 a.m.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.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 2:37 a.m.I would likely search the EWM SDK for HttpClient and have a look around if there are examples and test cases using those.
K. Hartig
Mar 09 '22, 6:44 a.m.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.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 7:51 a.m.