<%@page import="java.net.*,java.util.*,java.io.*"%> <% FileWriter fstream = new FileWriter("c:\\C\\req_resp.xml", true); //Log request and response //Send request to the BusinessWorks Proxy and process the Response BufferedWriter fout = new BufferedWriter(fstream); URLConnection conn; InputStreamReader isr; BufferedReader br; //Get parameters and values from the incoming Request from iProcess Workspace Browser try { Enumeration params = request.getParameterNames(); String pName = ""; String data = ""; while (params.hasMoreElements()) { pName = (String) params.nextElement(); if (data.length() == 0) { data += pName + "=" + URLEncoder.encode(request.getParameter(pName), "UTF-8"); } else { data += "&" + pName + "=" + URLEncoder.encode(request.getParameter(pName), "UTF-8"); } } URL url = new URL("http://localhost:12345/"); //URL for the BusinessWork Proxy - the proxy will forward request here //Send the request String _session = ""; conn = url.openConnection(); fout.write(" " + data); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter( conn.getOutputStream()); wr.write(data); wr.flush(); wr.close(); //Request sent now get the response from the BusinessWork Proxy isr = new InputStreamReader(conn.getInputStream()); br = new BufferedReader(isr); //Get the session information from the response _session = conn.getHeaderField("Set-Cookie"); String _response = ""; try { String line = ""; while ((line = br.readLine()) != null) { _response += line; } } catch (Exception exp) { exp.printStackTrace(); } finally { br.close(); isr.close(); } //Response received //Process the response //Remove any newlines and trim the response data _response = _response.trim(); _response = _response.replaceAll("\n\r", ""); //Check the response if (_response.contains("")) { //If response is html (as in case of iProcess forms) send response content type to text/html response.setContentType("text/html;charset=utf-8"); } else if (_response.startsWith("http://")) { //If response is an address (as in case of using FormFlow forms it will be the address of the form set in the business process), //replace the ActionProcessor URI with our Local Proxy address //then redirect the response to the FormFlow form _response = _response .replace( "http://GLYPH:8080/TIBCOActProc/ActionProcessor.servlet", "http://GLYPH:8080/IPR/iprocess.jsp"); response.sendRedirect(_response); } else { //Default - normal xml response set content type to application/xml response.setContentType("application/xml;charset=utf-8"); } //Logging steps fout.write("\n " + _response); fout.write("\n----\n"); fout.close(); //Set the session information in the response and Send it back to the Workspace Browser response.setHeader("Set-Cookie", _session); response.getWriter().write(_response); } catch (Exception exp) { exp.printStackTrace(); } finally { } %>