maven-2 - @WebServices 作为 ejb jar 中的 @Stateless session bean

标签 maven-2 wsdl jax-ws java-ee-6 ejb-3.1

设想:
创建一些 Web 服务作为 @Stateless bean,将其打包为 ejb jar。结果 - 无法访问 wsdl 文件。

目标:我想将@WebServices 用作@Stateless session ,使用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;
    }

}

在这种情况下,我得到

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



当我尝试访问 wsdl 时
如果不使用 wsdlLocation 的描述,我会得到空白页。

Web 服务,因为它自我运作良好。

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

Q2:maven打包时可以生成wsdl文件吗?

Q3:如何为我们有@Stateless和@EJB这样的注解的web服务生成wsdl文件(目前我只能通过注释这些注解来生成它)

环境:mave 2、ejb 3.1、glassfish v3、jax-ws 2.x

谢谢!

最佳答案

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



如果通过 wsdllocation 属性提供,Metro 似乎使用使 META-INF/wsdl 的类加载器读取 WSDL。 EJB JAR 是放置 WSDL 的不错选择。
我使用以下 EJB 进行了测试:
@Stateless
@WebService(wsdlLocation = "META-INF/wsdl/HelloService.wsdl")
public class HelloService {
    public String hello(String name) {
        return "Hello, " + name + "!";
    }
}

WSDL 位于 src/main/resources/META-INF/wsdl/在我的 EJB Maven 项目中。

并访问 http://localhost:8080/HelloServiceService/HelloService?wsdl显示 我的 WSDL(而不是动态生成的)。

所以问题是,你有没有尝试过 http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService?wsdl ?

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



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

当使用 Java-first 方法时,你要么让 JAX-WS 运行时在部署时动态生成 W​​SDL ~或者~你提供一个静态版本并使用 wsdlLocation .但是,生成 WSDL 并使用 wsdlLocation IMO 没有多大意义。重点是什么? wsgen 的文档以某种方式证实了这一点:

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

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)



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

关于maven-2 - @WebServices 作为 ejb jar 中的 @Stateless session bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2825578/

相关文章:

java - 使用 HTTPS 的网络服务

web-services - JAX-WS Web 服务的身份验证和授权的正确方法?

java - jax-ws:设置请求的内容类型

java - Maven:如何从命令行更改目标目录的路径?

java - 如何读取部署在Tomcat中的未分解war文件中的资源文件?

ssl - apache Camel cxf https 不工作

java - SOAP 的 WSDL 和 REST 的 WSDL 以及基于 JSON 的 REST

SpringBeanAutowiringSupport 与 WebApplicationContextUtils

java - 我如何通过 Maven "run"应用程序?

java - 何时使用 maven 依赖管理和依赖