BGTranslator end to end scenario

Author: Lukas Jungmann
Last update: $Date: 2009/10/29 16:50:43 $, $Revision: 1.1.1.1 $
Introduction:

This end to end scenario should test Web service client creation. The scenario covers developing of web service client (IDE-generated static stub).
The document is not intended as test specification for these features but describes developing web service client in NetBeans 5.5 (version for NetBeans 5.0 can be found here)

Table of Contents


BgTrans sources are avalaible here.

Creating web project

  • Go to File - New Project - Web - Web Application
  • Specify BgTrans as Project Name
  • Specify project's directory
  • Select Sun App server as target server
  • Choose J2EE 1.4 as J2EE version and
  • Click Finish

Creating web service client

  • Go to File - New File - Web services - Web Service Client - Next
  • Specify http://www.progem.bg/BGTrans/services.wsdl as WSDL URL
  • Optional: if you're behind proxy check its settings via Set Proxy ... button
  • Specify package for the client, eg. org.netbeans.end2end.bgtrans.client
  • Select IDE-generated static stub as client type
  • Click Finish

Testing web service

  • Go to Web Services References - SOAP - SOAPPort - BGTranslate and invoke Test Operation
    from context menu of BGTranslate node
  • In Test Web Service Operation dialog set word to Hello
  • Click Submit
  • You should see following "picture"
  • Test several others translations
  • Click Close
  • Implementing index.jsp

    • Open index.jsp code in editor
    • Create form for user input somewhere between the <body> tags
              <form action="index.jsp" method="get">
                  Enter some english word: <input type="text" name="word" /> <button type="submit">Translate</button>
              </form>
                      
    • Created form should look like:
    • Right-click somewhere in index.jsp and invoke Web Service Client Resources - Call Web Service Operation
    • Select BGTranslate and click OK button - now IDE generates webservice invokation code with some comments at the end of the page:
          <%-- start web service invocation --%>
          <h4>SOAP invocation:</h4>
          <hr/>
          <%
          // TODO compute web service operation arguments here, e.g.:
          // String arg0 = request.getParameter("arg0");
          try {
              org.netbeans.end2end.bgtrans.client.SOAP sOAP = new org.netbeans.end2end.bgtrans.client.SOAP_Impl();
              org.netbeans.end2end.bgtrans.client.SOAPPortType sOAPPort = sOAP.getSOAPPort();
              out.println("result = "+
                  sOAPPort.BGTranslate(/* TODO enter operation arguments*/));
          } catch(javax.xml.rpc.ServiceException ex) {
              // TODO handle ServiceException
          } catch(java.rmi.RemoteException ex) {
              // TODO handle remote exception
          } catch(Exception ex) {
              // TODO handle custom exceptions here
          }
          %>
          <hr/><%-- end web service invocation--%>
                  
    • And now we have to customize this code to fit our needs. Final version our this can look like eg.:
                      
      <%@page contentType="text/html"%>
      <%@page pageEncoding="UTF-8"%>
      <%@page import="java.io.PrintWriter"%>
      <%
          String word = request.getParameter("word");
          String result = null;
      %>
      
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
         "http://www.w3.org/TR/html4/loose.dtd">
      <html>
          <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <title>English -> Bulgarian translator</title>
          </head>
          <body>
              <h1>Welcome to English -> Bulgarian translator</h1>
      <%
              if (word != null) {
                  try {
                      org.netbeans.end2end.bgtrans.client.SOAP sOAP = new org.netbeans.end2end.bgtrans.client.SOAP_Impl();
                      org.netbeans.end2end.bgtrans.client.SOAPPortType sOAPPort = sOAP.getSOAPPort();
                      result = sOAPPort.BGTranslate(word);
                      int i = result.lastIndexOf("-Found-");
                      if (i > 0) {
                          result = result.substring(0, i).replace("\\n", " ").trim();
                      }
                  } catch (javax.xml.rpc.ServiceException ex) {
                      // TODO handle ServiceException
                      ex.printStackTrace(new PrintWriter(out));
                  } catch (java.rmi.RemoteException ex) {
                      // TODO handle remote exception
                      ex.printStackTrace(new PrintWriter(out));
                  } catch (Exception ex) {
                      // TODO handle custom exceptions here
                      ex.printStackTrace(new PrintWriter(out));
                  } %>
                  <p>
              <strong><%= word %></strong> in english is:<br/>
                   "<%= result %>" in bulgarian.</p>
      <%
              } else {
      %>
              <form action="index.jsp" method="get">
                  Enter some english word: <input type="text" name="word" /> <button type="submit">Translate</button>
              </form>
      <%
              }
      %>
          </body>
      </html>
                  

    Running application

    • Now we've done our application and we can run it. Here's sample output:

    Project Features

    About this Project

    QA was started in November 2009, is owned by Jiří Kovalský, and has 97 members.
    By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
     
     
    Close
    loading
    Please Confirm
    Close