List of usage examples for org.apache.commons.io FileUtils openInputStream
public static FileInputStream openInputStream(File file) throws IOException
new FileInputStream(file)
. From source file:org.chtijbug.drools.platform.runtime.builder.BusinessPackageAuthoringManagerTest.java
@Test @Ignore/*from w ww . ja v a 2s. c o m*/ public void should_get_everything_generated_on_guvnor() throws Exception { GuvnorRepositoryImpl guvnorRepository = new GuvnorRepositoryImpl("com.pymma.drools", "LATEST", "admin", "admin", "598"); Xsd2JarTransformer xsd2JarTransformer = new Xsd2JarTransformer(); BusinessPackageAuthoringManager toTest = new BusinessPackageAuthoringManager(guvnorRepository, xsd2JarTransformer, new MavenProjectFactory(), "/home/nheron/workspace-chtiJBUG/apache-maven-3.1.1", "/home/nheron/workspace-chtiJBUG/baseTestDirectory"); URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); URL modelFile = this.getClass().getResource("/model.xsd"); InputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); InputStream modelContent = FileUtils.openInputStream(FileUtils.toFile(modelFile)); toTest.createBusinessPackage(wsdlContent, modelContent); }
From source file:org.chtijbug.drools.platform.runtime.builder.BusinessPackageAuthoringManagerTest.java
@Test @Ignore/*from w w w .j av a2s.c o m*/ public void should_get_webservice_project_folder_generated() throws Exception { GuvnorRepositoryImpl guvnorRepository = new GuvnorRepositoryImpl("com.pymma.drools", "LATEST", "admin", "admin", "598"); guvnorRepository.setBaseUrl("http://localhost:10080"); Xsd2JarTransformer xsd2JarTransformer = new Xsd2JarTransformer(); BusinessPackageAuthoringManager toTest = new BusinessPackageAuthoringManager(guvnorRepository, xsd2JarTransformer, new MavenProjectFactory(), "/home/nheron/workspace-chtiJBUG/apache-maven-3.1.1", "/home/nheron/workspace-chtiJBUG/baseTestDirectory"); URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); URL modelFile = this.getClass().getResource("/model.xsd"); InputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); InputStream modelContent = FileUtils.openInputStream(FileUtils.toFile(modelFile)); toTest.generateExecutionService(wsdlContent, modelContent); }
From source file:org.chtijbug.drools.platform.runtime.utils.XpathQueryRunnerTest.java
@Test public void should_get_package_name_equals_to_name1() throws Exception { URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); FileInputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); XpathQueryRunner queryRunner = new XpathQueryRunner(wsdlContent); String packageName = queryRunner.executeXpath(XPATH_PACKAGE_NAME); assertThat(packageName).isEqualTo("newWSDL1"); }
From source file:org.chtijbug.drools.platform.runtime.utils.XpathQueryRunnerTest.java
@Test public void should_get_all_processes_from_wsdl() throws Exception { URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); FileInputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); XpathQueryRunner queryRunner = new XpathQueryRunner(wsdlContent); List<String> allProcessesName = queryRunner.executeXpathAsList(XPATH_PROCESSES_NAMES); assertThat(allProcessesName).hasSize(1); assertThat(allProcessesName.get(0)).isEqualTo("newWSDL1Operation"); }
From source file:org.chtijbug.drools.platform.runtime.utils.XpathQueryRunnerTest.java
@Test public void should_get_xsd_filename_equals_to_model_xsd() throws Exception { URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); FileInputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); XpathQueryRunner queryRunner = new XpathQueryRunner(wsdlContent); String xsdFilename = queryRunner.executeXpath(XPATH_XSD_NAME); assertThat(xsdFilename).isEqualTo("model.xsd"); }
From source file:org.chtijbug.drools.platform.runtime.utils.XpathQueryRunnerTest.java
@Test public void should_get_target_namespace() throws Exception { URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); FileInputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); XpathQueryRunner queryRunner = new XpathQueryRunner(wsdlContent); String xsdFilename = queryRunner.executeXpath(XPATH_TARGET_NAMESPACE); assertThat(xsdFilename).isEqualTo("http://j2ee.netbeans.org/wsdl/BpelModule1/src/newWSDL1"); }
From source file:org.chtijbug.drools.platform.runtime.utils.XpathQueryRunnerTest.java
@Test public void should_get_service_name() throws Exception { URL wsdlFile = this.getClass().getResource("/newWSDL1.wsdl"); FileInputStream wsdlContent = FileUtils.openInputStream(FileUtils.toFile(wsdlFile)); XpathQueryRunner queryRunner = new XpathQueryRunner(wsdlContent); String xsdFilename = queryRunner.executeXpath(XPATH_EXECUTION_SERVICE); assertThat(xsdFilename).isEqualTo("newWSDL1Service"); }
From source file:org.chtijbug.drools.platform.runtime.utils.Xsd2JarTransformerTestCase.java
@Test public void should_get_all_expected_entries_from_generated_jar_file() throws IOException { Xsd2JarTransformer toTest = new Xsd2JarTransformer(); URL xsdFile = this.getClass().getResource("/model.xsd"); InputStream modelJarStream = toTest.transformXsd2Jar("org.pymma.drools", new File(xsdFile.getFile())); File modelJarFile = File.createTempFile("model", ".jar"); IOUtils.copy(modelJarStream, FileUtils.openOutputStream(modelJarFile)); JarInputStream inputStream = new JarInputStream(FileUtils.openInputStream(modelJarFile)); assertThat(inputStream.getManifest()).isNotNull(); List<ZipEntry> allJarEntries = new ArrayList<ZipEntry>(); ZipEntry entry;//from ww w . j a v a 2s .c o m while ((entry = inputStream.getNextEntry()) != null) allJarEntries.add(entry); assertThat(allJarEntries).hasSize(5); }
From source file:org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.java
@Override public Object invoke(Object target, String methodName, Object[] arguments) { if (arguments.length == 0) { throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments); }/*from w w w. ja v a2s . c o m*/ GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes(); HttpServletResponse response = webRequest.getCurrentResponse(); boolean renderView = true; GroovyObject controller = (GroovyObject) target; if (arguments[0] instanceof CharSequence) { setContentType(response, TEXT_HTML, DEFAULT_ENCODING, true); CharSequence text = (CharSequence) arguments[0]; renderView = renderText(text, response); } else if (arguments[0] instanceof Closure) { setContentType(response, TEXT_HTML, gspEncoding, true); Closure closure = (Closure) arguments[arguments.length - 1]; renderView = renderMarkup(closure, response); } else if (arguments[0] instanceof Map) { Map argMap = (Map) arguments[0]; boolean hasContentType = argMap.containsKey(ARGUMENT_CONTENT_TYPE); Writer out = null; if (hasContentType) { out = getWriterForConfiguredContentType(response, argMap, hasContentType); webRequest.setOut(out); } if (argMap.containsKey(ARGUMENT_LAYOUT)) { webRequest.getCurrentRequest().setAttribute(GrailsLayoutDecoratorMapper.LAYOUT_ATTRIBUTE, argMap.get(ARGUMENT_LAYOUT)); } boolean statusSet = false; if (argMap.containsKey(ARGUMENT_STATUS)) { Object statusObj = argMap.get(ARGUMENT_STATUS); if (statusObj != null) { try { response.setStatus(Integer.parseInt(statusObj.toString())); statusSet = true; } catch (NumberFormatException e) { throw new ControllerExecutionException( "Argument [status] of method [render] must be a valid integer."); } } } if (arguments[arguments.length - 1] instanceof Closure) { Closure callable = (Closure) arguments[arguments.length - 1]; if (BUILDER_TYPE_JSON.equals(argMap.get(ARGUMENT_BUILDER)) || isJSONResponse(response)) { renderView = renderJSON(callable, response); } else { renderView = renderMarkup(callable, response); } } else if (arguments[arguments.length - 1] instanceof CharSequence) { if (out == null) { out = getWriterForConfiguredContentType(response, argMap, hasContentType); webRequest.setOut(out); } CharSequence text = (CharSequence) arguments[arguments.length - 1]; renderView = renderText(text, out); } else if (argMap.containsKey(ARGUMENT_TEXT)) { if (out == null) { out = getWriterForConfiguredContentType(response, argMap, hasContentType); webRequest.setOut(out); } Object textArg = argMap.get(ARGUMENT_TEXT); CharSequence text = (textArg instanceof CharSequence) ? ((CharSequence) textArg) : textArg.toString(); renderView = renderText(text, out); } else if (argMap.containsKey(ARGUMENT_VIEW)) { renderView(webRequest, argMap, target, controller, hasContentType); } else if (argMap.containsKey(ARGUMENT_TEMPLATE)) { if (out == null) { out = getWriterForConfiguredContentType(response, argMap, hasContentType); webRequest.setOut(out); } renderView = renderTemplate(target, controller, webRequest, argMap, out); } else if (argMap.containsKey(ARGUMENT_FILE)) { renderView = false; Object o = argMap.get(ARGUMENT_FILE); Object fnO = argMap.get(ARGUMENT_FILE_NAME); String fileName = fnO != null ? fnO.toString() : ((o instanceof File) ? ((File) o).getName() : null); if (o != null) { if (fileName != null) { detectContentTypeFromFileName(webRequest, response, argMap, fileName, hasContentType); if (fnO != null) { response.setHeader(HttpHeaders.CONTENT_DISPOSITION, DISPOSITION_HEADER_PREFIX + fileName); } } else if (!hasContentType) { throw new ControllerExecutionException( "Argument [file] of render method specified without valid [contentType] argument"); } InputStream input = null; try { if (o instanceof File) { File f = (File) o; input = FileUtils.openInputStream(f); } else if (o instanceof InputStream) { input = (InputStream) o; } else if (o instanceof byte[]) { input = new ByteArrayInputStream((byte[]) o); } else { input = FileUtils.openInputStream(new File(o.toString())); } IOUtils.copy(input, response.getOutputStream()); } catch (IOException e) { throw new ControllerExecutionException( "I/O error copying file to response: " + e.getMessage(), e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { // ignore } } } } } else if (statusSet) { // GRAILS-6711 nothing to render, just setting status code, so don't render the map renderView = false; } else { Object object = arguments[0]; if (object instanceof JSONElement) { renderView = renderJSON((JSONElement) object, response); } else { out = getWriterForConfiguredContentType(response, argMap, hasContentType); webRequest.setOut(out); renderView = renderObject(object, out); } } try { if (!renderView) { if (out != null) { out.flush(); } } } catch (IOException e) { throw new ControllerExecutionException( "I/O error executing render method for arguments [" + argMap + "]: " + e.getMessage(), e); } } else { throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments); } webRequest.setRenderView(renderView); return null; }
From source file:org.codehaus.httpcache4j.cache.CleanableFilePayload.java
public InputStream getInputStream() { if (isAvailable()) { try {// ww w . ja va2 s . c o m return FileUtils.openInputStream(file); } catch (IOException e) { throw new HTTPException("Could not create file input stream", e); } } throw new HTTPException(String.format("File '%s' is gone...", file.getAbsolutePath())); }