@WebServices 作为 ejb jar 中的 @Stateless 会话 bean
设想: 创建一些 Web 服务作为 @Stateless bean,将其打包为 ejb jar。结果 - 无法访问 wsdl 文件。
目标:我想使用 @WebServices 作为 @Stateless 会话,使用 ejb jar 打包和可访问的 wsdl 文件形式 web。
网络服务:
@Stateless
@WebService(serviceName = "ws.isp.SecurityService", wsdlLocation = "META-INF/wsdl/SecurityService.wsdl")
public class SecurityService{
@EJB
private Kerberos factory;
@EJB
private UsersServiceBean uService;
public SecurityService() {
}
@WebMethod
@WebResult(name = "SimpleResponse")
public SimpleResponse LogOut(
@WebParam(name = "sessionUUID", targetNamespace = "https://secure.co.ua/ws/")
String sessionUUID
) {
SimpleResponse resp = new SimpleResponse();
try{
factory.removeSession(sessionUUID);
resp.setError(WSErrorCodes.SUCCESS);
}catch (Exception e){
e.printStackTrace();
resp.setError(WSErrorCodes.UNRELOSVED_ERROR);
}
return resp;
}
@WebMethod
public MySession logIn(
@WebParam(name = "username", targetNamespace = "https://secure.co.ua/ws/")
String username,
@WebParam(name = "password", targetNamespace = "https://secure.co.ua/ws/")
String password){
MySession result = new MySession();
try {
UserSession us = factory.creatSession(uService.getUser(username, password).getId());
result.setSessionID(us.getSessionUUID().toString());
result.setError(WSErrorCodes.SUCCESS);
} catch (NullPointerException e){
e.printStackTrace();
result.setError(WSErrorCodes.UNRELOSVED_USER);
} catch (Exception e){
e.printStackTrace();
result.setError(WSErrorCodes.UNRELOSVED_ERROR);
}
return result;
}
}
在这种情况下我得到
无效的 wsdl 请求 http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService
当我尝试访问 wsdl 时 如果不使用 wsdlLocation 的描述,我会得到空白页面。
网络服务本身运行良好。
Q1:在 ejb jar 中将 Web 服务的 wsdl 文件位置描述为无状态的规则是什么?
Q2:maven打包时可以生成wsdl文件吗?
Q3:如何为具有 @Stateless 和 @EJB 等注释的 Web 服务生成 wsdl 文件(目前我只能通过注释这些注释来生成它)
环境:mave 2、ejb 3.1、glassfish v3、jax-ws 2.x
谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果通过 wsdllocation 属性提供,Metro 似乎会使用类加载器读取 WSDL,这使得 EJB JAR 的
META-INF/wsdl
成为放置 WSDL 的不错选择。我使用以下 EJB 进行了测试:
WSDL 位于我的 EJB maven 项目中的 src/main/resources/META-INF/wsdl/ 中。
访问 http://localhost:8080/HelloServiceService/HelloService?wsdl 显示 my WSDL(而不是动态生成的)。
所以问题是,您是否尝试过 http://192.168.44.48:8181/ ws.isp.SecurityService/SecurityService?wsdl?
jaxws-maven-plugin: wsgen
目标可以做到这一点(请参阅genWsdl
参数),但我必须承认我现在完全迷失了。使用 Java 优先方法时,您可以让 JAX-WS 运行时在部署时动态生成 WSDL,或者提供静态版本并使用
wsdlLocation
。然而,生成 WSDL 并使用wsdlLocation
在我看来没有多大意义。有什么意义? wsgen 的文档以某种方式证实了这一点:默认情况下,wsgen 不会生成 WSDL 文件。该标志是可选的,它将导致 wsgen 生成 WSDL 文件,通常仅用于开发人员可以在部署端点之前查看 WSDL。
我不明白这个问题,也不明白为什么你想生成WDSL(见上文)。
If provided via the wsdllocation attribute, it seems that Metro reads WSDLs using the classloader which makes
META-INF/wsdl
of the EJB JAR a decent choice to place WSDLs.I tested on my side with the following EJB:
The WSDL being located in
src/main/resources/META-INF/wsdl/
in my EJB maven project.And accessing http://localhost:8080/HelloServiceService/HelloService?wsdl shows my WSDL (and not a dynamically generated one).
So the question is, did you try http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService?wsdl?
The
jaxws-maven-plugin:wsgen
goal can do that (see thegenWsdl
parameter) but I must admit that I'm completely lost now.When using a Java-first approach, you either let the JAX-WS runtime generate the WSDL dynamically at deploy time ~or~ you provide a static version and use
wsdlLocation
. However, generating the WSDL and using thewsdlLocation
doesn't make much sense IMO. What's the point? The documentation of wsgen somehow confirms this:By default wsgen does not generate a WSDL file. This flag is optional and will cause wsgen to generate a WSDL file and is usually only used so that the developer can look at the WSDL before the endpoint is deploy.
I don't understand the question and I don't understand why you want to generate the WDSL (see above).
问题出在损坏的页面检查器中..所以当我转到 http://192.168 .44.48:8181/ws.isp.SecurityService/SecurityService?wsdl 我在 Web 检查器中看到空白页。
抱歉假的。
problem was in broken page inspector.. so whene I go to http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService?wsdl I got blank page in web inspector.
sorry for fake.