BGTranslator end to end scenario
Author: Lukas Jungmann
Last update: $Date: 2006/07/14 11:07:17 $, $Revision: 1.6 $
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.
- 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
- 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
- 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
- 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>
- Now we've done our application and we can run it. Here's sample
output: