Handle exceptions in web-based clients
Web based clients, meaning remoting clients that call on web based remoting servers (i.e. http, https, servlet, and sslservlet) have special needs when it comes to handling exceptions that come from the servers they are calling on. The main reason for this is that depending on what type of server they are calling on, they might receive the error in different formats. By default, web based clients will throw an exception when the response code from the server is greater than 400. The exact exception type thrown will depend on the type of web server the client is interacting with. If it is a JBoss Remoting server (http or https server invoker), the exception thrown will be the one originally generated on the server side. If the server is not a JBoss Remoting server (e.g. JBossAS, Tomcat, Apache Web Server, etc.), the exception thrown will be org.jboss.test.remoting.transport.http.WebServerError. The WebServerError's message will be the error html returned by the web server. Throwing an exception may be turned off with the parameter HTTPMetadataConstants.NO_THROW_ON_ERROR (actual text value "NoThrowOnError") set to "true". This parameter may be passed in the InvokerLocator or configuration map when the org.jboss.remoting.Client is created, or it may be included in the metadata map passed to public Object invoke(Object param, Map metadata) throws Throwable; . This will cause the http client invoker to not throw an exception, but instead return the data from the web server error stream. In the case that the data returned from this error stream is of type java.lang.String (i.e. is error html), it will be wrapped in a WebServerError and returned as this type. The raw data from the web server can the be retrieved by getting the WebServerError's message. Note. Prior to Remoting version 2.4, the servlet transport returned a simple error message in the event of an error on the server side. As of version 2.4, the discussion about exception handling applies to the servlet and sslservlet transports as well. The original behavior of returning an error message can be requested by configuring the server with the parameter org.jboss.remoting.transport.http.HTTPMetadataConstants.DONT_RETURN_EXCEPTION (actual value "dont-return-exception") set to "true".