org.mule.runtime.core.api.util.IOUtils.getResourceAsString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.mule.runtime.core.api.util.IOUtils.getResourceAsString()方法的一些代码示例,展示了IOUtils.getResourceAsString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getResourceAsString()方法的具体详情如下:
包路径:org.mule.runtime.core.api.util.IOUtils
类名称:IOUtils
方法名:getResourceAsString

IOUtils.getResourceAsString介绍

[英]Attempts to load a resource from the file system, from a URL, or from the classpath, in that order.
[中]尝试按该顺序从文件系统、URL或类路径加载资源。

代码示例

代码示例来源:origin: mulesoft/mule

protected String loadResourceAsString(String resourceName) throws IOException {
 return IOUtils.getResourceAsString(resourceName, getClass());
}

代码示例来源:origin: mulesoft/mule

private void executeGroovyScript() {
 try {
  GroovyShell shell = new GroovyShell();
  resolvePropertiesUsingLambdas();
  properties.forEach((key, value) -> shell.setProperty(key, value));
  shell.evaluate(IOUtils.getResourceAsString(scriptPath, GroovyScriptExecutor.class));
  LOGGER.info("Groovy script executed");
 } catch (IOException e) {
  throw new RuntimeException("Error reading Groovy script: " + scriptPath, e);
 } catch (CompilationFailedException e) {
  throw new RuntimeException("Compilation error were found on: " + scriptPath, e);
 }
}

代码示例来源:origin: mulesoft/mule

@Override
public String getObject() throws Exception {
 String returnData = content;
 if (file != null) {
  try {
   returnData = getResourceAsString(file, getClass());
  } catch (IOException e) {
   throw new MuleRuntimeException(createStaticMessage("Failed to load test-data resource: " + file), e);
  }
 }
 return returnData;
}

代码示例来源:origin: mulesoft/mule

@Before
public void setup() throws IOException {
 expectedSchema = getResourceAsString("schemas/" + expectedXSD, getClass());
}

代码示例来源:origin: mulesoft/mule

@Before
public void setup() throws IOException {
 generator = new ExtensionModelJsonSerializer(true);
 expectedJson = getResourceAsString("models/" + expectedSource, getClass()).trim();
}

代码示例来源:origin: mulesoft/mule

@Before
public void setUp() throws IOException {
 jsonSerializer = new ExtensionModelJsonSerializer(true);
 expectedJson = getResourceAsString(expectedSource, ModuleExtensionModelJsonTestCase.class).trim();
}

代码示例来源:origin: mulesoft/mule

@Test
public void parseTemplateFromLocationWithKnownMediaType() throws Exception {
 parseTemplateProcessor.setLocation(LOCATION);
 parseTemplateProcessor.initialise();
 String expectedExpression = IOUtils.getResourceAsString(LOCATION, this.getClass());
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertThat(response.getMessage().getPayload().getDataType().getMediaType(), is(equalTo(LOCATION_MEDIA_TYPE)));
}

代码示例来源:origin: mulesoft/mule

@Test
public void parseTemplateFromLocationWithUnknownMediaType() throws Exception {
 parseTemplateProcessor.setLocation(UNKNOWN_MEDIATYPE_LOCATION);
 parseTemplateProcessor.initialise();
 String expectedExpression = IOUtils.getResourceAsString(UNKNOWN_MEDIATYPE_LOCATION, this.getClass());
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertThat(response.getMessage().getPayload().getDataType().getMediaType(), is(equalTo(ANY)));
}

代码示例来源:origin: mulesoft/mule

@Test
public void parseTemplateFromLocation() throws InitialisationException, IOException {
 parseTemplateProcessor.setLocation(LOCATION);
 parseTemplateProcessor.initialise();
 when(mockMuleMessage.getInboundProperty("errorMessage")).thenReturn("ERROR!!!");
 String expectedExpression = IOUtils.getResourceAsString(LOCATION, this.getClass());
 when(mockMuleMessage.getPayload()).thenReturn(of("Parsed"));
 when(mockMuleMessage.getAttributes()).thenReturn(of(new HashMap<>()));
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertNotNull(response);
 assertEquals("Parsed", response.getMessage().getPayload().getValue());
 // Call a second time to make sure the template is stored once the transformer has been initialized
 response = parseTemplateProcessor.process(event);
 assertNotNull(response);
 assertEquals("Parsed", response.getMessage().getPayload().getValue());
}

代码示例来源:origin: mulesoft/mule

@Test
public void parseTemplateWithOverriddenDataTypeAsExpression() throws Exception {
 String customEncoding = "UTF-16";
 MediaType customMediaType = create("application", "lrmextension");
 parseTemplateProcessor.setLocation(UNKNOWN_MEDIATYPE_LOCATION);
 parseTemplateProcessor.setOutputMimeType(customMediaType.toRfcString());
 parseTemplateProcessor.setOutputEncoding(customEncoding);
 parseTemplateProcessor.initialise();
 String expectedExpression = IOUtils.getResourceAsString(UNKNOWN_MEDIATYPE_LOCATION, this.getClass());
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getPrimaryType(),
       is(equalTo(customMediaType.getPrimaryType())));
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getSubType(),
       is(equalTo(customMediaType.getSubType())));
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getCharset().get().toString(),
       is(equalTo(customEncoding)));
}

代码示例来源:origin: mulesoft/mule

@Test
public void parseTemplateWithOverriddenDataType() throws Exception {
 String customEncoding = "UTF-16";
 MediaType customMediaType = create("application", "lrmextension");
 parseTemplateProcessor.setLocation(UNKNOWN_MEDIATYPE_LOCATION);
 parseTemplateProcessor.setOutputMimeType(customMediaType.toRfcString());
 parseTemplateProcessor.setOutputEncoding(customEncoding);
 parseTemplateProcessor.initialise();
 String expectedExpression = IOUtils.getResourceAsString(UNKNOWN_MEDIATYPE_LOCATION, this.getClass());
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getPrimaryType(),
       is(equalTo(customMediaType.getPrimaryType())));
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getSubType(),
       is(equalTo(customMediaType.getSubType())));
 assertThat(response.getMessage().getPayload().getDataType().getMediaType().getCharset().get().toString(),
       is(equalTo(customEncoding)));
}

代码示例来源:origin: mulesoft/mule

IOUtils.getResourceAsString(moduleNamePrefix + XSD_SUFFIX, classLoader), extensionModel.getName()
 };
} catch (IOException e) {

代码示例来源:origin: org.mule.runtime/mule-core

private void loadContentFromLocation() throws InitialisationException {
 try {
  if (location == null) {
   throw new IllegalArgumentException("Location cannot be null");
  }
  content = IOUtils.getResourceAsString(location, this.getClass());
 } catch (Exception e) {
  throw new InitialisationException(e, this);
 }
}

代码示例来源:origin: org.mule.runtime/mule-core

@Override
public void initialise() throws InitialisationException {
 if (expressionFile != null) {
  try {
   expression = getResourceAsString(expressionFile, getClass());
  } catch (IOException e) {
   throw new InitialisationException(e, this);
  }
 } else if (expression == null) {
  throw new InitialisationException(objectIsNull("expression"), this);
 }
}

代码示例来源:origin: org.mule.runtime/mule-module-extensions-spring-support

@Before
public void setup() throws IOException {
 expectedSchema = getResourceAsString("schemas/" + expectedXSD, getClass());
}

代码示例来源:origin: org.mule.runtime/mule-module-extensions-spring-support

@Before
public void setup() throws IOException {
 generator = new ExtensionModelJsonSerializer(true);
 expectedJson = getResourceAsString("models/" + expectedSource, getClass()).trim();
}

代码示例来源:origin: org.mule.runtime/mule-core

private void loadGlobalFunctions() throws InitialisationException {
 // Global functions defined in external file
 if (globalFunctionsFile != null) {
  try {
   globalFunctions.putAll(CompilerTools
     .extractAllDeclaredFunctions(new ExpressionCompiler(IOUtils.getResourceAsString(globalFunctionsFile, getClass()))
       .compile()));
  } catch (IOException e) {
   throw new InitialisationException(CoreMessages.failedToLoad(globalFunctionsFile), e, this);
  }
 }
 // Global functions defined in configuration file (take precedence over functions in file)
 globalFunctions.putAll(CompilerTools.extractAllDeclaredFunctions(new ExpressionCompiler(globalFunctionsString).compile()));
}

代码示例来源:origin: org.mule.runtime/mule-core-tests

@Test
public void testParseTemplateFromLocation() throws InitialisationException, IOException {
 parseTemplateProcessor.setLocation(LOCATION);
 parseTemplateProcessor.initialise();
 when(mockMuleMessage.getInboundProperty("errorMessage")).thenReturn("ERROR!!!");
 String expectedExpression = IOUtils.getResourceAsString(LOCATION, this.getClass());
 when(mockMuleMessage.getPayload()).thenReturn(TypedValue.of("Parsed"));
 when(mockMuleMessage.getAttributes()).thenReturn(TypedValue.of(new HashMap<>()));
 when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed");
 CoreEvent response = parseTemplateProcessor.process(event);
 assertNotNull(response);
 assertEquals("Parsed", response.getMessage().getPayload().getValue());
 // Call a second time to make sure the template is stored once the transformer has been initialized
 response = parseTemplateProcessor.process(event);
 assertNotNull(response);
 assertEquals("Parsed", response.getMessage().getPayload().getValue());
}

相关文章