Hi there,

I'm using HTTPClient to send a request from on servlet to another servlet on 
the same host. The request can be a POST or a GET request. I know that the 
second servlet returns the right data. The first servlet also retrieves the 
right data but the client (browser) displays alsways an 405 error ("HTTP method 
GET is not supported by this URL") !  So what I'm doing wrong ?

Here's my servlet:

-- projectA.TransferDataServlet
protected void doGet .. {
 ...

byte[] forwardedData = RequestHelper.doGet(params, url);
String forwardedDataString = new String(forwardedData);
// this is the original code
/*outStream = response.getOutputStream();
 outStream.write(forwardedData);*/
// just a try
writer = response.getWriter();
writer.write(forwardedDataString);
}


-- RequestHelper
private static final HttpClient client = new HttpClient();

public static byte[] doGet(NameValuePair[] params, String url) throws 
IOException, AppException {
  GetMethod method = new GetMethod(url);
  method.setQueryString(params);
 // send to sampleB.DataLoggerGate
  int statusCode = client.executeMethod(method); 
  byte[] response = getInputStreamData(method.getResponseBodyAsStream());
  method.releaseConnection();
  String responseBody = new String(response);
  if (statusCode != HttpStatus.SC_OK ) {
   ...
  }
  return response;
}

-- projectB.DataLoggerGate
protected void doGet ... {
 ...

 String dataOutput = ...

  /*ServletOutputStream outStream = response.getOutputStream();
 outStream.write(dataOutput.getBytes());
 outStream.close();*/
// just a try
 PrintWriter writer = response.getWriter();
 writer.write(dataOutput);
 writer.close();
}

I can see that forwardedDataString in the TransferDataServlet.doGet method 
caontains the right data but the browser gets only error 405.
I know the UrlRewriteFilter  package (http://tuckey.org/urlrewrite/). But 
between different projects only redirection is supported. And because the 
servlet clients don't support redirection I need transparently forward the 
request to another URL and only returning the result data back to the client.

HTTP client 3.0 + Java 5

Thanks, Lothar
__________________________________________________________________________
Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!        
        
Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to