Exception handling from Java service

Hi Everyone,

I am using wM6.5. Is it possible to catch exception thrown from a wM flow service/java service which is being called from a java program using HTTP as below.

String u = “http://”+ hostName + “:” + hostPort + /invoke/wM service name;
URL url = new URL(u);
connection = url.openConnection();
catch(Exception e){}
Please advice.

Pauly Konikara


Perhaps you could explain a bit more about what you are trying to accomplish?

Why are you using a java service to invoke your Flow service? Why is it doing so using HTTP?


Hi Mark,

We have a batch file to run the java program and the wM flow service is called from java program using http. We do not want to use scheduler task to execute this particular flow service.

Whenever there is an error in flow service execution, I am able to catch only IOException in the catch block of the java program.

I am throwing ServiceException in the flow service.


Even if you are not catching the ServiceException in your calling program (which of course will require the client.jar in the classpath of your calling java program), you should still be able to catch it as Exception - keeping the catch(Exception e) block as the last one in the series of catch that you might have.


There is no notion of throwing an exception across an HTTP connection. Your Java program will not have any understanding of “ServiceException” nor will it ever see such a thing.

Your Java program will see only the exceptions associated with the methods you are calling. For example, your url.openConnection call may result in an IOException, which indicates a connection failure of some sort and not that the service on IS failed.

If your IS service throws an exception your Java program will actually see a successful HTTP interaction. You’ll need to process the returned HTML (the default behavior is to return an HTML table) to see what happened. You can also customize what your IS service returns when an error occurs by catching the error in the service and setting the response using pub.flow:setResponse or by defining a template.

Another approach, which Mark alludes to, is to use the IS Java API/libraries to call the service (refer to the API documentation for com.wm.app.b2b.client) instead of communicating via HTTP. In this case, you can indeed catch ServiceException objects.



Thanks for your response. We cannot catch ServiceException because ServiceException is never thrown by the code in try block in java program. ServiceException is thrown by the wM service. Since we are calling the wM service using http we cannot catch the ServiceException thrown by wM service in java program.

After setting the response by pub.flow:setResponse in flow service, I have tried System.out.println(“message=”+((HttpURLConnection) connection).getResponseMessage()); in the java program and it gives the output as message=OK.


I’m confused. In your original post you asked:

In a followup post you stated:

This again indicated that you were looking to catch an exception thrown by an IS service invoked via HTTP from a Java program.

I pointed out in my post that “There is no notion of throwing an exception across an HTTP connection. Your Java program will not have any understanding of “ServiceException” nor will it ever see such a thing.”

Then I go on to say that you can use the IS Java API instead of HTTP to catch ServiceExceptions, if desired.

Your latest post seems to indicate that you understood the “can’t catch an exception via HTTP” all along and that I misinterpreted your question.

In any case, you’re absolutely right that if you’re invoking the Integration Server service via HTTP that you will never be able to catch a ServiceException within your Java program–indeed you’ll never be able to catch any exception thrown by the IS service within your Java program because Java exceptions are not propogated across an HTTP connection.

If you do want to catch exceptions thrown by an IS service then you can do so if you use the IS Java API, instead of HTTP, to invoke the IS service. In this case, a ServiceException can be thrown and can be caught within your Java program.

If you want to continue using HTTP, instead of using the IS Java API, (I recommend sticking with HTTP) and you’re having issues with setResponse, perhaps you can post the snippet of your IS service that is supposed to be passing back the error via setResponse and we can take a look at what might the problem.

I have in the past used the IS Java API to create a client that connected to IS service and we were able to catch ServiceException… based on which I assumed (WRONG ASSUMPTION) that these exceptions can be caught across http connections too, provided we had the jar that knew what ServiceException is… I didn’t realize that the Java Exceptions don’t get propgated across http connection - a good learning :slight_smile:

While we are at it, may I ask you a question on the topic? I never got around do developing a java client using http, to invoke an IS service… when I tried yesterday, I got stuck at the authentication step. How do I pass my IS userId and password to invoke a service from my http java client? I kept getting 403 status when trying to connect in absence of a userid and password and when I changed the execute ACL of the IS service to Anonymous, I still got a 401. How do I overcome the authentication?

Thanks, Rohit


has some posts that apply to this thread. Both in reading HTTP responses and for setting authentication.

Works like a charm… thanks Rob! :slight_smile:
Interestingly… my search yesterday didn’t bring up this thread… hmmm.

Glad to be of help. I had trouble finding the post myself!

Thanks Mark,Rob and Rohit. Using pub.flow:setResponse in the catch block of the wM service was really helpful. I was able to read the message set by the setResponse service in the try block of the java program which calls the wM service.

InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = line = br.readLine();

I do not think we could read same message in catch block of java program.

Pauly Konikara