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.K. Hartig
Mar 08 '22, 12:14 p.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 2:02 a.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 2:37 a.m.K. Hartig
Mar 09 '22, 6:44 a.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Mar 09 '22, 7:51 a.m.