List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:ORG.oclc.os.SRW.SRWServlet.java
/** * Process GET requests. This includes handoff of pseudo-SOAP requests * * @param request request in/*from ww w .j a va2 s. c o m*/ * @param response request out * @throws ServletException * @throws IOException */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long time = System.currentTimeMillis(); servletLog.debug("Enter: doGet()"); if ("APP".equals(request.getAttribute("service"))) { if (log.isDebugEnabled()) log.debug("in doGet: got APP request for " + request.getRequestURI()); } try { AxisEngine engine = getEngine(); ServletContext servletContext = getServletConfig().getServletContext(); String pathInfo = request.getPathInfo(); String realpath = servletContext.getRealPath(request.getServletPath()); if (realpath == null) { realpath = request.getServletPath(); } boolean wsdlRequested = false; boolean listRequested = false; boolean hasParameters = request.getParameterNames().hasMoreElements(); //JWS pages are special; they are the servlet path and there //is no pathinfo...we map the pathinfo to the servlet path to keep //it happy boolean isJWSPage = request.getRequestURI().endsWith(".jws"); if (isJWSPage) { pathInfo = request.getServletPath(); } // check first if we are doing WSDL or a list operation String queryString = request.getQueryString(); boolean doExplain = false; if (queryString != null) { if (queryString.equalsIgnoreCase("wsdl")) { wsdlRequested = true; } else if (queryString.equalsIgnoreCase("list")) { listRequested = true; } else { String operation = request.getParameter("operation"); // MIH changed to one if-statement///////////////////// if (operation != null && operation.equals("explain")) { doExplain = true; } else if (request.getParameter("query") == null && request.getParameter("scanClause") == null) { doExplain = true; } //////////////////////////////////////////////////////// } } else doExplain = true; boolean hasNoPath = (pathInfo == null || pathInfo.equals("")); if (!wsdlRequested && !listRequested && hasNoPath && srwInfo.defaultDatabase == null) { // If the user requested the servlet (i.e. /axis/servlet/AxisServlet) // with no service name, present the user with a list of deployed // services to be helpful // Don't do this if we are doing WSDL or list. reportAvailableServices(response, request); } else if (realpath != null || doExplain) { // We have a pathname, so now we perform WSDL or list operations // get message context w/ various properties set MessageContext msgContext = createMessageContext(engine, request, response); if (doExplain) { srwInfo.handleExplain(request, response, msgContext); return; } // NOTE: HttpUtils.getRequestURL has been deprecated. // This line SHOULD be: // String url = req.getRequestURL().toString() // HOWEVER!!!! DON'T REPLACE IT! There's a bug in // req.getRequestURL that is not in HttpUtils.getRequestURL // req.getRequestURL returns "localhost" in the remote // scenario rather than the actual host name. // // ? Still true? For which JVM's? //String url = HttpUtils.getRequestURL(request).toString(); String url = request.getRequestURL().toString(); msgContext.setProperty(MessageContext.TRANS_URL, url); if (wsdlRequested) { // Do WSDL generation //MIH: get serviceName from URL////////////////////////// String serviceName = url.replaceAll(".*/", ""); if (serviceName == null || serviceName.equals("")) { serviceName = "SRW"; } msgContext.setTargetService(serviceName); ///////////////////////////////////////////////////////// ///MIH: add request to parameters//////////////////////// // processWsdlRequest(msgContext, response); processWsdlRequest(msgContext, response, request); ///////////////////////////////////////////////////////// } else if (listRequested) { // Do list, if it is enabled processListRequest(response); } else if (hasParameters) { // If we have ?method=x¶m=y in the URL, make a stab // at invoking the method with the parameters specified // in the URL processMethodRequest(msgContext, request, response); } else { // See if we can locate the desired service. If we // can't, return a 404 Not Found. Otherwise, just // print the placeholder message. String serviceName; if (pathInfo.startsWith("/")) { serviceName = pathInfo.substring(1); } else { serviceName = pathInfo; } SOAPService s = engine.getService(serviceName); if (s == null) { //no service: report it if (isJWSPage) { reportCantGetJWSService(request, response); } else { reportCantGetAxisService(request, response); } } else { //print a snippet of service info. reportServiceInfo(response, s, serviceName); } } } else { // We didn't have a real path in the request, so just // print a message informing the user that they reached // the servlet. response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println("<html><h1>Axis HTTP Servlet</h1>"); writer.println(Messages.getMessage("reachedServlet00")); writer.println("<p>" + Messages.getMessage("transportName00", "<b>" + transportName + "</b>")); writer.println("</html>"); writer.close(); } } catch (AxisFault fault) { reportTroubleInGet(fault, response); } catch (Exception e) { reportTroubleInGet(e, response); } finally { //writer.close(); servletLog.debug("Exit: doGet()"); servletLog.info("total request-response time: " + (System.currentTimeMillis() - time) + " ms"); } }
From source file:com.rapid.core.Application.java
public static String getConfigFolder(ServletContext servletContext, String id, String version) { return servletContext.getRealPath("/WEB-INF/applications/" + id + "/" + version); }
From source file:com.rapid.core.Application.java
public static String getWebFolder(ServletContext servletContext, String id, String version) { return servletContext.getRealPath("/applications/" + id + "/" + version); }
From source file:org.bibalex.wamcp.application.WAMCPUiActionListener.java
public WAMCPUiActionListener(String cONFIGSCHEMAFILE, String cONFIGROOTELTNAME, String cONFIGNAMESPACE, WAMCPSessionBackingBean sessionBBean, BAGAlbumBBean albumBBean) { super(cONFIGSCHEMAFILE, cONFIGROOTELTNAME, cONFIGNAMESPACE); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext();//from w w w . ja v a 2 s . co m this.xsdFilePath = servletContext.getRealPath(cONFIGSCHEMAFILE); this.xsdFilePath = "file:///" + this.xsdFilePath; this.schemaLocations = cONFIGNAMESPACE + " " + this.xsdFilePath; this.sessionBBean = sessionBBean; this.wamcpSessionBBean = sessionBBean; // Tell the longer life bean About yourself this.wamcpSessionBBean.setUiActionListener(this); this.albumBBean = albumBBean; // Tell the longer lived bean about yourself albumBBean.setControllingReqBBean(this); }
From source file:org.bibalex.wamcp.application.WAMCPUiActionListener.java
@Override public void initEditSession() throws XSAException { if (this.wamcpSessionBBean.isInEditSession()) { LOG.warn("Last edit session not properly closed. Will close now!"); this.uninitEditSession(); }// w ww. jav a 2 s . com ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String schemaFilePath = servletContext.getRealPath(this.CONFIG_SCHEMA_FILE); try { this.sdxeMediator.open(this.wamcpStorage.getWorkingFile().getCanonicalPath(), schemaFilePath); XSALocator siteLoc = this.xsaDoc.getSiteLocator(); this.sdxeMediator.moveToSugtnPath(siteLoc.asString()); this.uiGenDomListener.init(); // Immitate the first event that is not always caught! this.uiGenDomListener.notifyDomMovedVertical(this.sdxeMediator.getCurrentSugtnElement()); String filename = WAMCPStorage.filenameForShelfMark(this.wamcpStorage.getArtifact().getArtifactName()); BAGAlbum albumForMsDesc = this.galleryBean.openAlbumForMetadataFile(filename); this.albumBBean.setAlbum(albumForMsDesc); } catch (SDXEException e) { throw new XSAException(e); } catch (IOException e) { throw new XSAException(e); } catch (JDOMException e) { throw new XSAException(e); } catch (BAGException e) { throw new XSAException(e); } }
From source file:com.rapid.core.Application.java
public static String getBackupFolder(ServletContext servletContext, String id, String version, boolean allVersions) { if (allVersions) { return servletContext.getRealPath("/WEB-INF/applications/" + BACKUP_FOLDER + "/" + id + "/" + version); } else {/*from w w w.j a v a 2 s. com*/ return servletContext.getRealPath("/WEB-INF/applications/" + id + "/" + version + "/" + BACKUP_FOLDER); } }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase.java
public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); boolean migrationChangesMade = false; try {//w w w.j av a 2s . co m UpdateSettings settings = new UpdateSettings(); putReportingPathsIntoSettings(ctx, settings); putNonReportingPathsIntoSettings(ctx, settings); try { ApplicationUtils.instance().getTBoxReasonerModule().waitForTBoxReasoning(); } catch (Exception e) { // Should mean that the reasoner is not even started yet. } WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory(); settings.setDefaultNamespace(wadf.getDefaultNamespace()); settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getOntModelSelector(ASSERTIONS_ONLY)); settings.setInferenceOntModelSelector(ModelAccess.on(ctx).getOntModelSelector(INFERENCES_ONLY)); settings.setUnionOntModelSelector(ModelAccess.on(ctx).getOntModelSelector()); Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath(); settings.setDisplayModel(ModelAccess.on(ctx).getOntModel(DISPLAY)); OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(oldTBoxModelDir())); settings.setOldTBoxModel(oldTBoxModel); OntModel newTBoxModel = loadModelFromDirectory( createDirectory(homeDir, "rdf", "tbox", "filegraph").toString()); settings.setNewTBoxModel(newTBoxModel); OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(oldTBoxAnnotationsDir())); settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel); OntModel newTBoxAnnotationsModel = loadModelFromDirectory( createDirectory(homeDir, "rdf", "tbox", "firsttime").toString()); settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel); settings.setRDFService(ModelAccess.on(ctx).getRDFService()); boolean tryMigrateDisplay = true; try { //Display model tbox and display metadata //old display model tbox model OntModel oldDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(oldDisplayModelTBoxPath())); settings.setOldDisplayModelTboxModel(oldDisplayModelTboxModel); //new display model tbox model OntModel newDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_TBOX_PATH)); settings.setNewDisplayModelTboxModel(newDisplayModelTboxModel); //old display model display model metadata OntModel oldDisplayModelDisplayMetadataModel = loadModelFromFile( ctx.getRealPath(oldDisplayModelDisplayMetadataPath())); settings.setOldDisplayModelDisplayMetadataModel(oldDisplayModelDisplayMetadataModel); //new display model display model metadata OntModel newDisplayModelDisplayMetadataModel = loadModelFromFile( ctx.getRealPath(NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH)); settings.setNewDisplayModelDisplayMetadataModel(newDisplayModelDisplayMetadataModel); //Get new display model OntModel newDisplayModelFromFile = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_PATH)); settings.setNewDisplayModelFromFile(newDisplayModelFromFile); OntModel loadedAtStartupFiles = loadModelFromDirectory( ctx.getRealPath(LOADED_STARTUPT_DISPLAYMODEL_DIR)); settings.setLoadedAtStartupDisplayModel(loadedAtStartupFiles); OntModel oldDisplayModelVivoListView = loadModelFromFile( ctx.getRealPath(oldDisplayModelVivoListViewPath())); settings.setVivoListViewConfigDisplayModel(oldDisplayModelVivoListView); } catch (ModelFileNotFoundException e) { // expected if no display migration was intended tryMigrateDisplay = false; } catch (Exception e) { log.info("Unable to read display model migration files. ", e); tryMigrateDisplay = false; } KnowledgeBaseUpdater ontologyUpdater = new KnowledgeBaseUpdater(settings); boolean requiredUpdate = ontologyUpdater.updateRequired(ctx); if (requiredUpdate && !JenaDataSourceSetupBase.isFirstStartup()) { try { ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE); migrationChangesMade = ontologyUpdater.update(ctx); if (tryMigrateDisplay) { try { migrateDisplayModel(settings); log.info("Migrated display model"); } catch (Exception e) { log.warn("unable to successfully update display model: " + e.getMessage()); } } // reload the display model since the TBoxUpdater may have // modified it new ConfigurationModelsSetup().contextInitialized(sce); } catch (Exception ioe) { ss.fatal(parent, "Exception updating knowledge base for ontology changes: ", ioe); } } removeBadRestrictions(settings.getAssertionOntModelSelector().getTBoxModel()); log.info("Simple reasoner connected for the ABox"); if (JenaDataSourceSetupBase.isFirstStartup() || (migrationChangesMade && requiredUpdate)) { SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.FOREGROUND); } else if (migrationChangesMade) { SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.BACKGROUND); } } catch (Throwable t) { ss.fatal(parent, "Exception updating knowledge base for ontology changes: ", t); } }
From source file:org.codelibs.fess.job.SuggestJob.java
protected void executeSuggestCreator() { final List<String> cmdList = new ArrayList<>(); final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":"; final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class); final ProcessHelper processHelper = ComponentUtil.getProcessHelper(); final FessConfig fessConfig = ComponentUtil.getFessConfig(); cmdList.add(fessConfig.getJavaCommandPath()); // -cp/*ww w .j a va 2 s. c o m*/ cmdList.add("-cp"); final StringBuilder buf = new StringBuilder(100); ResourceUtil.getOverrideConfPath().ifPresent(p -> { buf.append(p); buf.append(cpSeparator); }); final String confPath = System.getProperty(Constants.FESS_CONF_PATH); if (StringUtil.isNotBlank(confPath)) { buf.append(confPath); buf.append(cpSeparator); } // WEB-INF/env/suggest/resources buf.append("WEB-INF"); buf.append(File.separator); buf.append("env"); buf.append(File.separator); buf.append("suggest"); buf.append(File.separator); buf.append("resources"); buf.append(cpSeparator); // WEB-INF/classes buf.append("WEB-INF"); buf.append(File.separator); buf.append("classes"); // target/classes final String userDir = System.getProperty("user.dir"); final File targetDir = new File(userDir, "target"); final File targetClassesDir = new File(targetDir, "classes"); if (targetClassesDir.isDirectory()) { buf.append(cpSeparator); buf.append(targetClassesDir.getAbsolutePath()); } // WEB-INF/lib appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/lib")), "WEB-INF" + File.separator + "lib" + File.separator); // WEB-INF/env/suggest/lib appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/env/suggest/lib")), "WEB-INF" + File.separator + "env" + File.separator + "suggest" + File.separator + "lib" + File.separator); final File targetLibDir = new File(targetDir, "fess" + File.separator + "WEB-INF" + File.separator + "lib"); if (targetLibDir.isDirectory()) { appendJarFile(cpSeparator, buf, targetLibDir, targetLibDir.getAbsolutePath() + File.separator); } cmdList.add(buf.toString()); if (useLocalElasticsearch) { final String transportAddresses = System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES); if (StringUtil.isNotBlank(transportAddresses)) { cmdList.add("-D" + Constants.FESS_ES_TRANSPORT_ADDRESSES + "=" + transportAddresses); } } final String systemLastaEnv = System.getProperty("lasta.env"); if (StringUtil.isNotBlank(systemLastaEnv)) { if (systemLastaEnv.equals("web")) { cmdList.add("-Dlasta.env=suggest"); } else { cmdList.add("-Dlasta.env=" + systemLastaEnv); } } else if (StringUtil.isNotBlank(lastaEnv)) { cmdList.add("-Dlasta.env=" + lastaEnv); } addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null); cmdList.add("-Dfess.suggest.process=true"); if (logFilePath == null) { final String value = System.getProperty("fess.log.path"); logFilePath = value != null ? value : new File(targetDir, "logs").getAbsolutePath(); } cmdList.add("-Dfess.log.path=" + logFilePath); addSystemProperty(cmdList, "fess.log.name", "fess-suggest", "-suggest"); if (logLevel == null) { addSystemProperty(cmdList, "fess.log.level", null, null); } else { cmdList.add("-Dfess.log.level=" + logLevel); } stream(fessConfig.getJvmSuggestOptionsAsArray()) .of(stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value))); File ownTmpDir = null; final String tmpDir = System.getProperty("java.io.tmpdir"); if (fessConfig.isUseOwnTmpDir() && StringUtil.isNotBlank(tmpDir)) { ownTmpDir = new File(tmpDir, "fessTmpDir_" + sessionId); if (ownTmpDir.mkdirs()) { cmdList.add("-Djava.io.tmpdir=" + ownTmpDir.getAbsolutePath()); } else { ownTmpDir = null; } } if (StringUtil.isNotBlank(jvmOptions)) { split(jvmOptions, " ").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(s -> cmdList.add(s))); } cmdList.add(SuggestCreator.class.getCanonicalName()); cmdList.add("--sessionId"); cmdList.add(sessionId); File propFile = null; try { cmdList.add("-p"); propFile = File.createTempFile("suggest_", ".properties"); cmdList.add(propFile.getAbsolutePath()); try (FileOutputStream out = new FileOutputStream(propFile)) { final Properties prop = new Properties(); prop.putAll(ComponentUtil.getSystemProperties()); prop.store(out, cmdList.toString()); } final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile(); if (logger.isInfoEnabled()) { logger.info("SuggestCreator: \nDirectory=" + baseDir + "\nOptions=" + cmdList); } final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> { pb.directory(baseDir); pb.redirectErrorStream(true); }); final InputStreamThread it = jobProcess.getInputStreamThread(); it.start(); final Process currentProcess = jobProcess.getProcess(); currentProcess.waitFor(); it.join(5000); final int exitValue = currentProcess.exitValue(); if (logger.isInfoEnabled()) { logger.info("SuggestCreator: Exit Code=" + exitValue + " - SuggestCreator Process Output:\n" + it.getOutput()); } if (exitValue != 0) { throw new FessSystemException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput()); } ComponentUtil.getPopularWordHelper().clearCache(); } catch (final FessSystemException e) { throw e; } catch (final InterruptedException e) { logger.warn("SuggestCreator Process interrupted."); } catch (final Exception e) { throw new FessSystemException("SuggestCreator Process terminated.", e); } finally { try { processHelper.destroyProcess(sessionId); } finally { if (propFile != null && !propFile.delete()) { logger.warn("Failed to delete {}.", propFile.getAbsolutePath()); } deleteTempDir(ownTmpDir); } } }
From source file:org.apache.jsp.fileUploader_jsp.java
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null;/*from w ww . j a v a 2 s. c o m*/ HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=utf-8"); pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("<!--\n"); out.write("Copyright 2012 The Infinit.e Open Source Project\n"); out.write("\n"); out.write("Licensed under the Apache License, Version 2.0 (the \"License\");\n"); out.write("you may not use this file except in compliance with the License.\n"); out.write("You may obtain a copy of the License at\n"); out.write("\n"); out.write(" http://www.apache.org/licenses/LICENSE-2.0\n"); out.write("\n"); out.write("Unless required by applicable law or agreed to in writing, software\n"); out.write("distributed under the License is distributed on an \"AS IS\" BASIS,\n"); out.write("WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); out.write("See the License for the specific language governing permissions and\n"); out.write("limitations under the License.\n"); out.write("-->\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"); out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"); out.write("<head>\n"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"); out.write("<title>Infinit.e File Upload Tool</title>\n"); out.write("<style media=\"screen\" type=\"text/css\">\n"); out.write("\n"); out.write("body \n"); out.write("{\n"); out.write("\tfont: 14px Arial,sans-serif;\n"); out.write("}\n"); out.write("h2\n"); out.write("{\n"); out.write("\tfont-family: \"Times New Roman\";\n"); out.write("\tfont-style: italic;\n"); out.write("\tfont-variant: normal;\n"); out.write("\tfont-weight: normal;\n"); out.write("\tfont-size: 24px;\n"); out.write("\tline-height: 29px;\n"); out.write("\tfont-size-adjust: none;\n"); out.write("\tfont-stretch: normal;\n"); out.write("\t-x-system-font: none;\n"); out.write("\tcolor: #d2331f;\n"); out.write("\tmargin-bottom: 25px;\n"); out.write("}\n"); out.write(".show {\n"); out.write("display: ;\n"); out.write("visibility: visible;\n"); out.write("}\n"); out.write(".hide {\n"); out.write("display: none;\n"); out.write("visibility: hidden;\n"); out.write("}\n"); out.write("</style>\n"); out.write("<script language=\"javascript\" src=\"AppConstants.js\"> </script>\n"); out.write("</head>\n"); out.write("\n"); out.write("<body onload=\"populate()\">\n"); if (API_ROOT == null) { ServletContext context = session.getServletContext(); String realContextPath = context.getRealPath("/"); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); try { // EC2 Machines FileReader reader = new FileReader(realContextPath + "/AppConstants.js"); engine.eval(reader); reader.close(); engine.eval("output = getEndPointUrl();"); API_ROOT = (String) engine.get("output"); SHARE_ROOT = API_ROOT + "share/get/"; } catch (Exception je) { try { ////////////Windows + Tomcat FileReader reader = new FileReader(realContextPath + "\\..\\AppConstants.js"); engine.eval(reader); reader.close(); engine.eval("output = getEndPointUrl();"); API_ROOT = (String) engine.get("output"); SHARE_ROOT = API_ROOT + "share/get/"; } catch (Exception e) { System.err.println(e.toString()); } } if (null == API_ROOT) { // Default to localhost API_ROOT = "http://localhost:8080/api/"; SHARE_ROOT = "$infinite/share/get/"; } if (API_ROOT.contains("localhost")) localCookie = true; else localCookie = false; } Boolean isLoggedIn = isLoggedIn(request, response); if (isLoggedIn == null) { out.println("The Infinit.e API cannot be reached."); out.println(API_ROOT); } else if (isLoggedIn == true) { showAll = (request.getParameter("sudo") != null); DEBUG_MODE = (request.getParameter("debug") != null); communityList = generateCommunityList(request, response); if (request.getParameter("logout") != null) { logOut(request, response); out.println("<div style=\" text-align: center;\">"); out.println("<meta http-equiv=\"refresh\" content=\"0\">"); out.println("</div>"); } else { out.println("<div style=\" text-align: center;\">"); String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) { // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); // Parse the request FileItemIterator iter = upload.getItemIterator(request); byte[] fileBytes = null; String fileDS = null; byte[] iconBytes = null; String iconDS = null; Set<String> communities = new HashSet<String>(); boolean isFileSet = false; while (iter.hasNext()) { FileItemStream item = iter.next(); String name = item.getFieldName(); InputStream stream = item.openStream(); if (item.isFormField()) { if (name.equalsIgnoreCase("communities")) { communities.add(Streams.asString(stream)); } else request.setAttribute(name, Streams.asString(stream)); //out.println("<b>" + name + ":</b>" + request.getAttribute(name).toString()+"</br>"); } else { if (name.equalsIgnoreCase("file")) { if (!item.getName().equals("")) isFileSet = true; fileDS = item.getContentType(); fileBytes = IOUtils.toByteArray(stream); // Check if this should be a java-archive (rather than just an octet stream) if (fileDS.equals("application/octet-stream")) { ZipInputStream zis = new ZipInputStream( new ByteArrayInputStream(fileBytes)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (entry.getName().endsWith(".class")) { fileDS = "application/java-archive"; break; } } } // Reset stream, and read } } } ////////////////////////////////////Delete Share //////////////////////////////// if (request.getAttribute("deleteId") != null) { String fileId = request.getAttribute("deleteId").toString(); if (fileId != null && fileId != "") removeFromShare(fileId, request, response).toString(); } ////////////////////////////////////Update Community Info//////////////////////////////// else if (null == fileBytes) { String shareId = request.getAttribute("DBId").toString(); if (shareId != null && shareId != "") addRemoveCommunities(shareId, communities, request, response); } else { ////////////////////////////////////////////////////////////////////////////////// Boolean newUpload = (request.getAttribute("DBId").toString().length() == 0); ///////////////////////////////// SWF Manip ///////////////////////////////// String shareId = request.getAttribute("DBId").toString(); String fileUrl = ""; String fileId = ""; String bin = request.getAttribute("binary").toString(); if (request.getAttribute("title") != null && request.getAttribute("description") != null && fileBytes != null) { if (!isFileSet) //if not a binary file or file was not changed { fileId = shareId; if (shareId != null && shareId != "") addRemoveCommunities(shareId, communities, request, response); out.println("File was not set, just updated communities."); } else if (bin.equals("null")) //is a json file, make sure its okay and upload it { fileId = UpdateToShare(fileBytes, fileDS, request.getAttribute("title").toString(), request.getAttribute("description").toString(), shareId, communities, true, request.getAttribute("type").toString(), newUpload, request, response); } else //is a binary, do normal { fileId = UpdateToShare(fileBytes, fileDS, request.getAttribute("title").toString(), request.getAttribute("description").toString(), shareId, communities, false, request.getAttribute("type").toString(), newUpload, request, response); } if (fileId.contains("Failed")) { out.println(fileId); } else { fileUrl = SHARE_ROOT + fileId; if (newUpload) out.println( "You have successfully added a file to the share, its location is: " + fileUrl); else out.println( "You have successfully updated a file on the share, its location is: " + fileUrl); } } else { fileUrl = null; out.println("Error: Not enough information provided for file Upload"); } ///////////////////////////////// End File Manip ///////////////////////////////// out.println("</div>"); } } else { } out.write("\n"); out.write("\t\n"); out.write("\t<script>\n"); out.write("\tfunction clearCommList()\n"); out.write("\t\t{\n"); out.write("\t\t\tmult_comms = document.getElementById('communities');\n"); out.write("\t\t\tfor ( var i = 0, l = mult_comms.options.length, o; i < l; i++ )\n"); out.write("\t\t\t{\n"); out.write("\t\t\t o = mult_comms.options[i];\n"); out.write("\t\t\t o.selected = false;\n"); out.write("\t\t\t}\n"); out.write("\t\t}\n"); out.write("\t\tfunction highlightComms(commList)\n"); out.write("\t\t{\n"); out.write("\t\t\tmult_comms = document.getElementById('communities');\n"); out.write("\t\t\tfor ( var i = 0, l = mult_comms.options.length, o; i < l; i++ )\n"); out.write("\t\t\t{\n"); out.write("\t\t\t o = mult_comms.options[i];\n"); out.write("\t\t\t if(commList.indexOf(o.value) == -1)\n"); out.write("\t\t\t\to.selected = false;\n"); out.write("\t\t\t else \n"); out.write("\t\t\t \to.selected = true;\n"); out.write("\t\t\t}\n"); out.write("\t\t}\n"); out.write("\tfunction populate()\n"); out.write("\t{\n"); out.write("\t\tvar typerow = document.getElementById('typerow');\n"); out.write("\t\tvar type = document.getElementById('type');\n"); out.write("\t\tvar title = document.getElementById('title');\n"); out.write("\t\tvar description = document.getElementById('description');\n"); out.write("\t\tvar file = document.getElementById('file');\n"); out.write("\t\tvar created = document.getElementById('created');\n"); out.write("\t\tvar DBId = document.getElementById('DBId');\n"); out.write("\t\tvar deleteId = document.getElementById('deleteId');\n"); out.write("\t\tvar deleteButton = document.getElementById('deleteButton');\n"); out.write("\t\tvar share_url = document.getElementById('share_url');\n"); out.write("\t\tvar owner_text = document.getElementById('owner_text');\n"); out.write("\t\tvar owner = document.getElementById('owner');\n"); out.write("\t\tvar url_row = document.getElementById('url_row');\n"); out.write("\t\tvar dropdown = document.getElementById(\"upload_info\");\n"); out.write("\t\tvar list = dropdown.options[dropdown.selectedIndex].value;\n"); out.write("\t\tvar binary = document.getElementById(\"binary\");\n"); out.write("\t\t\n"); out.write("\t\tif (list == \"new\")\n"); out.write("\t\t{\n"); out.write("\t\t\ttitle.value = \"\";\n"); out.write("\t\t\tdescription.value = \"\";\n"); out.write("\t\t\ttype.value = \"binary\";\n"); out.write("\t\t\tcreated.value = \"\";\n"); out.write("\t\t\tDBId.value = \"\";\n"); out.write("\t\t\tdeleteId.value = \"\";\n"); out.write("\t\t\tshare_url.value = \"\";\n"); out.write("\t\t\towner.value = \"\";\n"); out.write("\t\t\ttyperow.className = \"hide\";\n"); out.write("\t\t\turl_row.className = \"hide\";\n"); out.write("\t\t\towner.className = \"hide\";\n"); out.write("\t\t\towner_text.className = \"hide\";\n"); out.write("\t\t\tdeleteButton.className = \"hide\";\n"); out.write("\t\t\tclearCommList();\n"); out.write("\t\t\tbinary.value = \"\";\n"); out.write("\t\t\treturn;\n"); out.write("\t\t}\n"); out.write("\t\t\n"); out.write("\t\tif ( list == \"newJSON\")\n"); out.write("\t\t{\n"); out.write("\t\t\ttitle.value = \"\";\n"); out.write("\t\t\tdescription.value = \"\";\n"); out.write("\t\t\ttype.value = \"\";\n"); out.write("\t\t\tcreated.value = \"\";\n"); out.write("\t\t\tDBId.value = \"\";\n"); out.write("\t\t\tdeleteId.value = \"\";\n"); out.write("\t\t\tshare_url.value = \"\";\n"); out.write("\t\t\towner.value = \"\";\n"); out.write("\t\t\ttyperow.className = \"show\";\n"); out.write("\t\t\turl_row.className = \"hide\";\n"); out.write("\t\t\towner.className = \"hide\";\n"); out.write("\t\t\towner_text.className = \"hide\";\n"); out.write("\t\t\tdeleteButton.className = \"hide\";\n"); out.write("\t\t\tclearCommList();\n"); out.write("\t\t\tbinary.value = \"null\";\n"); out.write("\t\t\treturn;\n"); out.write("\t\t}\n"); out.write("\t\t\n"); out.write("\t\t//_id, created, title, description\n"); out.write("\t\tsplit = list.split(\"$$$\");\n"); out.write("\t\t\n"); out.write("\t\tres_id = split[0];\n"); out.write("\t\tres_created = split[1];\n"); out.write("\t\tres_title = split[2];\n"); out.write("\t\tres_description = split[3];\n"); out.write("\t\tres_url = split[4];\n"); out.write("\t\tcommunities = split[5];\n"); out.write("\t\tres_owner = split[6];\n"); out.write("\t\tres_binary = split[7];\t\t\n"); out.write("\t\tres_type = split[8];\t\t\t\n"); out.write("\t\t\n"); out.write("\t\tif ( res_binary == \"null\" )\n"); out.write("\t\t{\n"); out.write("\t\t\ttyperow.className = \"show\";\n"); out.write("\t\t}\n"); out.write("\t\telse\n"); out.write("\t\t{\n"); out.write("\t\t\ttyperow.className = \"hide\";\n"); out.write("\t\t}\n"); out.write("\t\ttitle.value = res_title;\n"); out.write("\t\tdescription.value = res_description;\n"); out.write("\t\tcreated.value = res_created;\n"); out.write("\t\tDBId.value = res_id;\n"); out.write("\t\tdeleteId.value = res_id;\n"); out.write("\t\tshare_url.value = res_url;\n"); out.write("\t\towner.value = res_owner;\t\t\n"); out.write("\t\tdeleteButton.className = \"show\";\n"); out.write("\t\towner.className = \"show\";\n"); out.write("\t\towner_text.className = \"show\";\n"); out.write("\t\turl_row.className = \"show\";\n"); out.write("\t\thighlightComms(communities);\t\t\n"); out.write("\t\tbinary.value = res_binary;\n"); out.write("\t\ttype.value = res_type;\n"); out.write("\t}\n"); out.write("\t\tfunction validate_fields()\n"); out.write("\t\t{\n"); out.write("\t\t\ttitle = document.getElementById('title').value;\n"); out.write("\t\t\tdescription = document.getElementById('description').value;\n"); out.write("\t\t\tfile = document.getElementById('file').value;\n"); out.write("\t\t\tbinary = document.getElementById(\"binary\").value;\n"); out.write("\t\t\ttype = document.getElementById(\"type\").value;\n"); out.write("\t\t\t//share_url = document.getElementById('share_url').value;\n"); out.write("\t\t\t//file_url = document.getElementById('file_url').value;\n"); out.write("\t\t\t//file_check = document.getElementById('file_check').checked;\n"); out.write("\t\t\t\n"); out.write("\t\t\tif (title == \"\")\n"); out.write("\t\t\t{\n"); out.write("\t\t\t\talert('Please provide a title.');\n"); out.write("\t\t\t\treturn false;\n"); out.write("\t\t\t}\n"); out.write("\t\t\tif (description == \"\")\n"); out.write("\t\t\t{\n"); out.write("\t\t\t\talert('Please provide a description.');\n"); out.write("\t\t\t\treturn false;\n"); out.write("\t\t\t}\n"); out.write("\t\t\tif ( binary == \"null\" && type == \"\")\n"); out.write("\t\t\t{\n"); out.write("\t\t\t\talert('Please provide a type.');\n"); out.write("\t\t\t\treturn false;\n"); out.write("\t\t\t}\n"); out.write("\t\t\t\n"); out.write("\t\t\t\n"); out.write("\t\t}\n"); out.write("\t\tfunction confirmDelete()\n"); out.write("\t\t{\n"); out.write( "\t\t\tvar agree=confirm(\"Are you sure you wish to Delete this file from the File Share?\");\n"); out.write("\t\t\tif (agree)\n"); out.write("\t\t\t\treturn true ;\n"); out.write("\t\t\telse\n"); out.write("\t\t\t\treturn false ;\n"); out.write("\t\t}\n"); out.write("\t\tfunction showResults()\n"); out.write("\t\t{\n"); out.write("\t\t\tvar title = document.getElementById('DBId').value;\n"); out.write("\t\t\tvar url = getEndPointUrl() + \"share/get/\" + title;\n"); out.write("\t\t\twindow.open(url, '_blank');\n"); out.write("\t\t\twindow.focus();\t\t\t\n"); out.write("\t\t}\n"); out.write("\t\t// -->\n"); out.write("\t\t</script>\n"); out.write("\t</script>\n"); out.write( "\t\t<div id=\"uploader_outter_div\" name=\"uploader_outter_div\" align=\"center\" style=\"width:100%\" >\n"); out.write( "\t \t<div id=\"uploader_div\" name=\"uploader_div\" style=\"border-style:solid; border-color:#999999; border-radius: 10px; width:475px; margin:auto\">\n"); out.write("\t \t<h2>File Uploader</h2>\n"); out.write("\t \t<form id=\"search_form\" name=\"search_form\" method=\"get\">\n"); out.write("\t \t\t<div align=\"center\"\">\n"); out.write("\t \t\t<label for=\"ext\">Filter On</label>\n"); out.write("\t\t\t\t\t <select name=\"ext\" id=\"ext\" onchange=\"this.form.submit();\">\n"); out.write("\t\t\t\t\t "); out.print(populateMediaTypes(request, response)); out.write("\n"); out.write("\t\t\t\t\t </select>\n"); out.write("\t\t\t\t\t </div>\n"); out.write("\t\t\t\t\t "); if (showAll) out.print("<input type=\"hidden\" name=\"sudo\" id=\"sudo\" value=\"true\" />"); out.write("\t \t\t\n"); out.write("\t \t</form>\n"); out.write( "\t \t<form id=\"delete_form\" name=\"delete_form\" method=\"post\" enctype=\"multipart/form-data\" onsubmit=\"javascript:return confirmDelete()\" >\n"); out.write( "\t \t\t<select id=\"upload_info\" onchange=\"populate()\" name=\"upload_info\"><option value=\"new\">Upload New File</option><option value=\"newJSON\">Upload New JSON</option> "); out.print(populatePreviousUploads(request, response)); out.write("</select>\n"); out.write( "\t \t\t<input type=\"submit\" name=\"deleteButton\" id=\"deleteButton\" class=\"hidden\" value=\"Delete\" />\n"); out.write("\t \t\t<input type=\"hidden\" name=\"deleteId\" id=\"deleteId\" />\n"); out.write("\t \t\t<input type=\"hidden\" name=\"deleteFile\" id=\"deleteFile\" />\n"); out.write("\t\t\t\t\t "); if (showAll) out.print("<input type=\"hidden\" name=\"sudo\" id=\"sudo\" value=\"true\" />"); out.write("\t \t\t\n"); out.write("\t \t</form>\n"); out.write( "\t <form id=\"upload_form\" name=\"upload_form\" method=\"post\" enctype=\"multipart/form-data\" onsubmit=\"javascript:return validate_fields();\" >\n"); out.write( "\t <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding-left:10px; padding-right:10px\">\n"); out.write("\t <tr>\n"); out.write("\t <td colspan=\"2\" align=\"center\"></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write("\t <td>Title:</td>\n"); out.write( "\t <td><input type=\"text\" name=\"title\" id=\"title\" size=\"39\" /></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write("\t <td>Description:</td>\n"); out.write( "\t <td><textarea rows=\"4\" cols=\"30\" name=\"description\" id=\"description\" ></textarea></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr id=\"typerow\">\n"); out.write("\t <td>Type:</td>\n"); out.write( "\t <td><input type=\"text\" name=\"type\" id=\"type\" size=\"39\" /></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write("\t \t<td>Communities:</td>\n"); out.write("\t \t<td>"); out.print(communityList); out.write("</td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write("\t \t<td id=\"owner_text\">Owner:</td>\n"); out.write("\t \t<td>\n"); out.write( "\t <input type=\"text\" name=\"owner\" id=\"owner\" readonly=\"readonly\" size=\"25\" />\n"); out.write("\t \t</td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write("\t <td>File:</td>\n"); out.write("\t <td><input type=\"file\" name=\"file\" id=\"file\" /></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr id=\"url_row\" class=\"hide\">\n"); out.write("\t \t<td>Share URL:</td>\n"); out.write( "\t \t<td><input type=\"text\" name=\"share_url\" id=\"share_url\" readonly=\"readonly\" size=\"38\"/>\n"); out.write( "\t \t<input type=\"button\" onclick=\"showResults()\" value=\"View\"/>\n"); out.write("\t \t</td>\n"); out.write("\t \t<td></td>\n"); out.write("\t </tr>\n"); out.write("\t <tr>\n"); out.write( "\t <td colspan=\"2\" style=\"text-align:right\"><input type=\"submit\" value=\"Submit\" /></td>\n"); out.write("\t </tr>\n"); out.write("\t </table>\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"created\" id=\"created\" />\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"DBId\" id=\"DBId\" />\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"fileUrl\" id=\"fileUrl\" />\n"); out.write("\t\t\t\t\t<input type=\"hidden\" name=\"binary\" id=\"binary\" />\n"); out.write("\t\t\t\t\t "); if (showAll) out.print("<input type=\"hidden\" name=\"sudo\" id=\"sudo\" value=\"true\" />"); out.write("\t \t\t\n"); out.write("\t\t\t\t</form>\n"); out.write("\t </div>\n"); out.write("\t <form id=\"logout_form\" name=\"logout_form\" method=\"post\">\n"); out.write( "\t \t<input type=\"submit\" name=\"logout\" id = \"logout\" value=\"Log Out\" />\n"); out.write("\t </form>\n"); out.write("\t </div>\n"); out.write("\t </p>\n"); out.write("\t\n"); } } else if (isLoggedIn == false) { //localCookie =(request.getParameter("local") != null); //System.out.println("LocalCookie = " + localCookie.toString()); String errorMsg = ""; if (request.getParameter("logintext") != null || request.getParameter("passwordtext") != null) { if (logMeIn(request.getParameter("logintext"), request.getParameter("passwordtext"), request, response)) { showAll = (request.getParameter("sudo") != null); out.println("<meta http-equiv=\"refresh\" content=\"0\">"); out.println("Login Success"); } else { errorMsg = "Log in Failed, Please Try again"; } } out.write("\n"); out.write("\n"); out.write("<script>\n"); out.write("\tfunction validate_fields()\n"); out.write("\t{\n"); out.write("\t\tuname = document.getElementById('logintext').value;\n"); out.write("\t\tpword = document.getElementById('passwordtext').value;\n"); out.write("\t\t\n"); out.write("\t\tif (uname == \"\")\n"); out.write("\t\t{\n"); out.write("\t\t\talert('Please provide your username.');\n"); out.write("\t\t\treturn false;\n"); out.write("\t\t}\n"); out.write("\t\tif (pword == \"\")\n"); out.write("\t\t{\n"); out.write("\t\t\talert('Please provide your password.');\n"); out.write("\t\t\treturn false;\n"); out.write("\t\t}\n"); out.write("\t}\n"); out.write("\n"); out.write("\n"); out.write("</script>\n"); out.write( "\t<div id=\"login_outter_div\" name=\"login_outter_div\" align=\"center\" style=\"width:100%\" >\n"); out.write( " \t<div id=\"login_div\" name=\"login_div\" style=\"border-style:solid; border-color:#999999; border-radius: 10px; width:450px; margin:auto\">\n"); out.write(" \t<h2>Login</h2>\n"); out.write( " <form id=\"login_form\" name=\"login_form\" method=\"post\" onsubmit=\"javascript:return validate_fields();\" >\n"); out.write( " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding-left:10px\">\n"); out.write(" <tr>\n"); out.write(" <td>User Name</td>\n"); out.write(" <td> </td>\n"); out.write(" <td>Password</td>\n"); out.write(" </tr>\n"); out.write(" <tr>\n"); out.write( " <td><input type=\"text\" name=\"logintext\" id=\"logintext\" width=\"190px\" /></td>\n"); out.write(" <td> </td>\n"); out.write( " <td><input type=\"password\" name=\"passwordtext\" id=\"passwordtext\" width=\"190px\" /></td>\n"); out.write(" </tr>\n"); out.write(" <tr>\n"); out.write( " <td colspan=\"3\" align=\"right\"><input name=\"Login\" type=\"submit\" value=\"Login\" /></td>\n"); out.write(" </tr>\n"); out.write(" </table>\n"); out.write("\t\t\t</form>\n"); out.write(" </div>\n"); out.write(" </div>\n"); out.write("\t<div style=\"color: red; text-align: center;\"> "); out.print(errorMsg); out.write(" </div>\n"); } out.write("\n"); out.write(" \n"); out.write(" \n"); out.write("</body>\n"); out.write("</html>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { out.clearBuffer(); } catch (java.io.IOException e) { } if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
From source file:org.codelibs.fess.job.GenerateThumbnailJob.java
protected void executeThumbnailGenerator() { final List<String> cmdList = new ArrayList<>(); final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":"; final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class); final ProcessHelper processHelper = ComponentUtil.getProcessHelper(); final FessConfig fessConfig = ComponentUtil.getFessConfig(); cmdList.add(fessConfig.getJavaCommandPath()); // -cp// w w w . j a v a 2s .c o m cmdList.add("-cp"); final StringBuilder buf = new StringBuilder(100); ResourceUtil.getOverrideConfPath().ifPresent(p -> { buf.append(p); buf.append(cpSeparator); }); final String confPath = System.getProperty(Constants.FESS_CONF_PATH); if (StringUtil.isNotBlank(confPath)) { buf.append(confPath); buf.append(cpSeparator); } // WEB-INF/env/thumbnail/resources buf.append("WEB-INF"); buf.append(File.separator); buf.append("env"); buf.append(File.separator); buf.append("thumbnail"); buf.append(File.separator); buf.append("resources"); buf.append(cpSeparator); // WEB-INF/classes buf.append("WEB-INF"); buf.append(File.separator); buf.append("classes"); // target/classes final String userDir = System.getProperty("user.dir"); final File targetDir = new File(userDir, "target"); final File targetClassesDir = new File(targetDir, "classes"); if (targetClassesDir.isDirectory()) { buf.append(cpSeparator); buf.append(targetClassesDir.getAbsolutePath()); } // WEB-INF/lib appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/lib")), "WEB-INF" + File.separator + "lib" + File.separator); // WEB-INF/env/thumbnail/lib appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/env/thumbnail/lib")), "WEB-INF" + File.separator + "env" + File.separator + "thumbnail" + File.separator + "lib" + File.separator); final File targetLibDir = new File(targetDir, "fess" + File.separator + "WEB-INF" + File.separator + "lib"); if (targetLibDir.isDirectory()) { appendJarFile(cpSeparator, buf, targetLibDir, targetLibDir.getAbsolutePath() + File.separator); } cmdList.add(buf.toString()); if (useLocalElasticsearch) { final String transportAddresses = System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES); if (StringUtil.isNotBlank(transportAddresses)) { cmdList.add("-D" + Constants.FESS_ES_TRANSPORT_ADDRESSES + "=" + transportAddresses); } } final String systemLastaEnv = System.getProperty("lasta.env"); if (StringUtil.isNotBlank(systemLastaEnv)) { if (systemLastaEnv.equals("web")) { cmdList.add("-Dlasta.env=thumbnail"); } else { cmdList.add("-Dlasta.env=" + systemLastaEnv); } } else if (StringUtil.isNotBlank(lastaEnv)) { cmdList.add("-Dlasta.env=" + lastaEnv); } addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null); cmdList.add("-Dfess.thumbnail.process=true"); if (logFilePath == null) { final String value = System.getProperty("fess.log.path"); logFilePath = value != null ? value : new File(targetDir, "logs").getAbsolutePath(); } cmdList.add("-Dfess.log.path=" + logFilePath); addSystemProperty(cmdList, Constants.FESS_VAR_PATH, null, null); addSystemProperty(cmdList, Constants.FESS_THUMBNAIL_PATH, null, null); addSystemProperty(cmdList, "fess.log.name", "fess-thumbnail", "-thumbnail"); if (logLevel != null) { cmdList.add("-Dfess.log.level=" + logLevel); } stream(fessConfig.getJvmThumbnailOptionsAsArray()) .of(stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value))); File ownTmpDir = null; final String tmpDir = System.getProperty("java.io.tmpdir"); if (fessConfig.isUseOwnTmpDir() && StringUtil.isNotBlank(tmpDir)) { ownTmpDir = new File(tmpDir, "fessTmpDir_" + sessionId); if (ownTmpDir.mkdirs()) { cmdList.add("-Djava.io.tmpdir=" + ownTmpDir.getAbsolutePath()); } else { ownTmpDir = null; } } if (StringUtil.isNotBlank(jvmOptions)) { split(jvmOptions, " ").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(s -> cmdList.add(s))); } cmdList.add(ThumbnailGenerator.class.getCanonicalName()); cmdList.add("--sessionId"); cmdList.add(sessionId); cmdList.add("--numOfThreads"); cmdList.add(Integer.toString(numOfThreads)); if (cleanup) { cmdList.add("--cleanup"); } File propFile = null; try { cmdList.add("-p"); propFile = File.createTempFile("thumbnail_", ".properties"); cmdList.add(propFile.getAbsolutePath()); try (FileOutputStream out = new FileOutputStream(propFile)) { final Properties prop = new Properties(); prop.putAll(ComponentUtil.getSystemProperties()); prop.store(out, cmdList.toString()); } final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile(); if (logger.isInfoEnabled()) { logger.info("ThumbnailGenerator: \nDirectory=" + baseDir + "\nOptions=" + cmdList); } final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> { pb.directory(baseDir); pb.redirectErrorStream(true); }); final InputStreamThread it = jobProcess.getInputStreamThread(); it.start(); final Process currentProcess = jobProcess.getProcess(); currentProcess.waitFor(); it.join(5000); final int exitValue = currentProcess.exitValue(); if (logger.isInfoEnabled()) { logger.info("ThumbnailGenerator: Exit Code=" + exitValue + " - ThumbnailGenerator Process Output:\n" + it.getOutput()); } if (exitValue != 0) { throw new FessSystemException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput()); } ComponentUtil.getPopularWordHelper().clearCache(); } catch (final FessSystemException e) { throw e; } catch (final InterruptedException e) { logger.warn("ThumbnailGenerator Process interrupted."); } catch (final Exception e) { throw new FessSystemException("ThumbnailGenerator Process terminated.", e); } finally { try { processHelper.destroyProcess(sessionId); } finally { if (propFile != null && !propFile.delete()) { logger.warn("Failed to delete {}.", propFile.getAbsolutePath()); } deleteTempDir(ownTmpDir); } } }