Vladimir Dzhuvinov Vladimir Dzhuvinov - 1 year ago 66
Java Question

Missing async methods in servlet api 3.0 jar?

I'm developing a servlet 3.0 application that has to process requests asynchronously.

Compilation fails with a

cannot find symbol
symbol : method startAsync(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
location: interface javax.servlet.http.HttpServletRequest


message.

I have the following dependency in my pom.xml :

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
</dependency>


Interestingly, the import javax.servlet.AsyncContext succeeds. But when I list the methods of javax.servlet.ServletRequest, there are none from 3.0 API that deal with asynchronous requests.

public abstract java.lang.String javax.servlet.ServletRequest.getScheme()
public abstract java.lang.String javax.servlet.ServletRequest.getProtocol()
public abstract javax.servlet.ServletInputStream javax.servlet.ServletRequest.getInputStream() throws java.io.IOException
public abstract int javax.servlet.ServletRequest.getContentLength()
public abstract java.lang.Object javax.servlet.ServletRequest.getAttribute(java.lang.String)
public abstract java.lang.String javax.servlet.ServletRequest.getContentType()
public abstract java.util.Locale javax.servlet.ServletRequest.getLocale()
public abstract java.util.Enumeration javax.servlet.ServletRequest.getAttributeNames()
public abstract java.lang.String javax.servlet.ServletRequest.getCharacterEncoding()
public abstract void javax.servlet.ServletRequest.setCharacterEncoding(java.lang.String) throws java.io.UnsupportedEncodingException
public abstract java.lang.String javax.servlet.ServletRequest.getParameter(java.lang.String)
public abstract java.util.Enumeration javax.servlet.ServletRequest.getParameterNames()
public abstract java.lang.String[] javax.servlet.ServletRequest.getParameterValues(java.lang.String)
public abstract java.util.Map javax.servlet.ServletRequest.getParameterMap()
public abstract java.lang.String javax.servlet.ServletRequest.getServerName()
public abstract int javax.servlet.ServletRequest.getServerPort()
public abstract java.io.BufferedReader javax.servlet.ServletRequest.getReader() throws java.io.IOException
public abstract java.lang.String javax.servlet.ServletRequest.getRemoteAddr()
public abstract java.lang.String javax.servlet.ServletRequest.getRemoteHost()
public abstract void javax.servlet.ServletRequest.setAttribute(java.lang.String,java.lang.Object)
public abstract void javax.servlet.ServletRequest.removeAttribute(java.lang.String)
public abstract java.util.Enumeration javax.servlet.ServletRequest.getLocales()
public abstract boolean javax.servlet.ServletRequest.isSecure()
public abstract javax.servlet.RequestDispatcher javax.servlet.ServletRequest.getRequestDispatcher(java.lang.String)
public abstract java.lang.String javax.servlet.ServletRequest.getRealPath(java.lang.String)
public abstract int javax.servlet.ServletRequest.getRemotePort()
public abstract java.lang.String javax.servlet.ServletRequest.getLocalName()
public abstract java.lang.String javax.servlet.ServletRequest.getLocalAddr()
public abstract int javax.servlet.ServletRequest.getLocalPort()


What am I missing?

Answer Source

I assume you have somehow "managed" to reference an older servlet-api library (probably transitively) that is located in the classpath before the javaee-web-api. This means existing classes are fetched from the older servlet-api, whereas classes that do not exist in the older spec are loaded from javaee-web-api.

You can run mvn dependency:tree to look where that outdated library is referenced and then exclude it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download