2

I get the following exception when calling the http service:

com.wm.app.b2b.server.ServiceException
Message: com.wm.net.NetException: [ISC.0064.9314] Authorization Required: Unauthorized

So far, so good. But I would like to get that information programatically - not the human readable translation. I seem to have no chance to get the status code 401 or something that is a 100% proof that the problem is a 401.

Writing a wrapper that tries to get the "root cause" (getCause...) does not work. There is no other "cause"...

All I have are parsable strings. Any idea?

UPDATE

I found a way to get it done - using a deprecated method...:

...
try {
    output =
        Service.doInvoke( "my.package.authentication", "checkAuthentication", input );
} catch( final ServiceException sEx ) {

    // if this is deprecated: how to we have to handle this in future?
    final Throwable wrappedEx = sEx.getWrappedException();

    // return early
    if(null == wrappedEx || !NetException.class.isInstance(wrappedEx) ) {
        throw sEx;
    }

    // process the net exception
    final NetException nEx = (NetException)wrappedEx;
    final String responseBody = convertStreamToString(nEx.getResponseInputStream());

    // process the returned body wrapped by the net exception
    final Gson gson = new Gson();
    final ErrorData errorData = gson.fromJson(responseBody, ErrorData.class);

    // check if the problem is an invalid token
    tokenIsInvalid = errorData.code.equals(INVALID_TOKEN_EXCEPTION__CODE_STRING);

} catch( Exception e ) {
    // wrap the exception in a service exception and throw it
    throw new ServiceException(e);
}
...

A better solution would simply check the HTTP-Status-Code - but a 401 is gone forever if recieved by the http-service... :-|

eventhorizon
  • 2,977
  • 8
  • 33
  • 57

1 Answers1

1

Hi usually that kind of error is due to the Execution ACL that is wrongly set on your web service (assuming that your http service is actually a SOAP web service).

With webMethods Designer 9.2,

  1. Open your web service descriptor
  2. In the properties, click on "Permissions"
  3. Set "Execution ACL" to "Anynomous"

If what you're exposing is actually a REST web service then the process is pretty much the same. The "Permission" property will be in your flow service's properties.

Hope this helps

TchiYuan
  • 4,258
  • 5
  • 28
  • 35
  • Hi and THX for your post! But my problem is not the Exception itself. I know why it is thrown. I would like to get the information in my code - fool-proof - without string parsing... :-) – eventhorizon Sep 14 '15 at 15:17
  • You cannot TRY/CATCH the exception in your flow service because it doesn't even reach the flow service. It's being rejected by the integration server before it reaches the flow service. The only way is to modify the client application to process that kind of error. – TchiYuan Sep 14 '15 at 15:25
  • Nope. Please look at my example (UPDATE). I wrapped my functionality/the http call by a java service... ugly - but it works. – eventhorizon Sep 14 '15 at 15:44
  • When you invoke this service "my.package.authentication:checkAuthentication" from a flow service (instead of java service), I'm really surprised that you're not getting the 401 status in the Catch sequence using "pub.flow:getLastError" – TchiYuan Sep 14 '15 at 21:28
  • :-) This was cleared in one of my last question-answer-games between the SAG an me: http://stackoverflow.com/questions/30838842/webmethods-pub-client-http-throws-error-on-401 – eventhorizon Sep 15 '15 at 06:33
  • Wow, interesting! Sad but interesting. – TchiYuan Sep 15 '15 at 18:35