@Before
  public void setUp() throws Exception {
    ServletContext servletContext = initServletContext();
    ServletLifecycle.beginApplication(servletContext);
    new Initialization(servletContext).create().init();

    servletContext.setAttribute(Gravity.class.getName(), mockGravity);

    MockHttpSession session =
        new MockHttpSession(servletContext) {
          @Override
          public String getId() {
            return "TEST$SESSION";
          }
        };
    MockHttpServletRequest request = new MockHttpServletRequest(session);
    MockHttpServletResponse response = new MockHttpServletResponse();

    Configuration cfg = new ConfigurationImpl();
    cfg.setGraniteConfig("/WEB-INF/granite/granite-config-seam.xml");
    servletContext.setAttribute(ServletGraniteConfig.GRANITE_CONFIG_CONFIGURATION_KEY, cfg);
    GraniteConfig graniteConfig = ServletGraniteConfig.loadConfig(servletContext);
    ServicesConfig servicesConfig = ServletServicesConfig.loadConfig(servletContext);
    HttpGraniteContext.createThreadIntance(
        graniteConfig, servicesConfig, servletContext, request, response);

    interceptor.before(requestMessage);

    SeamServiceFactory seamFactory = new SeamServiceFactory();
    seamFactory.configure(new XMap("properties"));
    @SuppressWarnings("unchecked")
    Destination destination =
        new Destination("seam", Collections.EMPTY_LIST, XMap.EMPTY_XMAP, null, null, null);
    invoker = new SeamServiceInvoker(destination, seamFactory);
  }
  @Before
  public void setUp() throws Exception {
    MockHttpSession session =
        new MockHttpSession(servletContext) {
          @Override
          public String getId() {
            return "TEST$SESSION";
          }
        };
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setSession(session);
    MockHttpServletResponse response = new MockHttpServletResponse();

    Configuration cfg = new ConfigurationImpl();
    cfg.setGraniteConfig("/WEB-INF/granite/granite-config-spring.xml");
    cfg.setFlexServicesConfig("/WEB-INF/flex/services-config-spring.xml");
    servletContext.setAttribute(ServletGraniteConfig.GRANITE_CONFIG_CONFIGURATION_KEY, cfg);
    GraniteConfig graniteConfig = ServletGraniteConfig.loadConfig(servletContext);
    ServicesConfig servicesConfig = ServletServicesConfig.loadConfig(servletContext);
    HttpGraniteContext.createThreadIntance(
        graniteConfig, servicesConfig, servletContext, request, response);

    springServiceFactory = new SpringServiceFactory();
    springServiceFactory.configure(new XMap("properties"));
    springServiceFactory.setApplicationContext(applicationContext);
  }
示例#3
0
  public GraniteConfig(
      String stdConfig,
      InputStream customConfigIs,
      Configuration configuration,
      String MBeanContextName)
      throws IOException, SAXException {
    try {
      amf3SerializerConstructor =
          TypeUtil.getConstructor(AMF3Serializer.class, new Class<?>[] {OutputStream.class});
      amf3DeserializerConstructor =
          TypeUtil.getConstructor(AMF3Deserializer.class, new Class<?>[] {InputStream.class});
    } catch (Exception e) {
      throw new GraniteConfigException("Could not get constructor for AMF3 (de)serializers", e);
    }

    this.MBeanContextName = MBeanContextName;

    ClassLoader loader = GraniteConfig.class.getClassLoader();

    final ByteArrayInputStream dtd =
        StreamUtil.getResourceAsStream("org/granite/config/granite-config.dtd", loader);
    final EntityResolver resolver =
        new EntityResolver() {
          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            if (GRANITE_CONFIG_PUBLIC_ID.equals(publicId)) {
              dtd.reset();
              InputSource source = new InputSource(dtd);
              source.setPublicId(publicId);
              return source;
            }
            return null;
          }
        };

    // Load standard config.
    InputStream is = null;
    try {
      is = StreamUtil.getResourceAsStream("org/granite/config/granite-config.xml", loader);
      XMap doc = new XMap(is, resolver);
      forElement(doc, false, null);
    } finally {
      if (is != null) is.close();
    }

    if (stdConfig != null) {
      try {
        is = StreamUtil.getResourceAsStream(stdConfig, loader);
        XMap doc = new XMap(is, resolver);
        forElement(doc, false, null);
      } finally {
        if (is != null) is.close();
      }
    }

    // Load custom config (override).
    if (customConfigIs != null) {
      XMap doc = new XMap(customConfigIs, resolver);
      forElement(
          doc, true, configuration != null ? configuration.getGraniteConfigProperties() : null);
    }

    if (amf3DeserializerSecurizer == null)
      log.warn(
          "You should configure a deserializer securizer in your granite-config.xml file in order to prevent potential security exploits!");
  }