@WebServices 作为 ejb jar 中的 @Stateless 会话 bean

发布于 2024-09-02 02:31:01 字数 2389 浏览 3 评论 0 原文

设想: 创建一些 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

谢谢你!

Scenario:
Creating some web service as @Stateless bean, package it as ejb jar. Result - can`t access to wsdl file.

Goal: I want to use @WebServices as @Stateless session using ejb jar packaging with accessible wsdl file form web.

Web service:

@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;
    }

}

In this case I getting

Invalid wsdl request
http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService

when I try to access to wsdl
and if do not use description of wsdlLocation I getting blank page.

Web service as it self working good.

Q1: what is the rule of describing wsdl file location for web services as stateless in ejb jar.

Q2: is it possible to generate wsdl file during maven packaging ?

Q3: how to generate wsdl file for web service where we have such annotation as @Stateless and @EJB (currently I can generate it only by commenting those annotations)

environment: mave 2, ejb 3.1, glassfish v3, jax-ws 2.x

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他不在意 2024-09-09 02:31:01

Q1。在 ejb jar 中将 Web 服务的 wsdl 文件位置描述为无状态的规则是什么。

如果通过 wsdllocation 属性提供,Metro 似乎会使用类加载器读取 WSDL,这使得 EJB JAR 的 META-INF/wsdl 成为放置 WSDL 的不错选择。
我使用以下 EJB 进行了测试:

@Stateless
@WebService(wsdlLocation = "META-INF/wsdl/HelloService.wsdl")
public class HelloService {
    public String hello(String name) {
        return "Hello, " + name + "!";
    }
}

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

第二季度。 maven打包时可以生成wsdl文件吗?

jaxws-maven-plugin: wsgen 目标可以做到这一点(请参阅genWsdl 参数),但我必须承认我现在完全迷失了。

使用 Java 优先方法时,您可以让 JAX-WS 运行时在部署时动态生成 W​​SDL,或者提供静态版本并使用 wsdlLocation。然而,生成 WSDL 并使用 wsdlLocation 在我看来没有多大意义。有什么意义? wsgen 的文档以某种方式证实了这一点:

默认情况下,wsgen 不会生成 WSDL 文件。该标志是可选的,它将导致 wsgen 生成 WSDL 文件,通常仅用于开发人员可以在部署端点之前查看 WSDL。

第三季度。如何为带有 @Stateless 和 @EJB 等注释的 Web 服务生成 wsdl 文件(目前我只能通过注释这些注释来生成它)

我不明白这个问题,也不明白为什么你想生成WDSL(见上文)。

Q1. what is the rule of describing wsdl file location for web services as stateless in ejb jar.

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:

@Stateless
@WebService(wsdlLocation = "META-INF/wsdl/HelloService.wsdl")
public class HelloService {
    public String hello(String name) {
        return "Hello, " + name + "!";
    }
}

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?

Q2. is it possible to generate wsdl file during maven packaging ?

The jaxws-maven-plugin:wsgen goal can do that (see the genWsdl 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 the wsdlLocation 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.

Q3. how to generate wsdl file for web service where we have such annotation as @Stateless and @EJB (currently I can generate it only by commenting those annotations)

I don't understand the question and I don't understand why you want to generate the WDSL (see above).

在梵高的星空下 2024-09-09 02:31:01

问题出在损坏的页面检查器中..所以当我转到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文