почему этот сервлет hello world "запрещен" на Wildfly? - PullRequest
0 голосов
/ 10 июня 2019

Как мне развернуть WAR в wildfly и вызвать NewServlet с локального хоста? Я получаю сообщение forbidden от Wildfly:

thufir@dur:~$ 
thufir@dur:~$ lynx http://localhost:8080/wildflyMaps  --dump
   Forbidden
thufir@dur:~$ 

структура войны:

thufir@dur:~/NetBeansProjects/wildflyMaps$ 
thufir@dur:~/NetBeansProjects/wildflyMaps$ gradle clean war

BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
thufir@dur:~/NetBeansProjects/wildflyMaps$ 
thufir@dur:~/NetBeansProjects/wildflyMaps$ cd build/libs/
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ 
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ ll
total 2668
drwxr-xr-x 2 thufir thufir    4096 Jun  9 19:05 ./
drwxr-xr-x 6 thufir thufir    4096 Jun  9 19:05 ../
-rw-r--r-- 1 thufir thufir 2723106 Jun  9 19:05 wildflyMaps.war
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ 
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ jar -xf wildflyMaps.war 
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ 
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ tree
.
├── META-INF
│   └── MANIFEST.MF
├── WEB-INF
│   ├── classes
│   │   ├── net
│   │   │   └── bounceme
│   │   │       └── dur
│   │   │           └── wildfly
│   │   │               └── war
│   │   │                   └── maps
│   │   │                       └── NewServlet.class
│   │   └── wildflyMaps
│   │       └── App.class
│   └── lib
│       ├── animal-sniffer-annotations-1.17.jar
│       ├── checker-qual-2.5.2.jar
│       ├── error_prone_annotations-2.2.0.jar
│       ├── failureaccess-1.0.1.jar
│       ├── guava-27.0.1-jre.jar
│       ├── j2objc-annotations-1.1.jar
│       ├── jsr305-3.0.2.jar
│       ├── listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
│       └── servlet-api-2.5.jar
└── wildflyMaps.war

11 directories, 13 files
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ 
thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0

thufir@dur:~/NetBeansProjects/wildflyMaps/build/libs$ 

образец сервлета:

package net.bounceme.dur.wildfly.war.maps;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NewServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet NewServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}

Wildfly показывает развернутую войну:

management console for wildfly

возможно, требуется конфигурация типа web.xml? Но разве web.xml не устарело?

...