2 Replies Latest reply: Jan 13, 2013 1:35 AM by 984522 RSS

    Unable to call a remote REST service inside Weblogic 10.3.5

    user8742475
      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());