This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes BEA/Weblogic and the fly likes Unable to call REST service from within Weblogic 10.3.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Unable to call REST service from within Weblogic 10.3.5" Watch "Unable to call REST service from within Weblogic 10.3.5" New topic
Author

Unable to call REST service from within Weblogic 10.3.5

Ong Vua
Ranch Hand

Joined: Jan 24, 2008
Posts: 59
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

Joined: Jan 24, 2008
Posts: 59
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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to call REST service from within Weblogic 10.3.5
 
Similar Threads
REST tutorial
Server returned HTTP response code: 405 for URL
HTTP request 'GET' example
HTTPUrlConnection only works with Debugger-without I'm to fast??!!
How Do I Forward/Redirect Extra Parameters From JSP To ASP via POST?