When you print this page, select the landscape layout option.
Listing 3. Client application
public class PersistDataClient extends HttpServlet
{
private PersistDataOne_PortType persistOne;
private PersistDataTwo_PortType persistTwo;
ServletContext context;
public PersistDataClient()
{
}
public void init(ServletConfig config)
throws ServletException
{
String baseParam = config.getInitParameter("baseURL");
String baseURL;
if(baseParam != null)
{
baseURL = baseParam.endsWith("/") ? baseParam : baseParam + "/";
} else
{
baseURL = "http://localhost:8080/jboss-net/services/";
}
try
{
PersistDataOneServiceLocator
persistDataOneServiceLocator = new PersistDataOneServiceLocator();
String persistDataOneWSDDServiceName =
persistDataOneServiceLocator.getPersistDataOneWSDDServiceName();
String persistOneUrl = baseURL + persistDataOneWSDDServiceName;
persistOne = persistDataOneServiceLocator.getPersistDataOne(
new URL(persistOneUrl));
PersistDataTwoServiceLocator persistDataTwoServiceLocator =
new PersistDataTwoServiceLocator();
String persistDataTwoWSDDServiceName =
persistDataTwoServiceLocator.
getPersistDataTwoWSDDServiceName();
String persistTwoUrl = baseURL + persistDataTwoWSDDServiceName;
persistTwo =
persistDataTwoServiceLocator.
getPersistDataTwo(new URL(persistTwoUrl));
}
catch(Exception e)
{
throw new ServletException(e.toString(), e);
}
context = config.getServletContext();
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
boolean onePassFail = true;
boolean twoPassFail = true;
String result = "Transaction finished OK.";
try
{
runBusinessActivity(onePassFail, twoPassFail);
}
catch(Exception e)
{
e.printStackTrace();
}
request.setAttribute("result", result);
}
private void runBusinessActivity(boolean onePassFail,
boolean twoPassFail)
throws Exception
{
UserBusinessActivity uba =
UserBusinessActivityFactory.userBusinessActivity();
if(uba == null)
{
System.out.println("uba is null");
} else
{
uba.begin();
}
boolean isOK = false;
try
{
if(persistOne.writeToFileOne(onePassFail) &&
persistTwo.writeToFileTwo(twoPassFail))
{
isOK = true;
}
}
catch(Throwable th)
{
System.out.println("CLIENT: caught exception processing bookings,
cancelling (" + th.getMessage() + ")");
}
if(isOK)
{
System.out.println("CLIENT: all OK");
System.out.println("CLIENT: calling close on the transaction...");
uba.close();
} else
{
System.out.println("CLIENT: one or more services failed,
calling cancel.");
uba.cancel();
}
System.out.println("CLIENT: done.");
System.out.flush();
}
}
|