How can I retrieve list of project Areas in xml form using HttpClient library?
Krzysztof Kaźmierczyk (7.5k●4●80●103)
| asked Jul 04 '12, 11:18 a.m.
edited Jul 04 '12, 11:27 a.m. by Geoffrey Clemm (30.1k●3●30●35)
Trying to retrieve oslc/workitems/catalog using Apache HttpClient
Hello, I am trying to retrieve list of project areas using Apache httpClient library. Here is my code: public static void main(String[] args) throws AuthenticationException, ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient(); WebClientDevWrapper.wrapClient(httpclient); Credentials defaultcreds = new UsernamePasswordCredentials( "jazzy", "jazzy"); String address = "https://localhost:9443/ccm/oslc/workitems/catalog"; HttpGet httpget = new HttpGet(address); HttpRequest request = new BasicHttpRequest("GET", address); request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); httpget.addHeader(new BasicScheme().authenticate(defaultcreds, request)); try { HttpResponse resp = httpclient.execute(httpget); InputStream is = resp.getEntity().getContent(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } } finally { httpget.releaseConnection(); } } Unfortunately instead of xml file I am receiving weird html file. Am I doing something wrong? How can I retrieve list of project Areas in xml form using HttpClient library? |
4 answers
The first question is what type of authentication is your server using? You're trying to do basic authentication but if your server is configured to use forms auth that won't work.
If your server is using forms authentication then you need to make an HTTP GET to https://localhost:9443/ccm/authenticated/j_security_check?j_username=jazzy&j_password=
jazzy Once you've authenticated correctly the request you're making for the service provider catalog should work fine.
|
Hi Jared.
In that case I should use following sequence of get commands: GET https://localhost:9443/ccm/authenticated/j_security_check?j_username=jazzy&j_password= jazzy GET https://localhost:9443/ccm/oslc/workitems/catalog - it should return list of project areas. Is that correct? Comments
Jared Russell
commented Jul 05 '12, 6:03 a.m.
Yes that's correct. Note that before making the login request you will probably need to make a request to https://localhost:9443/ccm/authenticated/identity in order to have a session cookie set. One other thing I forgot to mention is that you will need to ensure you send your session cookie to the server on every request. It looks like the cookie is stored within the HttpClient instance itself, so you will need to ensure you use the same instance on every request. |
Thanks Jared. It is becoming complicated. Is there any easier method to fetch list of project areas?
|
Not that I know of, if you want to use REST services. You can also get all project areas using our client libraries however, if that works for you. This snippet gives you an idea of what that would look like:
IProcessItemService processItemService = (IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class); processItemService ().findAllProjectAreas(IProcessClientService.ALL_PROPERTIES, monitor); |
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.
Comments
Please remember to phrase your question as a question.