NavigationUser login |
if_rig, appendix G annoying Java snippet ServletAdapterTest//Not pretty, but it works. public class ifbo { public static void main(String[] args) { String url; url = "http://server:port/apifw/APIFWAdapterServlet"; environment = ""; /* Read file */ String fileName = "c:/temp/ifbo/WORR.xml"; // Get the size of the file // Create the byte array to hold the data. try { FileInputStream fis = new FileInputStream(input); } catch (UnsupportedEncodingException ee) { System.out.println("filelength = " + filelength); /* end Read file */ try { java.io.OutputStream bos = new FileOutputStream(input); OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF8"); osw.write(new String(fileByteArray, "UTF8")); osw.close(); PostMethod fwPost = new PostMethod(url); Part parts[] = { new StringPart("envName", ICEncodingUtils.urlEncode(environment, "UTF8")), new FilePart(input.getName(), input, "text/xml", "UTF8") }; fwPost.setRequestEntity(new MultipartRequestEntity(parts, fwPost.getParams())); HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams(); connectionParams.setConnectionTimeout(5000); HttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); connectionManager.setParams(connectionParams); HttpClient httpClient = new HttpClient(connectionManager); int result = httpClient.executeMethod(fwPost); int httpCode = fwPost.getStatusCode(); String httpResponseText = fwPost.getStatusText(); Header headr = fwPost.getResponseHeader("ApifwRC"); headr = fwPost.getResponseHeader("InternalReqID"); String xmlResult = new String(); BufferedReader bufRdr = null; java.io.InputStream inStrm = fwPost.getResponseBodyAsStream(); InputStreamReader ISR = new InputStreamReader(inStrm); String sTmp; while((sTmp = bufRdr.readLine()) != null) xmlResult = xmlResult + sTmp; bufRdr.close(); fwPost.releaseConnection(); System.out.println("xmlResult:" + xmlResult); //input.delete(); return; } catch (Exception e) { } } Reply |