<%@page import="java.io.InputStream"%> <%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%> <%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%> <%@page import="org.apache.commons.fileupload.FileItem"%> <%@page import="java.io.BufferedReader"%> <%@page import="java.io.InputStreamReader"%> <%@page import="java.net.URLEncoder"%> <%@page import="java.nio.charset.Charset"%> <%@page import="java.nio.charset.CharsetEncoder"%> <%@page import="java.sql.DriverManager"%> <%! private static final String cvsId = "$Id: ws_import_translation.jsp,v 1.1 2014/11/06 00:03:12 ned Exp $"; %> <%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ page import="java.util.*, java.text.*" %> <%@ page import="com.hof.web.form.*" %> <%@ page import="com.hof.mi.web.service.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.io.ByteArrayOutputStream" %> <%@ page import="java.io.DataInputStream" %> <%! private Map handlePost(HttpServletRequest request) throws Exception { String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) { DataInputStream in = new DataInputStream(request.getInputStream()); //we are taking the length of Content type data int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0; //this loop converting the uploaded file into byte code while (totalBytesRead < formDataLength) { byteRead = in.read(dataBytes, totalBytesRead,formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes); //for saving the file name String saveFile = file.substring(file.indexOf("filename=\"") + 10); saveFile = saveFile.substring(0, saveFile.indexOf("\n")); saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\"")); int lastIndex = contentType.lastIndexOf("="); String boundary = contentType.substring(lastIndex + 1, contentType.length()); int pos; //extracting the index of file pos = file.indexOf("filename=\""); pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; int boundaryLocation = file.indexOf(boundary, pos) - 4; int startPos = ((file.substring(0, pos)).getBytes()).length; int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length; ByteArrayOutputStream fileOut = new ByteArrayOutputStream(); fileOut.write(dataBytes, startPos, (endPos - startPos)); fileOut.flush(); fileOut.close(); Map result = new HashMap(); result.put("data", fileOut.toByteArray()); result.put("fileExtension", saveFile.substring(saveFile.lastIndexOf(".") + 1).getBytes()); return result; } return null; } %> <% try { List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); String xmlString = null; byte[] data = null; for (FileItem item : items) { if(!item.isFormField()) { data = item.get(); break; } } String hostName = "localhost"; String yellowfinPath = "/"; int port = 8735; // JDBC URL //Enter your admin details here String adminUser = "admin@yellowfin.com.au"; String adminPass = "test"; AdministrationServiceResponse rs = null; AdministrationServiceRequest rsr = new AdministrationServiceRequest(); AdministrationServiceService ts = new AdministrationServiceServiceLocator(hostName, port, yellowfinPath + "/services/AdministrationService", false); AdministrationServiceSoapBindingStub rssbs = (AdministrationServiceSoapBindingStub) ts.getAdministrationService(); //Validate the user rsr.setLoginId(adminUser); rsr.setPassword(adminPass); rsr.setOrgId(new Integer(1)); rsr.setFunction("UPLOADLICENCE"); rsr.setBinaryData(data); AdministrationPerson ap = new AdministrationPerson(); ap.setUserId(adminUser); ap.setPassword(adminUser); rsr.setPerson(ap); rs = rssbs.remoteAdministrationCall(rsr); } catch(Exception e) { %>

<% } %>