List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:nl.surfnet.coin.mock.MockSoapServerTest.java
/** * Test the MockHttpServer.//ww w. j av a 2 s.c om * * @throws Exception */ @Test public void testMockHappyFlow() throws Exception { ClassPathResource responseResource = new ClassPathResource("test.json"); super.setResponseResource(responseResource); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(new HttpGet("http://localhost:8088/testUrl")); String contentType = response.getHeaders("Content-Type")[0].getValue(); Assert.assertEquals("application/json", contentType); InputStream is = response.getEntity().getContent(); OutputStream output = new ByteArrayOutputStream(); IOUtils.copy(is, output); Assert.assertEquals(IOUtils.toString(responseResource.getInputStream()), output.toString()); }
From source file:com.ephesoft.dcma.batch.service.EphesoftContext.java
/** * Gets stream to read workflow properties for the server. * /*w w w . ja v a2s .com*/ * @return {@link BufferedInputStream} * @throws IOException */ private BufferedInputStream getWorkflowPropertiesReaderStream() throws IOException { BufferedInputStream propertyInputStream = null; String filePath = BatchConstants.DCMA_WORKFLOWS_PROPERTIES; ClassPathResource classPathResourse = new ClassPathResource(filePath); if (classPathResourse.exists()) { propertyInputStream = new BufferedInputStream(classPathResourse.getInputStream()); } return propertyInputStream; }
From source file:nl.surfnet.coin.api.service.MockServiceImpl.java
@Override public PersonEntry getPerson(String userId, String loggedInUser, String spEntityId) { if (isActive()) { return getPreparedPerson(userId); }/*from w w w . j ava 2 s . c om*/ /* * Strip all characters that might cause problems in filenames. e.g.: * urn:collab:person:test.surfguest.nl:foo becomes: * urn_collab_person_test.surfguest.nl_foo */ String userIdStripped = userId.replaceAll("[^0-9a-zA-Z_.-]", "_"); final String filename = String.format(JSON_PATH, userIdStripped, "person"); LOG.debug("filename: {}", filename); ClassPathResource pathResource = new ClassPathResource(filename); if (!pathResource.exists()) { pathResource = new ClassPathResource(String.format(JSON_PATH, FALLBACK, "person")); } try { return parser.parsePerson(pathResource.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.ephesoft.dcma.workflows.service.impl.RestartBatchServiceImpl.java
/** * Fetches configuration for back up property service. * /*from w w w.j a v a 2s . c o m*/ * @param filePath {@link String} * @return {@link Properties} */ private Properties fetchConfig(final String filePath) { ClassPathResource classPathResource = new ClassPathResource(filePath); Properties properties = new Properties(); InputStream input = null; try { input = classPathResource.getInputStream(); properties.load(input); } catch (IOException ioException) { LOGGER.error("Cannot open and load backUpService properties file.", ioException); } finally { try { if (null != input) input.close(); } catch (IOException ioException2) { LOGGER.error("Cannot close backUpService properties file.", ioException2); } } return properties; }
From source file:com.sirma.itt.cmf.integration.alfresco3.CMFWorkflowDeployer.java
/** * Deploy the Workflow Definitions.//from w ww. j a v a2s. c om */ public void init() { PropertyCheck.mandatory(this, "transactionService", transactionService); PropertyCheck.mandatory(this, "authenticationContext", authenticationContext); PropertyCheck.mandatory(this, "workflowService", workflowService); String currentUser = authenticationContext.getCurrentUserName(); if (currentUser == null) { authenticationContext.setSystemUserAsCurrentUser(); } if (!transactionService.getAllowWrite()) { if (logger.isWarnEnabled()) logger.warn("Repository is in read-only mode; not deploying workflows."); return; } UserTransaction userTransaction = transactionService.getUserTransaction(); try { userTransaction.begin(); // bootstrap the workflow models and static labels (from classpath) if (models != null && resourceBundles != null && ((models.size() > 0) || (resourceBundles.size() > 0))) { DictionaryBootstrap dictionaryBootstrap = new DictionaryBootstrap(); dictionaryBootstrap.setDictionaryDAO(dictionaryDAO); dictionaryBootstrap.setTenantService(tenantService); dictionaryBootstrap.setModels(models); dictionaryBootstrap.setLabels(resourceBundles); dictionaryBootstrap.bootstrap(); // also registers with // dictionary } // bootstrap the workflow definitions (from classpath) if (workflowDefinitions != null) { for (Properties workflowDefinition : workflowDefinitions) { // retrieve workflow specification String engineId = workflowDefinition.getProperty(ENGINE_ID); if (engineId == null || engineId.length() == 0) { throw new WorkflowException("Workflow Engine Id must be provided"); } String location = workflowDefinition.getProperty(LOCATION); if (location == null || location.length() == 0) { throw new WorkflowException("Workflow definition location must be provided"); } Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY)); String mimetype = workflowDefinition.getProperty(MIMETYPE); // retrieve input stream on workflow definition ClassPathResource workflowResource = new ClassPathResource(location); // deploy workflow definition if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(), mimetype)) { if (logger.isDebugEnabled()) logger.debug("Workflow deployer: Definition '" + location + "' already deployed"); } else { if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(), mimetype)) { if (logger.isDebugEnabled()) logger.debug("Workflow deployer: Definition '" + location + "' already deployed"); } else { WorkflowDeployment deployment = workflowService.deployDefinition(engineId, workflowResource.getInputStream(), workflowResource.getFilename()); logDeployment(location, deployment); } } } } userTransaction.commit(); } catch (Throwable e) { // rollback the transaction try { if (userTransaction != null) { userTransaction.rollback(); } } catch (Exception ex) { // NOOP } } finally { if (currentUser == null) { authenticationContext.clearCurrentSecurityContext(); } } }
From source file:com.sirma.itt.cmf.integration.workflow.alfresco4.CMFWorkflowDeployer.java
/** * Deploy from properties.//from w w w. j a v a 2 s . co m * * @param workflowDefinition * the workflow definition * @return the workflow definition * @throws IOException * Signals that an I/O exception has occurred. */ private WorkflowDefinition deployFromProperties(Properties workflowDefinition) throws IOException { // retrieve workflow specification String engineId = workflowDefinition.getProperty(ENGINE_ID); if (engineId == null || engineId.length() == 0) { throw new WorkflowException("Workflow Engine Id must be provided"); } String location = workflowDefinition.getProperty(LOCATION); if (location == null || location.length() == 0) { throw new WorkflowException("Workflow definition location must be provided"); } if (workflowAdminService.isEngineEnabled(engineId)) { Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY)); String mimetype = workflowDefinition.getProperty(MIMETYPE); // retrieve input stream on workflow definition ClassPathResource workflowResource = new ClassPathResource(location); // deploy workflow definition if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(), mimetype)) { if (logger.isDebugEnabled()) logger.debug("Workflow deployer: Definition '" + location + "' already deployed"); } else { if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(), mimetype)) { logger.debug("Workflow deployer: Definition '" + location + "' already deployed"); } else { WorkflowDeployment deployment = workflowService.deployDefinition(engineId, workflowResource.getInputStream(), mimetype, workflowResource.getFilename()); getDefinitionToWorkflowMapping().put(deployment.getDefinition(), workflowDefinition); logDeployment(location, deployment); return deployment.getDefinition(); } } } else { logger.debug("Workflow deployer: Definition '" + location + "' not deployed as the '" + engineId + "' engine is disabled"); } return null; }
From source file:nl.surfnet.coin.api.service.MockServiceImpl.java
@Override public GroupEntry getGroups(String userId, String onBehalfOf, Integer count, Integer startIndex, String sortBy) {/*from ww w. j av a 2 s . c om*/ ClassPathResource pathResource = new ClassPathResource(String.format(JSON_PATH, userId, "groups")); if (!pathResource.exists()) { pathResource = new ClassPathResource(String.format(JSON_PATH, FALLBACK, "groups")); } try { return parser.parseGroups(pathResource.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:nl.surfnet.coin.api.service.MockServiceImpl.java
@Override public Group20Entry getGroup20(String userId, String groupId, String onBehalfOf) { if (isActive()) { return getPreparedGroup20(groupId); }// ww w . j a va 2 s . c o m ClassPathResource pathResource = new ClassPathResource(String.format(JSON_PATH, groupId, "group20")); if (!pathResource.exists()) { pathResource = new ClassPathResource(String.format(JSON_PATH, FALLBACK, "group20")); } try { return parser.parseGroups20(pathResource.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:nl.surfnet.coin.api.service.MockServiceImpl.java
@Override public Group20Entry getGroups20(String userId, String onBehalfOf, Integer count, Integer startIndex, String sortBy) {/* ww w .j a v a2s .c o m*/ if (isActive()) { return getPreparedGroups20(userId); } ClassPathResource pathResource = new ClassPathResource(String.format(JSON_PATH, userId, "groups20")); if (!pathResource.exists()) { pathResource = new ClassPathResource(String.format(JSON_PATH, FALLBACK, "groups20")); } try { return parser.parseGroups20(pathResource.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.dataconservancy.packaging.tool.impl.AnnotationDrivenPackageStateSerializerTest.java
@Test public void testDeserializeEmptyStream() throws Exception { ClassPathResource stateWithEmptyStream = new ClassPathResource("/stateWithEmptyStream.zip"); BufferedInputStream in = new BufferedInputStream(stateWithEmptyStream.getInputStream()); PackageState state = new PackageState(); underTest.setMarshallerMap(liveMarshallerMap); underTest.deserialize(state, in);/* w w w. j av a 2 s.co m*/ assertEmptyOrNullStreamsOnPackageState(state, StreamId.USER_SPECIFIED_PROPERTIES); }