<async-supported>true</async-supported> in web.xml - jersey

Someone help me plss, i got this error when i put async-supported tag in web.xml:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-role-ref}' is expected.
this is my web.xml
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.yeditepeim.messenger.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>

The web.xml goes of an XML schema. If you're not familiar with XML schemas, they describe what elements and attributes an XML document can contain in order to be a valid instance of that schema.
That being said, you can see in the schema location the version of the schema file being used, i.e. ...web-app_2_5.xsd. This means that your web.xml is going to be based on that version of the schema, which maps to that version of the servlet specification, which in your case is 2.5. The problem with this is that async is not introduced to the servlet spec until 3.0. So there is no element specification in the 2.5 schema. So when the xml is being validated, it's saying that not such element <async-supported> is allowed in the document, as it doesn't comply to the schema.
To fix it, just change the version to 3.0 and the schema file to 3_0
<!-- change to 3.0 -->
<web-app 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">
<!-- change to 3_0 -->

Related

Why does my Spring MVC application not work when changing the server mapping?

I'm working on the Spring MVC "FitnessTracker" application outlined on Pluralsight. Below is my "web.xml" file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/FitnessTracker/*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
The above makes Tomcat generate a bunch of exceptions, starting with
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
But when I change what's between the <url-pattern> tag to *.html, it works fine. Why is that?
Note: My goal is to try to make my app's controller run when I type /FitnessTracker/greeting.html, instead of /greeting.html. I am using Intellij IDEA, and doing Maven project with Tomcat 7.0 as my server.
Application runs # http://localhost:9090/FitnessTracker/greeting.html URL . FitnessTracker is application root context and greeting.html is mapped to Hello controller method. Please see below.
Could you please post the web.xml and controller mapping .
The original code runs at the URL - http://localhost:8080/FitnessTracker/greeting.html. SO I am not sure why you need to change web.xml for that.
Also the URL pattern you are trying to use "/FitnessTracker/*.html" is not valid.
More details here.
https://stackoverflow.com/a/5441862/6352160

Integrating Crystal Report with Spring Framework - JSP

I am integrating my Crystal Report code with Spring Framework.
Initially I had developed simple web application with only jsps (without spring feature) and CRystal Reports are rendering properly. I had tested it with parameters and DB connection Also.
Now I am trying to integrate it with Spring framework. I did all necessary set-up.
Reports are rendering properly, with parameters and DB connection. But when I click on subreport link I am getting error.
"The viewer is unable to connect with the CrystalReportViewerServlet
that handles asynchronous requests. Please ensure that the Servlet and
Servlet-Mapping have been properly declared in the application's
web.xml file."
Also, images on reports are not displaying (showing cross).I tried to search on different forums but no luck.
Here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>CRWeb1</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>crystal_image_uri</param-name>
<param-value>/reports/crystalreportviewers</param-value>
</context-param>
<context-param>
<param-name>crystal_image_use_relative</param-name>
<param-value>reports</param-value>
</context-param>
<servlet>
<description></description>
<display-name>reports</display-name>
<servlet-name>reports</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>reports</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<display-name>reports</display-name>
<servlet-name>CrystalReportViewerServlet</servlet-name>
<servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CrystalReportViewerServlet</servlet-name>
<url-pattern>/CrystalReportViewerHandler</url-pattern>
</servlet-mapping>
</web-app>
Thanks,
Sarika

My servlet stopped receive post params after adding CXF web service to the project

Good day, I created simple DynamicWebProject containing servlet Capture extending HttpServlet which overrides method doPost. When I sent a post request to this servlet it successfuly retrieved all posted parameters until I added simple Apache CXF Web Service. The CXF web service works but since I added it my servlet Capture isn't able to receive any posted parameters. When I post data to URL http://x.x.x.x:8080/capture the Capture.doPost method is called but no parameters are passed to it. When I comment out the listener tag it starts work again. Please could you advise why is this happening and how can I fix it? Many thanks in advance. Vojtech
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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" id="WebApp_ID" version="3.0">
<display-name>MyApp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/cxf.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Capture</servlet-name>
<servlet-class>myapp.servlet.Capture</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Capture</servlet-name>
<url-pattern>/capture</url-pattern>
</servlet-mapping>
</web-app>
And the cxf.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="decodeWS" implementor="myapp.ws.decoder.DecoderServiceImpl" address="/decode">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
EDIT: I resolved this issue by changing order of servlet mappings. If CaptureParts is on the first place then it works. But I still don't understand why the order matters.
<servlet-mapping>
<servlet-name>CaptureParts</servlet-name>
<url-pattern>/captureParts</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
You have
<param-value>WEB-INF/cfx.xml</param-value>
Should it be cxf.xml instead?

Can I initialize Spring via Tomcats web xml (../webapps/WEB-INF/web.xml)?

Thanks to the UNUSUAL deployment of Tomcat6 I need to deploy my web app that is using the Spring & Hibernate on a server where access to the WAR deployment's web.xml at /webapps/MyDeployment/WEB-INF/web.xml is not allowed.
So I need to know if such a deployment is even possible, Where we will initialize the spring framework in the serever's web.xml at /webapps/WEB-INF/web.xml and not use the WAR's web.xml ?
Below is the WAR's web.xml that I am currently using at my environment,
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>abcd</display-name>
<!--Here we specify about the DispatcherServlet class in the Web Deployment
Descriptor -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.abcd</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.xyz</url-pattern>
<url-pattern>*.pqr</url-pattern>
</servlet-mapping>
Unfortunately changes in the Tomcat configuration is not allowed,
Any suggestions will be highly appreciated.
Thank you for all your help, but we ended up solving the problem by asking the server administrator to lift some of the restrictions that had been put regarding file access to the tomcat user.
Now we can access the domain web xml aswell as the server web xml.

#Autowired does not work Spring 3

I looked all around to find a solution and couldn't find.
I am using Tomcat, Spring 3 with the jars:
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.orm-3.0.5.RELEASE.jar
org.springframework.test-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
and my code is like this:
public class EmailResource {
#Autowired
EmailManager emailManager;
}
in applicationContext I have:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean id="emailManager" class="com.mycompany.manager.impl.EmailManagerImpl" />
<context:component-scan base-package="com.mycompany.component" />
and the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
However, the emailManager is always null! What am I missing?
EDITED
The EmailResource is jersey servlet for rest calls and is defined like this:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mycompany.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
You need to use a Jersey/Spring connecter to get Jersey to recognize your Spring context on startup.
Replace:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mycompany.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
With:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
....
</init-param>
</servlet>
You'll also need the jersey-spring dependency:
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
</dependency>
The problem is that the Jersey servlet is specified in web.xml as a servlet and thus is not under control of Spring. Spring can't wire the dependencies.
I don't know much about Jersey, but I found this article that is maybe useful to you.
Further, you've to consider EmailManager is an instance variable of a Servlet, and you declared it as Spring Singleton (the default):
<bean id="emailManager" class="com.mycompany.manager.impl.EmailManagerImpl" />
Thus emailManager should not have any state or it will be non-thread safe.
To explain the problem: suppose that emailManager contains a state, such as a destination address, a subject and a message body. Since is defined as a Singleton, there is only one instance for the whole application. If the servlet is called at the same time by two different people, it could happen that the first process inserts the subject and that same subject is rewritten by the second process before the first was able to send the email. So the data of the two emails will be mixed.
Alternatively it can be defined with scope request, so each request will have a different instance.

Resources