I have created an XF and generated the Json by appending 'model.json' to the URL. Now, I want to get the same Json when I hit the same URL in servlet. I am getting Error#400 (bad Request) when I use below piece of code. Do I need to pass any authentication to get HTTP connection. If so, what kind of authentication I should you and how to get the authentication params?
HttpURLConnection urlConnection = createHttpConnection(PAGE_URL,null); //Passing Authentication Key as null. See createHttpConnection method below.
It looks like your request is not formed correctly.
Are you trying this on Author? If yes then you need credentials otherwise not.
If you can access XF as JSON from browser then you should be able to access in servlet as well. It is just another http request.
I would suggest trying this on publish server. Sample request can be like below (This is an example of use JS-API but you can get logic from here and easily convert in java servlet )
var xfpath = "/content/exp......./" // path to XF, make sure you escape / if needed
var curReq = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+xfpath+".model.json";
var method = new Packages.org.apache.commons.httpclient.methods.GetMethod(curReq);
var client = new Packages.org.apache.commons.httpclient.HttpClient();
/* Author specific
var creds = new Packages.org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin");
var responseBody = method.getResponseBodyAsStream();