2012-01-31 74 views
1

我使用CXF框架開發了JAX-RS webservices,並且我部署在Jboss6中。 雖然我嘗試使用以下URL http://localhost:8080/UPCServiceLayer/services/upcLineOfBusiness/create從我的HTML頁面來訪問應用程序(使用POST方法只)我在服務器控制檯CXF-RS拋出找不到與操作匹配請求路徑/ create的操作,

No operation matching request path /create is found,

下得到下面的錯誤是我cxf.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd 
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> 
    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
    <import resource="classpath:../upc-spring-dao.xml" /> 
    <jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness"> 
     <jaxrs:serviceBeans> 
      <ref bean="upcLineOfBusinessRestService" /> 
     </jaxrs:serviceBeans> 
    </jaxrs:server> 
    <bean id="upcLineOfBusinessRestService" 
     class="com.tecnotree.upc.services.restservices.impl.UpcLineOfBusinessRestServiceImpl"> 
     <property name="upcLineOfBusinessDao"> 
      <ref bean="upcLineOfBusinessDao" /> 
     </property> 
     <property name="upcUserDao"> 
      <ref bean="upcUserDao" /> 
     </property> 
    </bean> 
</beans> 

下面是我的資源類

@Path("/") 
public classUpcLineOfBusinessRestService { 
    @POST 
    @ConsumeMime("application/xml") 
    @ProduceMime("application/xml") 
    @Path("/create") 
    public UpcLineOfBusinessEntity createUpcLineOfBusinessEntity(
      UpcLineOfBusinessEntity upcLineOfBusinessEntity) 
      throws GenericUpcException 

和我在web.xml文件中聲明CXF的servlet也。

<servlet> 
      <servlet-name>CXFServlet</servlet-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>/services/*</url-pattern> 
     </servlet-mapping> 

請幫我

回答

1

我有些驚訝地看到那裏有@ProduceMime@ConsumeMime註釋;目前的風格是使用@Produces@Consumes代替(來自JAX-RS標準)。這很重要,因爲CXF使用內容類型註釋作爲其方法匹配過程的一部分,這可能會使事情無法匹配(並因此產生令人困惑的錯誤消息)。 (另外,你確定你在向服務器發送「application/xml」嗎?得到這個錯誤,你也會有不匹配的錯誤。嘗試調高服務器上的日誌級別以查看它的實際內容在匹配期間嘗試做;這有助於跟蹤這類問題,但不能在默認情況下,因爲它是非常嘮叨。)

+1

謝謝您的回答。我使用@ProduceMime的原因是Jboss6與cxf2.3.1捆綁在一起,在這個版本中我只能使用jsr311-api-0.8-1.3.0.jar。這個jar文件只有MIME類型的舊類。如何將數據發佈爲application/xml?我需要將該HTML頁面的內容類型設置爲application/xml?在這裏,我使用純HTML表單來發布數據。 – Dilip 2012-01-31 10:22:44

+0

暫時我只是將Consumes註釋值更改爲application/x-www-form-urlencoded。之後,我試圖使用HTML表單POST方法調用該資源,但我得到一個新的異常沒有消息正文讀取器找到請求類:UpcLineOfBusinessEntity,ContentType:應用程序/ x-www-form-urlencoded。基於谷歌我明白,我們需要在CXF中配置JAXB。所以我在cxf.xml中添加了以下代碼...... – Dilip 2012-01-31 11:06:58

+0

\t \t <屬性名=」 marshallerProperties」 REF = 「propertiesMap」/> \t \t \t \t <條目鍵= 「jaxb.formatted.output」> \t \t \t <值類型= 「java.lang.Boolean中的」>真 \t \t \t但我正在逐漸同樣的異常。請幫我 – Dilip 2012-01-31 11:07:19

0

這四行看行對我說:

<url-pattern>/services/*</url-pattern> 

<jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness"> 

@Path("/") 

@Path("/create") 

Togehter他們應該匹配/services/upcLineOfBusiness/create

+0

感謝您的快速答案。如果我嘗試打開一個WADL文件http:// localhost:8080/UPCServiceLayer/services/upcLineOfBusiness?_wadl&_type = xml我收到以下異常15:36:55,206 WARN [org.apache.cxf.jaxrs.utils.JAXRSUtils]。沒有找到匹配請求路徑/的操作,ContentType:*/*,Accept:text/html,application/xhtml + xml,application/xml; q = 0.9,*/*; q = 0.8。 15:36:55,231 WARN [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] WebApplicationException已被捕獲:無可用原因 – Dilip 2012-01-31 10:08:03

相關問題