It's all about the answers!

Ask a question

How can I retrieve list of project Areas in xml form using HttpClient library?


Krzysztof Kaźmierczyk (7.4k35098) | asked Jul 04 '12, 11:18 a.m.
edited Jul 04 '12, 11:27 a.m. by Geoffrey Clemm (30.0k23035)
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?

Comments
Geoffrey Clemm commented Jul 04 '12, 11:27 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Please remember to phrase your question as a question.

4 answers



permanent link
Jared Russell (1.3k12019) | answered Jul 05 '12, 4:50 a.m.
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.

permanent link
Parker Dunton (4064) | answered Jul 05 '12, 12:51 p.m.
JAZZ DEVELOPER
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);

permanent link
Krzysztof Kaźmierczyk (7.4k35098) | answered Jul 05 '12, 5:29 a.m.
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.


permanent link
Krzysztof Kaźmierczyk (7.4k35098) | answered Jul 05 '12, 6:52 a.m.
Thanks Jared. It is becoming complicated. Is there any easier method to fetch list of project areas?

Your answer


Register or to post your answer.