Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jersey

web.xml

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>

like image 844
parliament Avatar asked Dec 15 '22 06:12

parliament


1 Answers

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 -->
like image 109
Paul Samsotha Avatar answered Apr 28 '23 16:04

Paul Samsotha