• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to call REST service from within Weblogic 10.3.5

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is my code to call a REST service. It worked fine outside of Weblogic. After I deployed it (WAR) to Weblogic 10.3.5, I got the below errors. It's the same exact code. Do you have any ideas?

401
Unauthorized: Missing required argument username

==========================================

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());
 
Ong Vua
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I printed out the output for both the good and bad ones. I noticed the content-type is text/html when I call the REST service within Weblogic. It should be application/json since the code is exactly the same.

ERROR
=====

connAllowUserInteraction: false
connContentType: text/html
connContentEncoding: null
connRequestMethod: POST
connDoInput: true
connDoOutput: true
connPermission: (java.net.SocketPermission servername:80 connect,resolve)
connURL: http://servername/rest/user/login
connHeaderField: null=[HTTP/1.1 401 Unauthorized: Missing required argument username]
connHeaderField: ETag=["1348297842"]
connHeaderField: Date=[Sat, 22 Sep 2012 07:10:42 GMT]
connHeaderField: Vary=[Accept]
connHeaderField: Transfer-Encoding=[chunked]
connHeaderField: Expires=[Sun, 19 Nov 1978 05:00:00 GMT]
connHeaderField: Last-Modified=[Sat, 22 Sep 2012 07:10:42 GMT]
connHeaderField: Connection=[close]
connHeaderField: Content-Type=[text/html]
connHeaderField: Server=[Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8m DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635]
connHeaderField: X-Powered-By=[PHP/5.2.17]
connHeaderField: Cache-Control=[no-cache, must-revalidate, post-check=0, pre-check=0]

GOOD
====

connAllowUserInteraction: false
connContentType: application/json
connContentEncoding: null
connRequestMethod: POST
connDoInput: true
connDoOutput: true
connPermission: (java.net.SocketPermission servername:80 connect,resolve)
connURL: http://servername/rest/user/login
connHeaderField: null=[HTTP/1.1 200 OK]
connHeaderField: ETag=["1348297985"]
connHeaderField: Expires=[Sun, 19 Nov 1978 05:00:00 GMT]
connHeaderField: Last-Modified=[Sat, 22 Sep 2012 07:13:05 GMT]
connHeaderField: Set-Cookie=[SESS0b960ba15fe89f91c2c8b1f79c14a60f=Xehs0in8jvrGLHaPBh3EqkMTdVtCAx_DhFAVse18a4E; expires=Mon, 15-Oct-2012 10:46:26 GMT; path=/; domain=servername; HttpOnly]
connHeaderField: Connection=[close]
connHeaderField: X-Powered-By=[PHP/5.2.17]
connHeaderField: Server=[Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8m DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635]
connHeaderField: Cache-Control=[no-cache, must-revalidate, post-check=0, pre-check=0]
connHeaderField: Transfer-Encoding=[chunked]
connHeaderField: Vary=[Accept]
connHeaderField: Date=[Sat, 22 Sep 2012 07:13:05 GMT]
connHeaderField: Content-Type=[application/json]
reply
    Bookmark Topic Watch Topic
  • New Topic