Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se

Java8 e métodos incompatíveis

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
          String path = req.getRequestURI().split("/file")[1];

            Path source = Paths.get(FileSaver.SERVER_PATH + "/" + path);
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            String contentType = fileNameMap.getContentTypeFor("file:"+source);

            res.reset();
            res.setContentType(contentType);
            res.setHeader("Content-Length", String.valueOf(Files.size(source)));
            res.setHeader("Content-Disposition", 
                    "filename=\""+source.getFileName().toString() + "\"");
            FileSaver.transfer(source, res.getOutputStream());    
}

Prezados,

Estou tendo problemas aqui, tentei duas jvms 1.6_0_37 e 1.8.0_201, elas não reconhecem os métodos abaixo:

The method getRequestURI() is undefined for the type ServletRequest The method setHeader(String, String) is undefined for the type ServletResponse

Desde já agradeço o suporte e sua atenção!

4 respostas

Como está seu pom.xml?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.com.casadocodigo</groupId>
  <artifactId>casadocodigo</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>casadocodigo</finalName>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.jboss.spec.javax.faces</groupId>
      <artifactId>jboss-jsf-api_2.1_spec</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.3.Final</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.1_spec</artifactId>
        <version>2.1.29.1.Final</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.0-SP4</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Tenta incluir essa dependência no seu pom.xml:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>

Fala Otávio,

Infelizmente não funcionou incluindo a dependência. Alguma outra sugestão?