public Object buildBean(
     String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
   if (containsBean(className)) return getBean(className);
   else {
     Class clazz = ClassLoaderUtil.loadClass(className, SpringOsgiObjectFactory.class);
     Object object = clazz.newInstance();
     if (injectInternal) injectInternalBeans(object);
     return object;
   }
 }
 protected String readAsString(String resource) throws Exception {
   InputStream is = null;
   try {
     is = ClassLoaderUtil.getResourceAsStream(resource, PlainTextResultTest.class);
     int sizeRead = 0;
     byte[] buffer = new byte[1024];
     StringBuilder stringBuilder = new StringBuilder();
     while ((sizeRead = is.read(buffer)) != -1) {
       stringBuilder.append(new String(buffer, 0, sizeRead));
     }
     return stringBuilder.toString();
   } finally {
     if (is != null) is.close();
   }
 }
Example #3
0
 private void init_CustomConfigurationProviders() {
   String configProvs = initParams.get("configProviders");
   if (configProvs != null) {
     String[] classes = configProvs.split("\\s*[,]\\s*");
     for (String cname : classes) {
       try {
         Class cls = ClassLoaderUtil.loadClass(cname, this.getClass());
         ConfigurationProvider prov = (ConfigurationProvider) cls.newInstance();
         configurationManager.addContainerProvider(prov);
       } catch (InstantiationException e) {
         throw new ConfigurationException("Unable to instantiate provider: " + cname, e);
       } catch (IllegalAccessException e) {
         throw new ConfigurationException("Unable to access provider: " + cname, e);
       } catch (ClassNotFoundException e) {
         throw new ConfigurationException("Unable to locate provider class: " + cname, e);
       }
     }
   }
 }
  public void testPlainTextWithoutSlash() throws Exception {
    PlainTextResult result = new PlainTextResult();
    result.setLocation("someJspFile.jsp");

    response.setExpectedContentType("text/plain");
    response.setExpectedHeader("Content-Disposition", "inline");
    InputStream jspResourceInputStream =
        ClassLoaderUtil.getResourceAsStream(
            "org/apache/struts2/dispatcher/someJspFile.jsp", PlainTextResultTest.class);

    try {
      servletContext.setResourceAsStream(jspResourceInputStream);
      result.execute(invocation);

      String r = AbstractUITagTest.normalize(stringWriter.getBuffer().toString(), true);
      String e =
          AbstractUITagTest.normalize(
              readAsString("org/apache/struts2/dispatcher/someJspFile.jsp"), true);
      assertEquals(r, e);
    } finally {
      jspResourceInputStream.close();
    }
  }
 public Class getClassInstance(String className) throws ClassNotFoundException {
   return containsBean(className)
       ? getBean(className).getClass()
       : ClassLoaderUtil.loadClass(className, SpringOsgiObjectFactory.class);
 }
 /**
  * Look for a static resource in the classpath.
  *
  * @param path The resource path
  * @return The inputstream of the resource
  * @throws IOException If there is a problem locating the resource
  */
 protected URL findResource(String path) throws IOException {
   return ClassLoaderUtil.getResource(path, getClass());
 }