<%-- Copyright (c) 2000 by BEA Systems, Inc. All Rights Reserved. --%>

<html>
<head>
<title>BizClient</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<h2>BizTalk Client</h2>
<hr>
<%
  if(request.getParameter("submit") == null 
    || request.getParameter("submit").equals("")) {
%>
Fill out the form below to submit a stock trade. When you submit the form, this JSP 
page will generate a BizTalk document based on your input and send it to the address 
specified below. The BizTalk Server will accept the form and hand it off to appropriate 
EJB(s) for processing.

<form method="POST" action="BizClient.jsp">
<table  cellpadding="3">
<tr valign="top"><td>&nbsp</td>
<td>Customer name: </td>
<td><input type="text" name="customer" size="30"></td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>Stock symbol: </td>
<td><select name="symbol">
  <option value="BEAS" selected>BEAS</option>
  <option value="INTL">INTL</option>
</select></td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>Action: </td>
<td><select name="action">
  <option value="buy" selected>Buy</option>
  <option value="sell">Sell</option>
</select></td>
</tr>


<tr valign="top"><td>&nbsp</td>
<td>Number of shares: </td>
<td><input type="text" name="shares" size="30"></td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>BizTalk Server address: </td>
<td><input type="text" name="address" size="30">
<br>This address must be of the form: 
<font face="Courier New" size=-1>http://<i>hostname:port</i>/BizTalkServer</font>,
where <i><font face="Courier New" size = -1>hostname</font></i> is 
the host name of the WebLogic Server and <i><font face="Courier New" size = -1>port</font></i>
is the port where the WebLogic Server is listening for connections
 (<font face="Courier New" size=-1>weblogic.system.ListenPort</font>). 
<b>Note:</b> The uri defined in the BizTalk server configuration file should be 
identicle to the above address.</td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>&nbsp<p><input type="submit" name="submit" value="Submit trade"></td><td></td>
</tr>
</table>
<%
  } else {
%>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="examples.xml.biztalk.*" %>
<%
    try {
      URL url = new URL(request.getParameter("address"));

      URLConnection urlc = url.openConnection();
      urlc.setDoOutput(true);
      urlc.setDoInput(true);
      PrintWriter pw = new PrintWriter(new 
	OutputStreamWriter(urlc.getOutputStream()), true);

      // This implementation does not make use of many of the available 
      // fields in a BizTalk document. Critical fields for this implementation
      // include type, fromAddress, toAddress, and body.

      DOMOutgoingMessage om = new DOMOutgoingMessage();
      om.setType("Trade");
      om.setNameSpace();
      om.setFromAddress(request.getParameter("customer"));
      om.setToAddress(request.getParameter("address"));
      om.setBodyAsXML("<Trade customer='"+request.getParameter("customer") +
                 "' action='"+request.getParameter("action") +
                 "' symbol='"+request.getParameter("symbol") +
                 "' shares='"+request.getParameter("shares")+"'/>"); 
      pw.println(om.toString());

      urlc.getInputStream();
%>
Thank you! Your trade has been recieved. A BizTalk document has 
been sent to <b><%=request.getParameter("address")%></b> with the 
following information: 
<p>
<table  cellpadding="3">
<tr valign="top"><td>&nbsp</td>
<td>Customer name: </td>
<td><%=request.getParameter("customer")%></td>
</tr>


<tr valign="top"><td>&nbsp</td>
<td>Stock symbol: </td>
<td><%=request.getParameter("symbol")%></td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>Action: </td>
<td><%=request.getParameter("action")%></td>
</tr>

<tr valign="top"><td>&nbsp</td>
<td>Number of shares: </td>
<td><%=request.getParameter("shares")%></td>
</tr>
</table>
<p>
<a href="BizClient.jsp">Enter another trade</a>
<%
    } catch (Exception e) {
      out.println("There was a problem connecting to the BizTalk server.\n");
      out.println("Exception caught: "+e.toString());
%>
<p>
<a href="BizClient.jsp">Enter another trade</a>
<%

    }
  }
%>


</body>
</html>
