2

调用 http 服务时出现以下异常:

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

到目前为止,一切都很好。但我想以编程方式获取这些信息 - 而不是人类可读的翻译。我似乎没有机会获得状态码 401 或 100% 证明问题是 401 的东西。

编写试图获取“根本原因”(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

嗨,通常这种错误是由于在您的 Web 服务上错误设置的执行 ACL(假设您的 http 服务实际上是一个 SOAP Web 服务)。

使用 webMethods Designer 9.2,

  1. 打开您的 Web 服务描述符
  2. 在属性中,单击“权限”
  3. 将“执行 ACL”设置为“匿名”

如果您公开的实际上是 REST Web 服务,那么过程几乎相同。“权限”属性将在您的流服务的属性中。

希望这可以帮助

于 2015-09-14T14:18:11.277 回答