<%@ page language="java" import="java.io.BufferedReader, java.io.InputStreamReader, java.io.PrintWriter, java.net.URL, java.net.URLConnection, javax.xml.transform.Transformer, javax.xml.transform.Source, javax.xml.transform.Result, javax.xml.transform.stream.StreamSource, javax.xml.transform.stream.StreamResult, java.io.ByteArrayInputStream, java.io.ByteArrayOutputStream, javax.xml.transform.TransformerFactory, javax.xml.transform.OutputKeys" %> <% // Access the UDDI registry on localhost final String HTTP_PROXY_HOST = null; final String HTTP_PROXY_PORT = null; final URL INQUIRY_URL = new URL("http://localhost:" + request.getServerPort() + "/juddi/inquiry"); final URL PUBLISH_URL = new URL("http://localhost:" + request.getServerPort() + "/juddi/publish"); final URL ADMIN_URL = new URL("http://localhost:" + request.getServerPort() + "/juddi/admin"); // Access a remote UDDI registry //final String HTTP_PROXY_HOST = "proxy"; //final String HTTP_PROXY_PORT = "80"; //final URL INQUIRY_URL = new URL("http://[host]:[port]/juddi/inquiry"); //final URL PUBLISH_URL = new URL("http://[host]:[port]/juddi/publish"); //final URL ADMIN_URL = new URL("http://[host]:[port]/juddi/admin"); // Pull input parameters from the HTTP request String requestName = request.getParameter("request_name"); String requestType = request.getParameter("request_type"); String validateAction = request.getParameter("validate_button"); String submitAction = request.getParameter("submit_button"); String resetAction = request.getParameter("reset_button"); String requestMsg = request.getParameter("soap_request"); // Initialize the Session keys, target page and response message String requestKey = requestName+":request"; String responseKey = requestName+":response"; String requestTimeKey = requestName+":time"; String targetPage = requestName+".jsp"; String responseMsg = null; // Initialize the response time variables long startTime = 0; long endTime = 0; long totalTime = 0; // Determine which action the user selected. if (validateAction != null) { // If user clicked the "Validate" button then check // that the request XML is well-formed and validate // it against the UDDI v2.0 XML Schema. responseMsg = "Validation is not implemented yet."; } else if (resetAction != null) { // If user clicked the "Reset" button then initialize // the request & response values to null. requestMsg = null; responseMsg = null; } else if (submitAction != null) { // If the user didn't select the "Reset" then they // must have clicked the "Submit" button. requestMsg = requestMsg.toString().trim(); try { // If HTTP proxy values are specified then use them if ((HTTP_PROXY_HOST != null) && (HTTP_PROXY_PORT != null)) { System.setProperty("http.proxyHost",HTTP_PROXY_HOST); System.setProperty("http.proxyPort",HTTP_PROXY_PORT); } else { // In case they were specified but you no longer need them System.setProperty("http.proxyHost",""); System.setProperty("http.proxyPort",""); } // Determine which endpoint the request should use URL targetURL = null; if (requestType.equals("publish")) targetURL = PUBLISH_URL; else if (requestType.equals("inquiry")) targetURL = INQUIRY_URL; else if (requestType.equals("admin")) targetURL = ADMIN_URL; // Start the clock startTime = System.currentTimeMillis(); // Create HTTP Connection URLConnection connection = targetURL.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("SOAPAction",""); PrintWriter writer = new PrintWriter(connection.getOutputStream()); // Send the HTTP Request writer.write(requestMsg); writer.close(); // Read the HTTP Response BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer msg = new StringBuffer(); String line; while((line = reader.readLine()) != null) msg.append(line+"\n"); // Convert reponse to String and trim whitespace responseMsg = msg.toString().trim(); ByteArrayInputStream bais = new ByteArrayInputStream(responseMsg.getBytes()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Source responseSrc = new StreamSource(bais); Result responseRes = new StreamResult(baos); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(responseSrc, responseRes); responseMsg = baos.toString(); // Close the HTTP Connection reader.close(); // Stop the clock & calculate time endTime = System.currentTimeMillis(); totalTime = endTime - startTime; } catch (Exception e) { e.printStackTrace(); // Display the exception msg as the result responseMsg = e.getMessage(); } } // Set new values into the session session.setAttribute(requestKey,requestMsg); session.setAttribute(responseKey,responseMsg); session.setAttribute(requestTimeKey,String.valueOf(totalTime).trim()); // Redirect back to the source page request.getRequestDispatcher(targetPage).forward(request,response); %>