001package org.nuxeo.ecm.platform.importer.executor.jaxrs; 002 003import java.io.IOException; 004import java.io.InputStream; 005 006import javax.ws.rs.GET; 007import javax.ws.rs.Path; 008import javax.ws.rs.Produces; 009 010import org.apache.commons.io.IOUtils; 011import org.nuxeo.ecm.platform.importer.executor.AbstractImporterExecutor; 012import org.nuxeo.ecm.platform.importer.log.BufferredLogger; 013import org.nuxeo.ecm.platform.importer.log.ImporterLogger; 014 015@Produces("text/plain; charset=UTF-8") 016public abstract class AbstractJaxRSImporterExecutor extends AbstractImporterExecutor { 017 018 @Override 019 public ImporterLogger getLogger() { 020 if (log == null) { 021 log = new BufferredLogger(getJavaLogger()); 022 } 023 return log; 024 } 025 026 @GET 027 @Produces("text/html; charset=UTF-8") 028 public String index() throws IOException { 029 try (InputStream stream = this.getClass().getResource("/static/importForm.html").openStream()) { 030 return IOUtils.toString(stream, "UTF-8"); 031 } 032 } 033 034 @GET 035 @Path("log") 036 public String getLogAsString() { 037 return getLogger().getLoggerBuffer(); 038 } 039 040 @GET 041 @Path("logActivate") 042 public String enableLogging() { 043 getLogger().setBufferActive(true); 044 return "Logging activated"; 045 } 046 047 @GET 048 @Path("logDesactivate") 049 public String disableLogging() { 050 getLogger().setBufferActive(false); 051 return "Logging desactivated"; 052 } 053 054 @GET 055 @Path("status") 056 public String getStatus() { 057 return super.getStatus(); 058 } 059 060 @GET 061 @Path("running") 062 public String running() { 063 return Boolean.toString(super.isRunning()); 064 } 065 066 @GET 067 @Path("kill") 068 public String kill() { 069 return super.kill(); 070 } 071 072}