2

http サービスを呼び出すと、次の例外が発生します。

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

ここまでは順調ですね。しかし、人間が読める翻訳ではなく、プログラムでその情報を取得したいと思います。ステータス コード 401 や、問題が 401 であることを 100% 証明する何かを取得するチャンスはないようです。

「根本原因」 (getCause...) を取得しようとするラッパーを作成しても機能しません。他に「原因」はありません...

私が持っているのは解析可能な文字列だけです。何か案が?

アップデート

私はそれを成し遂げる方法を見つけました - 非推奨の方法を使用して...:

...
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);
}
...

より良い解決策は、単純に HTTP-Status-Code をチェックすることですが、http-service によって受信された場合、401 は永久に消えてしまいます... :-|

4

1 に答える 1

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

于 2015-09-14T14:18:11.277 に答える