0

I am trying to deploy a jetty server. The deployment is happening fine and I am able to access all the resources. But I am unable to access the files in web root directory, specifically index.html. Here are my configurations:

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--REST SERVLET-->
    <!--This need to add so that spring is called before jersey-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--This need to add so that jersey knows where is spring config-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/conf/my_spring/spring*.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <!-- Register resources and providers under com.altinn.rest package. -->
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>
                com.altin.api;com.fasterxml.jackson.jaxrs.json
            </param-value>
        </init-param>
        <init-param>
            <!--http://howtodoinjava.com/jersey/jersey-file-upload-example/-->
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Directory Structure:

.
├── build.gradle
├── java-api.iml
├── resources
│   └── conf
│       └── my_spring
│           └── spring-config.xml
├── src
│   └── com
│       └── altin
│           └── api
│               └── base
│                   ├── AuthenticationFilter.java
│                   ├── PingRestAPI.java
│                   └── config
│                       └── spring
│                           └── ApiSpringConfig.java
└── web
    ├── WEB-INF
    │   └── web.xml
    └── index.html

The extracted war looks like:

$ tree -L 2
.
├── META-INF
│   └── MANIFEST.MF
├── WEB-INF
│   ├── classes
│   ├── lib
│   └── web.xml
└── index.html

application.wadl looks like:

enter image description here

According to me Context Path is / as I marked it to be root in intellij and also I am able to access the ping resource on /.

But I am unable to access index.html:

Abhishek Gupta
  • 6,465
  • 10
  • 50
  • 82

1 Answers1

2

I got the issue. The issue is

<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

in web.xml. This clause was forwarding all the requests to jersey servlet (ServletContainer). I just changed the rule to api/* and index.html started working.

Abhishek Gupta
  • 6,465
  • 10
  • 50
  • 82