2012-08-28 88 views
1

我正在嘗試將odata4j集成到現有的CXF服務應用程序中。該servlet已經託管了現有的肥皂和休息服務。我的應用程序服務器是tomcat。OData4j和CXF與彈簧

我的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製片廠:

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服務的乾淨的方式?

感謝您的幫助!

回答

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>