简体   繁体   中英

unable to invoke rest cxf service

I am new to RESTful services and I followed the tutorial here .

My deployment descriptor web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
   <display-name>RestDemo</display-name>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:com/example/rest/cxf.xml</param-value>
   </context-param>
   <listener> 
     <listener-class>
       org.springframework.web.context.ContextLoaderListener
     </listener-class>
   </listener>
   <servlet>
     <servlet-name>CXFServlet</servlet-name>
       <servlet-class>
         org.apache.cxf.transport.servlet.CXFServlet
       </servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>CXFServlet</servlet-name>
     <url-pattern>/services/*</url-pattern>
   </servlet-mapping>
</web-app>

The cxf.xml descriptor:

<beans xmlns:jaxrs="http://cxf.apache.org/jaxrs"   
       xmlns:util="http://www.springframework.org/schema/util"          
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns="http://www.springframework.org/schema/beans"   
       xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/util
             http://www.springframework.org/schema/util/spring-util-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-servlet.xml" />
  <jaxrs:server address="/" id="connectionService">
    <jaxrs:serviceBeans>
      <ref bean="order"/>
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
      <entry key="xml" value="application/xml">
      </entry>
    </jaxrs:extensionMappings>
  </jaxrs:server>
  <bean class="com.example.rest.OrderInfoImpl" id="order"></bean>
</beans>

My Rest service Interface OrderInfo.java :

package com.example.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/Order/")
public interface OrderInfo {

  @GET
  @Produces("application/xml")
  @Path("{orderId}")
  public Order getOrder(@PathParam("orderId") int officeId);

  @GET
  @Produces("application/xml")
  @Path("All")
  public OrderList getAllOrders();

}

The implementation OrderInfoImpl.java .

When I am trying to run localhost:8080/RestDemo/services?_wadl , localhost:8080/RestDemo/services/order/1 I get 404 Error .

The Rest endpoint should be case sensitive, assuming that your project is set correctly (Checkout you Order service implementation since I can't see it in the OP), you should be accessing below endpoint:

  • localhost:8080/RestDemo/services/Order/1

instead of:

  • localhost:8080/RestDemo/services/order/1

Note the O uppercase letter in the order path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM