Adobe Flash Player阻止HTTP响应的问题

时间:2017-11-06 18:07:58

标签: java http flash servlets

我有一个项目,我一直在兼职工作,现在应该提交。我通过以太网连接到外部plc并尝试使用HTTP请求从设备检索数据。我有这个工作,数据以XML格式接收回来,我能够解析这些数据并将其提交到数据库。

我现在才提交项目,工作的内容已不再有效!我没有收到XML格式的数据,而是收到安装Adobe Flash Player的消息。在调查问题时,谷歌和其他浏览器已经禁用了如何控制如何使用Flash播放器的一些功能。以前当我运行程序时,我必须在所有站点上启用Flash播放器,这很有效。现在我只允许在指定的站点上启用它,无论我输入什么选项,我仍然会收到同样的错误。

关于HTTP连接,我得到一个代码200响应,显示连接正在工作,但我无法获取我一直得到的数据。

自Chrome改变其政策以来,还有其他人遇到此问题吗?我尝试过其他浏览器,但同样的问题。我已尝试使用较早版本的Chrome进行回溯跟踪,但只能将.exe文件单独运行而不是安装在计算机上,因此Netbeans无法识别它。我已经尝试过Firefox及其扩展版本,这是为了在2018年3月/ 4月之前解决这些问题,但我也遇到了同样的问题。

任何见解或帮助都将受到赞赏。

这是服务器信息

Server Response

这是信息请求的结果

import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.io.ByteArrayInputStream;
import org.xml.sax.SAXException;
import org.w3c.dom.Document;
import org.xml.sax.*;
import javax.xml.parsers.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.*;



/**
 *
 * @author ******
 */
@WebServlet(urlPatterns = {"/DeviceReadDateTime"})
public class DanfossDeviceReadDateTime extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */



       String userName;
       String userPassword;
       String siteAddress;
       String tagReference;
       String reportType;
       String danfossResponseXMLReturned;
       String danfossReadDateTimeYear;
       String danfossReadDateTimeMonth;
       String danfossReadDateTimeDay;
       String danfossReadDateTimeHour;
       String danfossReadDateTimeMinute;
       String danfossReadDateTimeSecond;
       String danfossReadDateTimeEpoch;
       String danfossReadDateTimeTimeZone;
       String danfossReadDateTimeDayLightSavings;

       Connection conn;
       PreparedStatement prepStat;
       Statement stat;
       ResultSet rs = null;

    /**
     *
     * @throws ServletException
     */

       @Override
       public void init() throws ServletException
       {

        String connectionUrl ="jdbc:sqlserver://localhost:***;" +
                   "databaseName=*******************;user=**;password=*****";




           try{

               // establishing the connection

              Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
              conn =  DriverManager.getConnection(connectionUrl);



               System.out.println("You are connected to SQLServer 2014");



         //      stat = (Statement) conn.createStatement();

             // retrieve data

     /*   Statement st = (Statement) conn.createStatement();
        ResultSet rs1 = st.executeQuery("select * from danfossDateTime");
        while(rs1.next()){
            danfossReadDateTimeYear = rs1.getString(1);
            danfossReadDateTimeMonth = rs1.getString(2);
            danfossReadDateTimeDay = rs1.getString(3);
            danfossReadDateTimeHour = rs1.getString(4);    
            danfossReadDateTimeMinute = rs1.getString(5);
            danfossReadDateTimeSecond = rs1.getString(6);
            danfossReadDateTimeEpoch = rs1.getString(7);
            danfossReadDateTimeTimeZone = rs1.getString(8);
            danfossReadDateTimeDayLightSavings = rs1.getString(9);


            System.out.println("danfossReadDateTimeYear = " + danfossReadDateTimeYear + "\n"
                    + "danfossReadDateTimeMonth = " + danfossReadDateTimeMonth + "\n"
                    + "danfossReadDateTimeDay = " + danfossReadDateTimeDay
             + "danfossReadDateTimeHour = " + danfossReadDateTimeHour + "\n"
             + "danfossReadDateTimeMinute = " + danfossReadDateTimeMinute + "\n"
             + "danfossReadDateTimeSecond = " + danfossReadDateTimeSecond + "\n"
             + "danfossReadDateTimeEpoch = " + danfossReadDateTimeEpoch + "\n"
             + "danfossReadDateTimeTimeZone = " + danfossReadDateTimeTimeZone + "\n"
             + "danfossReadDateTimeDayLightSavings = " + danfossReadDateTimeDayLightSavings + "\n");
        }

         System.out.println("Data retrieved from MS SQL");

       */
       }   catch (SQLException | ClassNotFoundException ex) {
               Logger.getLogger(DanfossDeviceReadDateTime.class.getName()).log(Level.SEVERE, null, ex);
           }

     }// end of init method// end of init method// end of init method// end of init method





    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();

        Cookie cookie = null;
        Cookie cookiesArray[] = null;

        //get an array of cookies associated with this domain
        cookiesArray = request.getCookies();

        if(cookiesArray != null)
        {
            for(int i = 0; i<cookiesArray.length; i++)
            {
                cookie = cookiesArray[i];

                switch (cookie.getName()) {
                    case "userName":
                        userName = cookie.getValue();
                        break;
                    case "userPassword":
                        userPassword = cookie.getValue();
                        break;
                    case "siteAddress":
                        siteAddress = cookie.getValue();
                        siteAddress = ("http:\\").concat(siteAddress);
                        break;
                }

            }
        }




        //Code requesting that data from the danfoss unit

        XPath path;



        String xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n\r\n<cmd action=\"read_date_time\" node =\"1\"/>\r\n\r\n";

       OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/octet-stream");

        RequestBody body = RequestBody.create(mediaType, xmlString);

        Request danfossRequest = new Request.Builder()
            .url(siteAddress)
            .post(body)
            .build();

         System.out.println("danfossRequest = " + danfossRequest);

        Response danfossResponse = client.newCall(danfossRequest).execute();

        System.out.println("danfossResponse = " + danfossResponse);




        // converting string to xml and parsing

        danfossResponseXMLReturned = danfossResponse.body().string();
         System.out.println("danfossResponseXMLReturned = " + danfossResponseXMLReturned);

        XMLReader parser;

        try {

            Document dbfactory =DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new ByteArrayInputStream(danfossResponseXMLReturned.getBytes("utf-8"))));
            XPathFactory xpfactory = XPathFactory.newInstance();
            path = xpfactory.newXPath();



            danfossReadDateTimeYear = path.evaluate("/resp/year", dbfactory);
            danfossReadDateTimeMonth = path.evaluate("/resp/month", dbfactory);
            danfossReadDateTimeDay = path.evaluate("/resp/day", dbfactory);
            danfossReadDateTimeHour = path.evaluate("/resp/hour", dbfactory);
            danfossReadDateTimeMinute = path.evaluate("/resp/minute", dbfactory);
            danfossReadDateTimeSecond = path.evaluate("/resp/second", dbfactory);
            danfossReadDateTimeEpoch = path.evaluate("/resp/epoch", dbfactory);
            danfossReadDateTimeTimeZone = path.evaluate("/resp/timezone", dbfactory);
            danfossReadDateTimeDayLightSavings = path.evaluate("/resp/daylightsavings", dbfactory);

            //print results
            System.out.println("danfossReadDateTimeYear = " + danfossReadDateTimeYear);
            System.out.println("danfossReadDateTimeMonth = " + danfossReadDateTimeMonth);

        } catch (FactoryConfigurationError err) {
            System.err.println ("can't create JAXP SAXParserFactory, "
            + err.getMessage ());
        } catch (ParserConfigurationException err) {
            System.err.println ("can't create XMLReader with namespaces, "
            + err.getMessage ());
        } catch (SAXException err) {
            System.err.println ("Hmm, SAXException, " + err.getMessage ());
        }  catch (XPathExpressionException ex) {
               Logger.getLogger(DanfossDeviceReadDevices.class.getName()).log(Level.SEVERE, null, ex);
           }


        System.out.println(danfossReadDateTimeYear);
        System.out.println(danfossReadDateTimeMonth);
        System.out.println(danfossReadDateTimeDay);
        System.out.println(danfossReadDateTimeHour);
        System.out.println(danfossReadDateTimeMinute);
        System.out.println(danfossReadDateTimeSecond);
        System.out.println(danfossReadDateTimeEpoch);
        System.out.println(danfossReadDateTimeTimeZone);
        System.out.println(danfossReadDateTimeDayLightSavings);

// submit data to database

    /*    try{
            String query = "INSERT INTO danfossDateTime VALUES (?,?,?,?,?,?,?,?,?)";
            prepStat = (PreparedStatement) conn.prepareStatement(query);
            prepStat.setString(1,danfossReadDateTimeYear);
            prepStat.setString(2,danfossReadDateTimeMonth);
            prepStat.setString(3,danfossReadDateTimeDay);
            prepStat.setString(4,danfossReadDateTimeHour);
            prepStat.setString(5,danfossReadDateTimeMinute);
            prepStat.setString(6,danfossReadDateTimeSecond);
            prepStat.setString(7,danfossReadDateTimeEpoch);
            prepStat.setString(8,danfossReadDateTimeTimeZone);
            prepStat.setString(9,danfossReadDateTimeDayLightSavings);
            prepStat.executeUpdate();

        }catch(Exception e)
        {

        }
   */
    //html page output


        response.setContentType("text/html;charset=UTF-8");
           // out = response.getWriter();
            String title = "***";
            String docType = "<!doctype html>";
            out.println(docType + "<html>\n" +

"<head>\n" +
"    <title>***</title>\n" +
"    <link rel=\"stylesheet\" type=\"text/css\" href=\"***RemoteSiteDataCheckerCSS2.css\"/>\n" +
"</head>\n" +
"<body>\n" +
"    \n" +
"    \n" +
"    <section id=\"logo\">\n" +
"        <!-- Introduction on the company -->\n" +
"        <header>\n" +
"        <center><h1>**************</h1></center>\n" +
"    \n" +
"        <center><h3>Remote Site Data Checker</h3></center>\n" +
"        </header>\n" +
"    </section>\n" +
"    \n" +
"    \n" +
"     \n" +
"    <section>\n" +
"        <form action=\"SubmitTestData\" method=\"POST\">\n" +
"            <label>User Name</label> <input type=\"text\" name=\"userName\" value=\"" + userName + "\">\n" +
"            <br>\n" +
"            <label>Password</label> <input type=\"password\" name=\"userPassword\" value=\"" + userPassword + "\">\n" +
"            <br>\n" +
"            <label>Site Address</label> <input type=\"text\" name=\"siteAddress\" value=\"" + siteAddress + "\">\n" +
"            <br>\n" +
"            <label></label><input type=\"submit\" value=\"Submit Test Data\"/>\n" +
"             \n" +
"        </form>\n" +
"    </section>   \n" +
"    \n" +
"    <section>\n" +
"       <form>\n" +
"        <label>Results:</label>\n" +
"        \n" +
"        <textarea name=\"resultsTextBox\" rows=\"10\" cols=\"80\" wrap=\"hard\">\n" +
"            Results now here...\n" + danfossResponseXMLReturned +
"         \nFrom XML Dom BUilder - year =   "  + danfossReadDateTimeYear  +
"         \nFrom XML Dom BUilder - month =   "  +  danfossReadDateTimeMonth +
"         \nFrom XML Dom BUilder - day =   "  +             danfossReadDateTimeDay  +
"         \nFrom XML Dom BUilder - hour =   "  +            danfossReadDateTimeHour +
"         \nFrom XML Dom BUilder - minute =   "  +             danfossReadDateTimeMinute +
"         \nFrom XML Dom BUilder - second =   "  +             danfossReadDateTimeSecond +
"         \nFrom XML Dom BUilder - epoch =   "  +             danfossReadDateTimeEpoch +
"         \nFrom XML Dom BUilder - timezone =   "  +             danfossReadDateTimeTimeZone +
"         \nFrom XML Dom BUilder - daylightsavings =   "  +             danfossReadDateTimeDayLightSavings +

"        </textarea>\n" +
"        </form>\n" +
"    </section>   \n" +
"                    \n<section>\n" +
"        <button onclick=\"location.href='index.html'\">Home Page</button>\n" +
"        <button onclick=\"location.href='DanfossDeviceHome.html'\">Generate New Report</button>\n" +
"        \n" +
"    </section>" +

"                \n" +
"    <footer>\n" +
"        <!-- Footer -->\n" +
"        <hr>\n" +
"   \n" +
"       <p>**********************</p>\n" +
"    </footer>\n" +
" \n" +
"</body>\n" +
"</html>\n" +
"\n");





    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
           try {
               processRequest(request, response);
           } catch (SQLException ex) {
               Logger.getLogger(DanfossDeviceReadDateTime.class.getName()).log(Level.SEVERE, null, ex);
           }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
           try {
               processRequest(request, response);
           } catch (SQLException ex) {
               Logger.getLogger(DanfossDeviceReadDateTime.class.getName()).log(Level.SEVERE, null, ex);
           }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

这基本上告诉我安装Adobe Flash Player,因为我已经看到哪些已经完成!

以下是servlet中的代码。

{{1}}

0 个答案:

没有答案