I have a webapp with Maven which uses Tomcat plugin for the server. The app gets compiled to .war which, when extracted, seems to contain all classes (incl. servlets) in WEB-INF/classes folder.
When the url http://localhost:8080/com.galya.crm gets hit, index.html (which is a SPA app) gets loaded normally redirecting to http://localhost:8080/com.galya.crm/#!/login/msg/notlogged
I have 4 servlets annotated in a similar manner:
#WebServlet("/restapi/login")
public class LoginController extends HttpServlet {
The problem comes when the SPA app tries to authenticate using the login servlet (shown above). I expect it to be here: http://localhost:8080/com.galya.crm/restapi/login , but I get 404 error.
Below I attached the Tomcat plugin folder that is automatically created. Work directory is empty and I'm not sure if it's OK.
Initially the webapp/WEB-INF/web.xml was auto generated and contained the following:
<!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>Archetype Created Web Application</display-name>
</web-app>
I also tried to change it to accept WebServlet annotations, but didn't work also:
<!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 xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
P.S. The app was working on another server some time ago, so the problem should be in the server configurations, not in the code itself.
Surely the cause is that the deployment descriptor must be declared to be of version 3.0. Your web.xml is still 2.3.
Remove the DOCTYPE declaration and leave the root node just as you already did:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
Tested myself, and it worked.
Related
im learning SpringMVC, and find this problem, project running well, but this is irritating
I think the web.xml is in wrong place
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
this line in web.xml is giving error.
you just have to delete these lines from the file "web.xml"
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
Working on sample spring boot application using spring-boot-starter-parent 2.0.5 with security. Main spring boot application class extends SpringBootServletInitializer. War file generated and works fine in tomcat. I deployed same war file on websphere application server and the application starts but it looks like spring boot is not getting initialized. I don't see any error in log. Is thre anything should be done for the application to initialize in websphere?
The issue is resolved by updating web.xml from
<!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>Archetype Created Web Application</display-name>
</web-app>
to latest format
<?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.xsc"
id="webApp_ID" version="3.1">
<display-name>Archetype Created Web Application</display-name>
</web-app>
I creating a web project using maven, java 7, String framework, hibernate, JPA and restful service in Eclipse. I changed the jre library in Java Build Path and also change the compiler.
but now i got error
Cannot change version of project facet Dynamic Web Module to 3.0.
thanks in advance !!!
The solution given by #enkor may work for you (Question is the same):
Cannot change version of project facet Dynamic Web Module to 3.0?
you need to change the version into web.xml you need change some configuration you can find it below:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Servlet 3.0 Web Application</display-name>
</web-app>
then Update Project.
I tried different ways to set a customized cookie name. But none is working in my configuration.
I have a Spring Boot application which is running in a standalone Tomcat.
I tried to set the cookie name in the SpringBootApplication class which is derived from SpringBootServletInitializer:
#Value("${session.cookie.name}")
private String sessionCookieName;
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.getSessionCookieConfig().setName(sessionCookieName);
super.onStartup(servletContext);
}
Also I tried to define a bean as DefaultCookieSerializer:
#Value("${session.cookie.name}")
private String sessionCookieName;
#Bean
public DefaultCookieSerializer defaultCookieSerializer(){
DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
defaultCookieSerializer.setCookieName(sessionCookieName);
return defaultCookieSerializer;
}
But nothing is working so far, I always get the default JSESSONID instead of my configured session.cookie.name
Are there any other ways to customize the cookie name?
I tried the TomcatContextCustomizer as suggested. But I think it does not work, when you deploy your application as a WAR-File because it is just for the embedded tomcat.
I resolved the issue by adding a web.xml. In the folder src/main/webapp/WEB-INF. I'm not really satisfied with this solution, because I don't want a web.xml in my spring boot application. But it works...
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true">
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
<name>CUSTOM_SESSION_ID</name>
<http-only>true</http-only>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>
If there are any better solutions let me know
In the spring boot application. You can rename the JESSIONID by setting your custom name in application.properties file as below:
server.servlet.session.cookie.name=Your_custome_name
It works fine for me.
I followed this article and created simplest websocket echo application. Although article is about Glassfish, I successfully run my app under Jetty 9, as they are using standard javax.websocket API in article.
It works just fine, but now I want to secure websocket connection. I googled around and found most examples are written as standalone Java application (with public static void main() method). They create new ConnectionFactory and starts server from their code (like here for example).
But I want to run my app under Jetty as a container, so I want to just specify some options in web.xml or something, to secure my connection. So I found this article and modified my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected resource</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<!-- https -->
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
The problem is it doesn't work. Probably because article is about Glassfish again.
How it is does NOT work:
My IDE (IDEA) shows red all tags inside <security-constraint>, that means schema validation is failed and these tags can not be contained inside <security-constraint>
When I try to open index.html over HTTPS I get error ssl_error_rx_record_too_long in browser and also there are two errors in Jetty output:
Illegal character 0x16 in state=START for buffer HeapByteBuffer
and
badMessage: 400 Illegal character 0x16 for HttpChannelOverHttp
So.. What I am doing wrong? How to make secured websocket via Jetty or application configuration?
The security constraint tag you described is mostly used for specify BASIC authentication mode in application server.
I guess you want to enable HTTPS and not authentication. For enabling HTTPS you may follow this article: https://wiki.eclipse.org/Jetty/Howto/Configure_SSL