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

时间:2010-05-13 09:16:18

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

方案: 创建一些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的描述,我会得到空白页。

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

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

Q2:在maven打包期间是否可以生成wsdl文件?

问题3:如何为Web服务生成wsdl文件,其中我们有@Stateless和@EJB这样的注释(目前我只能通过注释那些注释来生成它)

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

谢谢!

2 个答案:

答案 0 :(得分:2)

  

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会显示我的 WSDL(而不是动态生成的WSDL)。

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

  

Q2。是否可以在maven包装期间生成wsdl文件?

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

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

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

  

Q3。如何为Web服务生成wsdl文件,其中我们有@Stateless和@EJB这样的注释(目前我只能通过注释那些注释来生成它)

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

答案 1 :(得分:0)

问题发生在页面检查器坏了..当我去http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService?wsdl时,我在网络检查员那里得到了空白页。

抱歉。