Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8089558

WebView does not handle setHeader("Content-Disposition", "attachment; filename...

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 7u45
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      Windows XP 32bits, JAVA 1.7u45 JAVAFX 2.2.45

    • Subcomponent:
      web

      Description

      In a WebView, a java servlet code (struts like .do action, i cannot modify it) send a response with a content type and an attachment file to display the save / open dialog nothing happens.
      Here is the code to reproduce :

      it only uses that jars for servlet rendering :
      javax.servlet-3.0.0.v201112011016.jar
      jetty-all-9.2.1.v20140609.jar

      Main class :

      package fr.testcase.rt37806;

      import java.awt.Dimension;

      import javafx.application.Platform;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.concurrent.Worker.State;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;

      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      import org.eclipse.jetty.server.Server;
      import org.eclipse.jetty.servlet.ServletHandler;

      public class Main {

      public Main() {
      }

      /**
      * @param args
      */
      public static void main(String[] args) {

      // jetty embedded
      // cf
      // http://www.eclipse.org/jetty/documentation/current/advanced-embedding.html
      try {
      Server server = new Server(7373);
      ServletHandler handler = new ServletHandler();
      server.setHandler(handler);
      handler.addServletWithMapping(RT37806Servlet.class, "/*");

      // GUI
      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      initAndShowGUI();
      }
      });
      server.start();
      server.join();

      } catch (Exception e) {
      e.printStackTrace();
      }

      }

      private static void initAndShowGUI() {
      JFrame f = new JFrame();
      f.setTitle("TESTCASE RT-37806");
      final JFXPanel fxPanel = new JFXPanel();
      f.add(fxPanel);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setPreferredSize(new Dimension(400, 300));
      f.setLocation(100, 100);
      f.setLocationRelativeTo(null);
      f.pack();
      f.setVisible(true);

      Platform.runLater(new Runnable() {
      @Override
      public void run() {
      initFX(fxPanel);
      }
      });
      }

      private static void initFX(JFXPanel fxPanel) {
      Scene scene = createScene();
      fxPanel.setScene(scene);
      }

      private static Scene createScene() {
      Group root = new Group();
      WebView view = new WebView();
      WebEngine engine = view.getEngine();
      engine.getLoadWorker().stateProperty()
      .addListener(new ChangeListener<State>() {
      public void changed(ObservableValue ov, State oldState,
      State newState) {
      if (newState == State.SUCCEEDED) {
      System.out.println(newState);
      }
      }
      });
      engine.load("http://localhost:7373/");

      root.getChildren().add(view);
      return new Scene(root);
      }

      }

      Servlet :

      package fr.testcase.rt37806;

      import java.io.IOException;
      import java.io.PrintWriter;

      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      @SuppressWarnings("serial")
      public class RT37806Servlet extends HttpServlet{

      @Override
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
          {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println("<html><head><title>RT-37806</title></head>" +
      "<body bgcolor=FFFFFF>");

      out.println("<FORM METHOD=\"POST\">");
      out.println("<INPUT TYPE=\"SUBMIT\" value=\"Export\">");

      out.println("</FORM></body></html>");
      out.close();
          }

      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

      String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><tests><test><numTest>1</numTest></test></tests>";

      String filename = "test.xml";

      PrintWriter stream = response.getWriter();
      response.setContentType("text/xml;charset=UTF-8");
      response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

      stream.write(fileContent);
      stream.flush();
              stream.close();
      }

      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: