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

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

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?

0 votes

Comments

Please remember to phrase your question as a question.



4 answers

Permanent link
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.

2 votes


Permanent link
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);

1 vote


Permanent link
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?

0 votes

Comments

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
Thanks Jared. It is becoming complicated. Is there any easier method to fetch list of project areas?

0 votes

Your answer

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

Question asked: Jul 04 '12, 11:18 a.m.

Question was seen: 6,155 times

Last updated: Jul 05 '12, 12:51 p.m.

Confirmation Cancel Confirm