调用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 - 但是如果 401 被 http-service 接收到,那么 401 就永远消失了......:-|
最佳答案
您好,这种错误通常是由于在您的 Web 服务上错误设置了执行 ACL(假设您的 http 服务实际上是一个 SOAP Web 服务)。
使用 webMethods Designer 9.2,
- 打开您的网络服务描述符
- 在属性中,单击“权限”
- 将“执行 ACL”设置为“匿名”
如果您公开的实际上是一个 REST 网络服务,那么该过程几乎相同。 “权限”属性将在您的流服务的属性中。
希望对你有帮助
关于java - webMethods 获取 ServiceException 的根本原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561069/