代码之家  ›  专栏  ›  技术社区  ›  kislo_metal

@ejb jar中作为@Stateless session bean的WebServices

  •  4
  • kislo_metal  · 技术社区  · 16 年前

    脚本: 创建一些web服务作为@Stateless bean,将其打包为ejbjar。结果-无法访问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时 如果不使用wsdli位置的描述,则获取空白页。

    Web服务作为它自己工作的好东西。

    问题1:在ejbjar中将web服务的wsdl文件位置描述为无状态的规则是什么。

    问题2:maven打包期间是否可以生成wsdl文件?

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

    环境:mave2、ejb3.1、glassfishv3、jax-ws 2.x

    谢谢您!

    2 回复  |  直到 15 年前
        1
  •  2
  •   Pascal Thivent    16 年前

    问题1。在ejbjar中将web服务的wsdl文件位置描述为无状态的规则是什么。

    如果通过wsdllocation属性提供,那么Metro似乎使用classloader读取wsdl,这使得 META-INF/wsdl 对于ejbjar来说,放置wsdl是一个不错的选择。

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

    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 ?

    这个 jaxws-maven-plugin:wsgen genWsdl 但我必须承认我现在完全迷路了。

    当使用Java-first方法时,要么让JAX-WS运行时在部署时动态生成WSDL,要么提供一个静态版本并使用 wsdlLocation . 但是,生成WSDL并使用 wsdl位置 在我看来没什么意义。有什么意义?文件 wsgen 从某种程度上证实了这一点:

    问题3。如何为我们有@Stateless和@EJB注释的web服务生成wsdl文件(目前我只能通过注释这些注释来生成)

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

        2
  •  0
  •   kislo_metal    16 年前

    问题出在断页检查器中。。我什么时候去 http://192.168.44.48:8181/ws.isp.SecurityService/SecurityService?wsdl 我在网页检查器里找到了空白页。

    对不起,我是假的。

    推荐文章