permaculture playing cards*
The moose likes Servlets and the fly likes Error 405 with getOutputStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error 405 with getOutputStream()" Watch "Error 405 with getOutputStream()" New topic
Author

Error 405 with getOutputStream()

Mike Rybicki
Greenhorn

Joined: Apr 12, 2006
Posts: 2
I am writing an app, using JRun, that will do the following:

1. Receive a POST from an external IP
2. Parse the parameters, one being the external IP address, and fire a POST request for more data
3. Receive a second POST from the IP with the extra data

For now, I am testing with a Perl script that fires off a POST, receives the request from the app, and
sends the second POST.

Below is the code section:

...

URL u=null;
HttpURLConnection conn=null;
OutputStream theOutStream=null;
InputStream theInStream=null;

u = new URL(url);
conn=(HttpURLConnection) u.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setDoOutput(true);
conn.setDoInput(true);

theOutStream=conn.getOutputStream();

int rc = conn.getResponseCode();
if( DEBUG ) LOG_INFO("** rc: "+rc);
String rval = conn.getResponseMessage();
SK_Servlet.LOG_INFO("** rval: " + rval);

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theOutStream));
out.write(postReq.toString());
out.flush();
out.close();

StringBuffer startupParams = new StringBuffer();
theInStream = conn.getInputStream();

BufferedReader in = new BufferedReader(new InputStreamReader(theInStream));
startupParams.append(in.readLine());

...

The Perl script runs and sends the first POST. The app receives the POST and parses it, but when I send my POST,
it errors. I get in the log:

04/12 09:20:58 info ** rc: 405
04/12 09:20:58 info ** rval: Method Not Allowed

I tried adding conn.connect() before making the getOutputStream() call, but I get the same error.

Any tips/suggestions would be greatly appreciated. Thanks.


Just say WOOF.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

This error usually occurs when a servlet (or other server-side target) isn't wired up to accept the HTTP method type -- for example, not implementing doPost() in a servlet.

Is the target of this post set up to accept POST operations?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Rybicki
Greenhorn

Joined: Apr 12, 2006
Posts: 2
The client app will be. The test machine I am using is a linux box with Perl. The linux box is receiving without any problem. We won't have access to the true client for a couple weeks.

If this is the issue, then I will "code around" and wait until I have access to their client to verify the connection.

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Cool. Check back if you have further problems when connecting to the actual client.
 
 
subject: Error 405 with getOutputStream()
 
Similar Threads
HttpUrlConnection - cXML PunchOutSetupRequest
how to wait my class for the servlet response
Servlet call another context
JPEG Image Upload
HttpURLConnection - Luanch Browser