Applet无法连接到Web服务

时间:2015-07-20 16:47:31

标签: java web-services maven applet

我试图在localhost中使用带有Web服务的Applet Form构建一个简单的示例。目标是创建与Web服务的连接,并在屏幕上显示验证码和显示。在以前的设计中,当我尝试在Web浏览器上使用它时调用getNameofServiceport()失败,但是当我在Netbeans上执行它时它工作。"当然我知道命令不同"。我还需要找到一种在浏览器上调试applet的方法,这里的响应没有帮助,因为Home目录中的vars不存在。

我在使用什么:

  • 使用maven的网络服务
  • 我使用wsimport生成存根并导入到我有Applet表单的普通Java应用程序
  • Last opensuse O.S
  • 最后的GlassFish服务器

我在这里看到很多回复,但是到目前为止还没有帮助解决这个问题。

到目前为止我尝试了什么:

  1. 小程序标记配置
  2. MANIFEST属性
  3. jarsigner"在各个网站上我看到我感到害怕因为注意安全"
  4. Applet政策"我不确定这是否可以在网络浏览器中使用"
  5. 读取stackoverflow类似问题
  6. 来源

    - Applet tag

    - Validate jar files

    更新1

    让我们试试这个例子来帮助人们理解我想做的事情:

    服务器端

        package test.example.serviceexample;
    
        import javax.jws.WebService;
        import javax.jws.WebMethod;
        import javax.jws.WebParam;
    
        /**
        *
        * @author felipe
        */
        @WebService(serviceName = "WebServiceHelloWord")
        public class WebServiceHelloWord {
    
        /**
        * This is a sample web service operation
        * @param txt
        * @return 
        */
        @WebMethod(operationName = "hello")
          public String hello(@WebParam(name = "name") String txt) {
          return "Hello " + txt + " !";
         }
        }
    

    生成存根文件

        wsimport -d . -keep -verbose  -clientjar example.jar http://localhost:8080/ServiceExample/WebServiceHelloWord?WSDL
    

    为Web应用程序创建Applet

    1. 创建Java程序
    2. 添加Apllet表单
    3. 在Libary Jar上添加example.jar
    4. 编辑源小程序以连接端口
    5. 源代码客户端

          package applethelloword;
      
          import test.example.serviceexample.*;
      
          /**
          *
          * @author felipe
          */
           public class AppletHelloWord extends java.applet.Applet {
      
              private WebServiceHelloWord_Service port;
              private WebServiceHelloWord sMyReturn;
          /**
          * Initializes the applet AppletHelloWord
          */
           public void init() {
              try {
                   java.awt.EventQueue.invokeAndWait(new Runnable() {
                     public void run() {
                         initComponents();
                    }
                  });
                } catch (Exception ex) {
                      ex.printStackTrace();
                }
              }
      
             /**
             * This method is called from within the init() method to initialize the
             * form. WARNING: Do NOT modify this code. The content of this method is
             * always regenerated by the Form Editor.
             */
             // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
             private void initComponents() {
      
                   jLabel1 = new javax.swing.JLabel();
                   jTextField1 = new javax.swing.JTextField();
                   jButton1 = new javax.swing.JButton();
                   jLabel2 = new javax.swing.JLabel();
      
                   jLabel1.setFont(new java.awt.Font("Cantarell", 1, 14)); // NOI18N
                   jLabel1.setText("Say WORD !!!");
      
                   jButton1.setText("PRESS HERE");
                   jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                           jButton1ActionPerformed(evt);
                     }
                     });
      
                    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
                    this.setLayout(layout);
                    layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jLabel1)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap())
              .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addGroup(layout.createSequentialGroup()
                  .addGap(162, 162, 162)
                  .addComponent(jButton1)
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel1)
                      .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                     .addComponent(jLabel2,  javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(23, 23, 23)
                    .addComponent(jButton1)
                    .addContainerGap())
            );
            }// </editor-fold>                        
      
          private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)    {                                         
               // TODO add your handling code here:
      
               port =  new WebServiceHelloWord_Service();
               sMyReturn = port.getWebServiceHelloWordPort();
      
              jLabel2.setText(sMyReturn.hello(jTextField1.getText()));
      
          }                                        
      
      
          // Variables declaration - do not modify                     
          private javax.swing.JButton jButton1;
          private javax.swing.JLabel jLabel1;
          private javax.swing.JLabel jLabel2;
          private javax.swing.JTextField jTextField1;
          // End of variables declaration                   
          }
      

      在Web服务上执行

           <!DOCTYPE html>
           <html>
           <head>
                <title>Start Page</title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            </head>
            <body>
             <h1>Hello World!</h1>
                 <applet archive="AppletHelloWord.jar,lib/example.jar" code="applethelloword/AppletHelloWord.class" width="500" height="400" >
          <param name="permissions" value="all-permissions">
            </applet>
            </body>
            </html>
      

      OBS

      在我阅读了更多关于我看到我进入sMyReturn = port.getWebServiceHelloWordPort();发生错误,它不在服务中连接,不执行远程命令。

0 个答案:

没有答案