Authenticate external restapi in meteor

Iam able to authenticate to external RestAPI using the following java code, iam wondering how to authenticate in Meteor. i tried with http package but ended up with the certificate error. Not sure what iam missing here? Appreciate for any pointers. thanks

      //create an instance of SSLContext:
            SSLContext mySSLContext = SSLContext.getInstance("SSL");
            //initialize the SSLContext with the TrustManager instance we created:
            mySSLContext.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(mySSLContext.getSocketFactory());

            //Authenticate credentials **********************

            DefaultHttpClient httpclient = new DefaultHttpClient();
            CookieStore cookieStore = new BasicCookieStore();
            HttpContext localContext = new BasicHttpContext();
            localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            //Instantiate an object HttpGet with the URL of the server you want to connect, 
            HttpGet httpGetID = new HttpGet("https://localhost:9443/ccm/authenticated/identity");
            httpclient.execute(httpGetID, localContext);
            httpGetID.abort();
            //to make sure that you created your cookies correctly, try to retrieve the saved information:
            List<Cookie> cookies1 = cookieStore.getCookies();
            for (Cookie cookie : cookies1) {
               System.out.println("\t" + cookie.getName() + " : " + cookie.getValue());
            }



            //The next step is to authenticate with the j_security_check, using a valid username and password credentials.
            //For this step, we use the Apache HttpClient class NameValuePair:
            List<NameValuePair> authFormParams = new ArrayList<NameValuePair>();
            authFormParams.add(new BasicNameValuePair("j_username", "Myusername"));
            authFormParams.add(new BasicNameValuePair("j_password", "Mypassword"));
            UrlEncodedFormEntity encodedentity = new UrlEncodedFormEntity(authFormParams,
                    "UTF-8");
            HttpPost httpPostAuth = new HttpPost("https://localhost:9443/ccm/authenticated/j_security_check");
            httpPostAuth.setEntity(encodedentity);

            httpclient.execute(httpPostAuth, localContext);
            //to display the cookie data
            List<Cookie> cookies2 = cookieStore.getCookies();
            for (Cookie cookie : cookies2) {
                  System.out.println("\t" + cookie.getName() + " : " + cookie.getValue());
            }

The following is the Meteor Code i have tried:

var result = HTTP.call("GET", https://localhost:9443/ccm/authenticated/identity,
                    function(error,result){
                        if(result){
                            console.log("result is" + JSON.stringify(result));
                            //console.log("myresult"  + result);
                        }else{

                            console.log("error is" + error);
                        }


                     }
                       );
                       console.log("my result" + result);   
        var result1 = HTTP.call("POST", https://localhost:9443/ccm/authenticated/j_security_check,
                     {auth: {j_username: 'MyUserName',j_password: 'MyPassword' }
                    }
                       );

What is the error you’re getting?

currently i am getting the status code 302. i have put the code on meteor pad. Not sure what is missing, iam able to get the proper output on firefox poster and chrome advanced rest api. thanks

http://meteorpad.com/pad/5fgeTuPKi7FMSRYSD/RestAPI

You’re stopping at a redirect. Try explicitly telling HTTP.call to followRedirects:

...
HTTP.call('POST', geturl, {
  headers: { "Accept": "application/json","OSLC-Core-Version": "2.0" },
  followRedirects: true
},
...

I know the docs say the default is true, but I think they might be wrong.

Thanks a lot @hwillson. now the status code problem gone, but i am not able to authenticate onto rest service, using the same credentials i am able to, using the Firefox poster and chrome Advanced Rest client application. the following are the steps i followed in chrome Advanced Rest client application. I assume the first request sending some cookies, does meteor handles the cookies just like the browser. Appreciate your help.
http://meteorpad.com/pad/5fgeTuPKi7FMSRYSD/RestAPI (code on meteor pad)

  1. used the following url with the headers using POST method:
    Headers:
    Accept:application/json
    OSLC-Core-Version:2.0
    URL:
    https://jazz.net/jazz/authenticated/j_security_check?j_username=usemeonce&j_password=NewWorld123

  2. used the following url with the headers using GET method:
    Headers:
    Accept:application/json
    OSLC-Core-Version:2.0
    URL:https://jazz.net/jazz/oslc/contexts/_Q2fMII8EEd2Q-OW8dr3S5w/workitems