views:

81

answers:

2

i have two tomcat servers that communicate between them. upon an error at one of the servers i would like to send an error response to the other server.

i am sending the error using: resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());

i am catching the response with org.apache.commons.httpclient.httpMethod.

my question is how can i retrieve the e.getMessage () that i am adding to the error message?

thanks

A: 

I think the error message gets packaged up in HTML and then sent, so in order to get the message you will need to parse the HTML.

I would suggest this isn't the most efficient way of transferring information between two servers. Provided that no humans need to look at the data, why don't you send the messages in a machine-readable format such as XML instead? Is there a specific reason you need to use response.sendError()?

Phill Sacre
+3  A: 

You can override the page that is sent by declaring a specific page for the status code in the web.xml:

<error-page>
     <error-code>400</error-code>
     <location>/errorMsg.jsp</location>
</error-page>

In the JSP, do something like:

<%@page isErrorPage="true"%>
<%= exception.getMessage(); %>

Then, all that is sent back is the message.

EJB