0

I am trying to deploy a web service in Tomcat7 using maven.

Below I provide some configuration info:

web.xml

...
<servlet-mapping>
   <servlet-name>CXFServlet</servlet-name>
   <url-pattern>/services/*</url-pattern>
</servlet-mapping>
...

pom.xml

...
<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <server>TomcatServer</server>
                    <path>/services/userinfo</path>
...

Given the <url-pattern>/services/*</url-pattern> and <path>/services/userinfo</path> configuration, the URL http://localhost:8080/services/userinfo shows 404.

If using instead <url-pattern>/*</url-pattern> everything works as expected (i.e. http://localhost:8080/services/userinfo shows the list of available methods).

The question:

Why /services/* doesn't work in my case?

Eugen
  • 2,292
  • 3
  • 29
  • 43

1 Answers1

1

The path in your tomcat-maven-plugin configuration

<path>/services/userinfo</path>

defines where you are deploying the webapp (the context root). In this case, you are deploying it to

http://localhost:8080/services/userinfo

Check out the webapps directory in your Tomcat installation.

Since you are defining the CXFServlet mapping as /services/*, the CXF service list would show at

http://localhost:8080/services/userinfo/services/

When you re-defined the mapping to /*, it just appeared to work as expected, but that was only because the context root you used and the service listing path you expected were the same.

Patrick
  • 2,102
  • 15
  • 11
  • The full URL for my service is `http://localhost:8080/services/userinfo/UserInfoService` (I didn't show the `cxf-servlet.xml` since it doesn't play a role here). The service list appears at: `http://localhost:8080/services/userinfo/`. If I understand correctly the specification of wildcard `/services/*` will work for any subdirectory under the `services` path. BTW the generated war has the name `services#userinfo.war`. – Eugen Aug 11 '13 at 17:14
  • 1
    If you change the mapping back to `/services/*`, does the service listing show at `http://localhost:8080/services/userinfo/services`? That is what I would expect. The services#userinfo.war name is what maps your webapp to `http://localhost:8080/services/userinfo/`, regardless of CXF or the servlet mapping. – Patrick Aug 11 '13 at 17:21
  • Yes it does. I thought that the matching starts immediately after the port number. – Eugen Aug 11 '13 at 18:48
  • The matching starts after the webapp's context root, which for your application is `/services/userinfo/`. If you want this application to run as Tomcat's ROOT context (i.e right at `http://localhost:8080/`), you will need configure Tomcat for that. – Patrick Aug 11 '13 at 18:54
  • 1
    [This link](http://stackoverflow.com/questions/715506/tomcat-6-how-to-change-the-root-application) might help if you have questions changing the ROOT webapp. – Patrick Aug 11 '13 at 19:05