This discussion is archived
2 Replies Latest reply: Jan 12, 2013 11:35 PM by 984522 RSS

Unable to call a remote REST service inside Weblogic 10.3.5

user8742475 Newbie
Currently Being Moderated
I tried to call a remote RESTful service inside Weblogic and it failed. It worked fine outside of Weblogic. When I printed out the content of the HttpURLConnection object, it's text/html and not application/json. I think that's why it failed. I got this link

http://docs.oracle.com/cd/E24329_01/web.1211/e24983/client.htm#DAFGICFC

It mentioned jersey? We have to use jersey? Below is my current code

URL url = new URL("http://servername/rest/user/login");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");

//Set basic authentication in the header required by the REST service
String userPassword = "user1:password1";
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
conn.setRequestProperty("Authorization", "Basic " + encoding);

//Submit user and password
String params = "{\"username\":\"user2\",\"password\":\"password2\"}";

conn.getOutputStream().write(params.getBytes());
conn.getOutputStream().flush();

System.out.println(conn.getResponseCode());
System.out.println(conn.getResponseMessage());

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points