OData4j和CXF与Spring

时间:2012-08-28 14:12:56

标签: spring cxf jax-rs odata4j

我正在尝试将odata4j集成到现有的CXF服务应用程序中。 servlet已经托管了现有的肥皂和休息服务。我的应用服务器是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服务的最简洁方法是什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分: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>