无法在Glassfish 3中部署基于ejb的WSDL Web服务

时间:2011-03-31 13:14:31

标签: web-services java-ee maven glassfish

我正在尝试将从EJB生成的weeb服务部署到glassfish中,但由于某种原因,我的Web服务在Glassfish中永远不可见。 Web服务是从EJB接口定义的,如下所示:

@Remote
@WebService
public interface TemplateEJBRemote {
    public abstract @WebResult(name="found") Template find(@WebParam(name="templateId", mode=Mode.IN) Long id);
}

此EJB接口具有Local实现:

@Local
@Stateless
public class TemplateEJBImpl implements TemplateEJBRemote {
    @PersistenceContext(unitName=NamingConstants.PERSISTENCE_CONTEXT)
    private EntityManager entityManager;

    @Override
    public Template find(Long id) {
        return entityManager.find(Template.class, id);
    }
}

它们都在war模块中定义,ear模块发送给Glassfish。

这些模块会产生正确的人工制品,包括ear正确的application.xml

<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
version="6">
  <description>This is the project that will deliver a full usable
  EAR including all delivered components. All the project
  dependencies here will be included in this</description>
  <display-name>my-ear</display-name>
  <module>
    <web>
      <web-uri>my-war-0.0.1-SNAPSHOT.war</web-uri>
      <context-root>/my-war</context-root>
    </web>
  </module>
</application>

在Glassfish中部署时,我能得到的所有信息都是

E:\java-ext\glassfish3>bin\asadmin list-components --subcomponents
my-ear-0.0.1-SNAPSHOT  <ear, ejb, webservices, web>
  my-war-0.0.1-SNAPSHOT.war  <WebModule>
Command list-components executed successfully.

在我看来,如果我的网络服务真的部署了,它会显示在我的war子模块下面,不是吗?

如果没有,我该怎么做才能确保我的网络服务得到正确定义和部署?

[更新1] 为了提供更多信息,我创建了一个较小的Web服务端点, in 着名的Hello世界,编码如下:

@WebService
public class Hello {
    public String hello(String world) {
        return "Salut, "+world+" !";
    }
}

使用这个定义,它是一个完美的Glassfiosh网络服务:

enter image description here

但是,只要我把它变成豆子,就这样:

@WebService
@Stateless
public class Hello {
    public String hello(String world) {
        return "Salut, "+world+" !";
    }
}

事情变得有点不同:

enter image description here

但是,正如日志文件告诉我的那样,HelloService仍然存在:

[#|2011-03-31T17:55:55.059+0200|INFO|glassfish3.1|javax.enterprise.webservices.org.glassfish.webservices|_ThreadID=339;_ThreadName=Thread-1;|WS00019: EJB Endpoint deployed

autocat-ear-0.0.1-SNAPSHOT在地址http://perigee-567125f:8080/HelloService/Hello|#]收听

我尝试将相同的逻辑应用于我的初始bean,但是有一个infortunate结果(当然是404错误)。所以我猜其他隐藏的问题。但是哪个呢?我无从谈论。

[更新2] 为了清楚起见,我尝试部署的EJb在Glassfish控制台中不能作为Web服务显示,并且任何Web客户端都无法ping通其URL。

2 个答案:

答案 0 :(得分:0)

您需要进行更多故障排除。查看glassfish3/glassfish/domains/domain1/logs中的日志。或者如果您有独立节点或集群节点,请查看glassfish3/glassfish/nodes/<nodename>/<instancename>/logs

此外,登录管理页面“http:// localhost:4848”,默认用户名为admin,默认密码为adminadmin。在左边有一棵树,找到应用程序,那么你的耳朵应该在那里列出。单击它,您将看到模块和组件的列表。如果列出了您的Web服务,则可以单击“查看端点”。有一个内置的测试器,你也可以在那里获得wsdl URL。

更新1 : 你的hello()上没有任何@WebMethod(operationName =“blah”)。也许如果没有WebMethods,GlassFish会认为你的网络服务不可用。

更新2 :更完整的示例,了解我的网络服务是如何组合在一起的。我很确定你不必分开@WebService和@Stateless类,但我喜欢这样,因为它感觉更干净,似乎将问题分开。

<强>战:

SomePojo.java:

@WebService(targetNamespace="blah.com")
public class SomePojo {
    @EJB
    private BlahSessionLocal blahSession;

    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "user_id") Integer userId) throws Exception {
        return blahSession.hello(userId);
    }
}

ejb jar:

BlahSessionLocal.java

@Local
public interface BlahSessionLocal {
    String hello(Integer userId);
}

BlahSessionBean.java

@Stateless(mappedName = "BlahSession")
public class BlahSessionBean implements BlahSessionLocal {
    public String hello(Integer userId) {
        return "hello user " + userId);
    }
}

答案 1 :(得分:0)

我正在查看我的“EJB 3 In Action”副本,它说:

“仔细查看代码会发现@WebService端点接口看起来与远程接口类似。您可能想要将同一个接口标记为Web服务和远程接口,如下所示:

@WebService
@Remote
public interface PlaceBid {
  public Long addBid(String bidderID, Long itemID, Double dibPrice);
}

不幸的是,虽然有些供应商允许将其作为扩展,但这不是规范的一部分,使用此特定属性组合的代码将无法移植。“

您将不得不删除@Remote