1

我正在尝试将 odata4j 集成到现有的 CXF 服务应用程序中。servlet 已经托管了一个现有的soap and rest 服务。我的应用服务器是tomcat。

我的 web.xml:

<servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
        <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

现有的soap 和rest 服务是通过jaxrs 和jaxws 配置文件配置的。

我创建了我的 JPA OData Producer Factory:

public class CmecfOdataProducerFactoryImpl implements ODataProducerFactory {
    String namespace = "MyOData";
    private int maxResults = 100;
    @Override
    public ODataProducer create(Properties prprts) {

        String persistenceName = null;
        try {
            persistenceName = ServiceLocator.getInstance().getResource("java:/comp/env/persistenceUnitName", String.class);
        } catch (Exception ex) {
            Logger.getLogger(CmecfOdataProducerFactoryImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceName);
        JPAProducer producer = new JPAProducer(emf, namespace, maxResults);

        return producer;
    }
}

包含此 odata 服务的最简洁方法是什么?

谢谢你的帮助!

4

1 回答 1

0

只需在 web.xml 文件中添加您的 odata JPA 工厂即可。下面的 web.xml 配置将正常工作,正确放置您的 JPA 工厂包。

<servlet>     
<servlet-name>JPAFactory</servlet-name>     
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>     
<init-param>       
<param-name>javax.ws.rs.Application</param-name>       
<param-value>org.odata4j.jersey.producer.resources.ODataApplication</param-value>     
</init-param> 
<init-param> 
<param-name>odata4j.producerfactory</param-name> 
<param-value>**your packageName**.CmecfOdataProducerFactoryImpl </param-value> 
</init-param> 
<load-on-startup>1</load-on-startup>   
</servlet>   
<servlet-mapping>     
<servlet-name>JPAFactory</servlet-name>     
<url-pattern>/jpaproducer.svc/*</url-pattern>   
</servlet-mapping>
于 2013-04-05T12:31:44.773 回答