Will investigate more on Monday, but this is currently breaking in CXF 2.1.4:

context.xml:

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       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/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd";>

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

  <jaxrs:server id="cxfMapping" address="/">
    <jaxrs:serviceBeans>
      <bean class="sandbox.cxf.controller.FooController"/>
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
      <entry key="json" value="application/json"/>
      <entry key="xml" value="application/xml"/>
    </jaxrs:extensionMappings>
  </jaxrs:server>

</beans>

web.xml:

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
         version="2.4">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/context.xml</param-value>
  </context-param>

  <listener>
    
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>cxf</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/foo/*</url-pattern>
  </servlet-mapping>

</web-app>

FooController.java:

@Path("/foo/")
public class FooController {

    @GET
    @Path("/text/")
    @ProduceMime("text/plain")
        public String text() {
                return "foo";
        }

    @GET
    @Path("/response/")
    public Response response() {
        return new Response("foo");
    }

}

Response.java:

@XmlRootElement(name = "response")
@XmlAccessorType(XmlAccessType.FIELD)
public class Response {

        @XmlElement(name = "msg")
        private String message;

        public Response() {
        }

        public Response(String message) {
                this.message = message;
        }

        /**
         * @return the message
         */
        public String getMessage() {
                return message;
        }

        /**
         * @param message
         *            the message to set
         */
        public void setMessage(String message) {
                this.message = message;
        }

}

Results:

GET /foo/foo/text -> 200 "foo"
GET /foo/foo/response.xml -> 404
GET /foo/foo/response.json -> 404

But change web.xml from

  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/foo/*</url-pattern>
  </servlet-mapping>

To

  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/wtf/*</url-pattern>
  </servlet-mapping>

GET /wtf/foo/text -> 200 "foo"
GET /wtf/foo/response.xml -> 200 ...
GET /wtf/foo/response.json -> 200 ...

Bizarre...

--------------------------------------------------------------------------
This is not an offer (or solicitation of an offer) to buy/sell the 
securities/instruments mentioned or an official confirmation. Morgan Stanley 
may deal as principal in or own or act as market maker for 
securities/instruments mentioned or may advise the issuers. This is not 
research and is not from MS Research but it may refer to a research 
analyst/research report. Unless indicated, these views are the author’s and may 
differ from those of Morgan Stanley research or others in the Firm. We do not 
represent this is accurate or complete and we may not update this. Past 
performance is not indicative of future returns. For additional information, 
research reports and important disclosures, contact me or see 
https://secure.ms.com/servlet/cls. You should not use e-mail to request, 
authorize or effect the purchase or sale of any security or instrument, to send 
transfer instructions, or to effect any other transactions. We cannot guarantee 
that any such requests received via e-mail will be processed in a timely 
manner. This communication is solely for the addressee(s) and may contain 
confidential information. We do not waive confidentiality by mistransmission. 
Contact me if you do not wish to receive these communications. In the UK, this 
communication is directed in the UK to those persons who are professional and 
eligible counterparties (as defined in the UK Financial Services Authority’s 
rules).

Reply via email to