Package org.pentaho.platform.api.engine

Examples of org.pentaho.platform.api.engine.IOutputHandler


      httpServletResponse.setCharacterEncoding( LocaleHelper.getSystemEncoding() );
    } catch ( Throwable t ) {
      logger.warn( "could not set encoding, servlet-api is likely too old.  are we in a unit test?" ); //$NON-NLS-1$
    }

    IOutputHandler outputHandler = new HttpOutputHandler( httpServletResponse, outputStream, true );
    outputHandler.setMimeTypeListener( new HttpMimeTypeListener( httpServletRequest, httpServletResponse ) {
      /*
       * This content generator is setting the mimeType
       */
      @Override
      public void setMimeType( String mimeType ) {
View Full Code Here


      boolean doMessages = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "debug", "false" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      boolean doWrapper = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "wrapper", "true" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      IOutputHandler outputHandler =
        createOutputHandler( httpServletResponse, getOutputStream( httpServletResponse, doMessages ) );

      // configure output handler, this is necessary so that the right content
      // disposition is set on the response header
      if ( mimeTypeListener == null ) {
        mimeTypeListener = new HttpMimeTypeListener( httpServletRequest, httpServletResponse, null );
      }
      outputHandler.setMimeTypeListener( mimeTypeListener );
      outputHandler.setSession( userSession );

      Map parameterProviders = new HashMap();
      parameterProviders.put( "request", requestParameters ); //$NON-NLS-1$
      parameterProviders.put( "session", sessionParameters ); //$NON-NLS-1$
      createOutputFileName( file, outputHandler );
      int outputPreference = IOutputHandler.OUTPUT_TYPE_DEFAULT;
      outputHandler.setOutputPreference( outputPreference );
      boolean forcePrompt = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "prompt", "false" ) ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

      List messages = new ArrayList();
      runtime =
View Full Code Here

      boolean doMessages = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "debug", "false" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      boolean doWrapper = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "wrapper", "true" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      IOutputHandler outputHandler =
        createOutputHandler( httpServletResponse, getOutputStream( httpServletResponse, doMessages ) );
      if ( mimeTypeListener == null ) {
        mimeTypeListener = new HttpMimeTypeListener( httpServletRequest, httpServletResponse, null );
      }
      outputHandler.setMimeTypeListener( mimeTypeListener );
      outputHandler.setSession( userSession );

      Map parameterProviders = new HashMap();
      parameterProviders.put( "request", requestParameters ); //$NON-NLS-1$
      parameterProviders.put( "session", sessionParameters ); //$NON-NLS-1$
      createOutputFileName( file, outputHandler );
      int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
      outputHandler.setOutputPreference( outputPreference );
      List messages = new ArrayList();

      // forcePrompt=true when displaying the scheduling UI
      runtime =
        executeInternal( file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession,
View Full Code Here

      logger.warn( MessageFormat.format( deprecationMessage, request.getMethod(), request.getRequestURL(), referer ) );
    }

    PentahoSystem.systemEntryPoint();

    IOutputHandler outputHandler = null;
    // BISERVER-2767 - grabbing the current class loader so we can replace it at the end
    ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader();
    try {
      InputStream in = request.getInputStream();
      String servletPath = request.getServletPath();
      String pathInfo = request.getPathInfo();
      String contentGeneratorId = ""; //$NON-NLS-1$
      String urlPath = ""; //$NON-NLS-1$
      SimpleParameterProvider pathParams = new SimpleParameterProvider();
      if ( StringUtils.isEmpty( pathInfo ) ) {
        logger.error(
          Messages.getInstance().getErrorString( "GenericServlet.ERROR_0005_NO_RESOURCE_SPECIFIED" ) ); //$NON-NLS-1$
        response.sendError( 403 );
        return;
      }

      String path = pathInfo.substring( 1 );
      int slashPos = path.indexOf( '/' );
      if ( slashPos != -1 ) {
        pathParams.setParameter( "path", pathInfo.substring( slashPos + 1 ) ); //$NON-NLS-1$
        contentGeneratorId = path.substring( 0, slashPos );
      } else {
        contentGeneratorId = path;
      }
      urlPath = "content/" + contentGeneratorId; //$NON-NLS-1$

      pathParams.setParameter( "query", request.getQueryString() ); //$NON-NLS-1$
      pathParams.setParameter( "contentType", request.getContentType() ); //$NON-NLS-1$
      pathParams.setParameter( "inputstream", in ); //$NON-NLS-1$
      pathParams.setParameter( "httpresponse", response ); //$NON-NLS-1$
      pathParams.setParameter( "httprequest", request ); //$NON-NLS-1$
      pathParams.setParameter( "remoteaddr", request.getRemoteAddr() ); //$NON-NLS-1$
      if ( PentahoSystem.debug ) {
        debug( "GenericServlet contentGeneratorId=" + contentGeneratorId ); //$NON-NLS-1$
        debug( "GenericServlet urlPath=" + urlPath ); //$NON-NLS-1$
      }
      IPentahoSession session = getPentahoSession( request );
      IPluginManager pluginManager = PentahoSystem.get( IPluginManager.class, session );
      if ( pluginManager == null ) {
        OutputStream out = response.getOutputStream();
        String message =
          Messages.getInstance().getErrorString(
            "GenericServlet.ERROR_0001_BAD_OBJECT", IPluginManager.class.getSimpleName() ); //$NON-NLS-1$
        error( message );
        out.write( message.getBytes() );
        return;
      }

      // TODO make doing the HTTP headers configurable per content generator
      SimpleParameterProvider headerParams = new SimpleParameterProvider();
      Enumeration names = request.getHeaderNames();
      while ( names.hasMoreElements() ) {
        String name = (String) names.nextElement();
        String value = request.getHeader( name );
        headerParams.setParameter( name, value );
      }

      String pluginId = pluginManager.getServicePlugin( pathInfo );

      if ( pluginId != null && pluginManager.isStaticResource( pathInfo ) ) {
        boolean cacheOn = "true".equals( pluginManager
          .getPluginSetting( pluginId, "settings/cache", "false" ) ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        String maxAge = (String) pluginManager.getPluginSetting( pluginId, "settings/max-age", null ); //$NON-NLS-1$
        allowBrowserCache( maxAge, pathParams );

        String mimeType = MimeHelper.getMimeTypeFromFileName( pathInfo );
        if ( mimeType != null ) {
          response.setContentType( mimeType );
        }
        OutputStream out = response.getOutputStream();

        // do we have this resource cached?
        ByteArrayOutputStream byteStream = null;

        if ( cacheOn ) {
          byteStream = (ByteArrayOutputStream) cache.getFromRegionCache( CACHE_FILE, pathInfo );
        }

        if ( byteStream != null ) {
          IOUtils.write( byteStream.toByteArray(), out );
          return;
        }
        InputStream resourceStream = pluginManager.getStaticResource( pathInfo );
        if ( resourceStream != null ) {
          try {
            byteStream = new ByteArrayOutputStream();
            IOUtils.copy( resourceStream, byteStream );

            // if cache is enabled, drop file in cache
            if ( cacheOn ) {
              cache.putInRegionCache( CACHE_FILE, pathInfo, byteStream );
            }

            // write it out
            IOUtils.write( byteStream.toByteArray(), out );
            return;
          } finally {
            IOUtils.closeQuietly( resourceStream );
          }
        }
        logger.error( Messages.getInstance().getErrorString(
          "GenericServlet.ERROR_0004_RESOURCE_NOT_FOUND", pluginId, pathInfo ) ); //$NON-NLS-1$
        response.sendError( 404 );
        return;
      }

      // content generators defined in plugin.xml are registered with 2 aliases, one is the id, the other is type
      // so, we can still retrieve a content generator by id, even though this is not the correct way to find
      // it. the correct way is to look up a content generator by pluginManager.getContentGenerator(type,
      // perspectiveName)
      IContentGenerator contentGenerator = (IContentGenerator) pluginManager.getBean( contentGeneratorId );
      if ( contentGenerator == null ) {
        OutputStream out = response.getOutputStream();
        String message =
          Messages.getInstance().getErrorString(
            "GenericServlet.ERROR_0002_BAD_GENERATOR",
            ESAPI.encoder().encodeForHTML( contentGeneratorId ) ); //$NON-NLS-1$
        error( message );
        out.write( message.getBytes() );
        return;
      }

      // set the classloader of the current thread to the class loader of
      // the plugin so that it can load its libraries
      // Note: we cannot ask the contentGenerator class for it's classloader, since the cg may
      // actually be a proxy object loaded by main the WebAppClassloader
      Thread.currentThread().setContextClassLoader( pluginManager.getClassLoader( pluginId ) );

      // String proxyClass = PentahoSystem.getSystemSetting( module+"/plugin.xml" ,
      // "plugin/content-generators/"+contentGeneratorId,
      // "content generator not found");
      IParameterProvider requestParameters = new HttpRequestParameterProvider( request );
      // see if this is an upload

      // File uploading is a service provided by UploadFileServlet where appropriate protections
      // are in place to prevent uploads that are too large.

      // boolean isMultipart = ServletFileUpload.isMultipartContent(request);
      // if (isMultipart) {
      // requestParameters = new SimpleParameterProvider();
      // // Create a factory for disk-based file items
      // FileItemFactory factory = new DiskFileItemFactory();
      //
      // // Create a new file upload handler
      // ServletFileUpload upload = new ServletFileUpload(factory);
      //
      // // Parse the request
      // List<?> /* FileItem */items = upload.parseRequest(request);
      // Iterator<?> iter = items.iterator();
      // while (iter.hasNext()) {
      // FileItem item = (FileItem) iter.next();
      //
      // if (item.isFormField()) {
      // ((SimpleParameterProvider) requestParameters).setParameter(item.getFieldName(), item.getString());
      // } else {
      // String name = item.getName();
      // ((SimpleParameterProvider) requestParameters).setParameter(name, item.getInputStream());
      // }
      // }
      // }

      response.setCharacterEncoding( LocaleHelper.getSystemEncoding() );

      IMimeTypeListener listener = new HttpMimeTypeListener( request, response );

      outputHandler = getOutputHandler( response, true );
      outputHandler.setMimeTypeListener( listener );

      IParameterProvider sessionParameters = new HttpSessionParameterProvider( session );
      IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
      Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
      parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParameters );
View Full Code Here

   * @throws Exception
   *           if there was a problem creating the content
   */
  public static String getContentAsString( IContentGenerator cg ) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler( out, false );

    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
    SimpleUrlFactory urlFactory = new SimpleUrlFactory( "?" ); //$NON-NLS-1$
    List<String> messages = new ArrayList<String>();
    cg.setOutputHandler( outputHandler );
    IMimeTypeListener mimeTypeListener = new IMimeTypeListener() {
      @SuppressWarnings( "unused" )
      public String mimeType = null;

      @SuppressWarnings( "unused" )
      public String name = null;

      public void setMimeType( String mimeType ) {
        this.mimeType = mimeType;
      }

      public void setName( String name ) {
        this.name = name;
      }
    };
    outputHandler.setMimeTypeListener( mimeTypeListener );
    cg.setMessagesList( messages );
    cg.setParameterProviders( parameterProviders );
    cg.setSession( PentahoSessionHolder.getSession() );
    cg.setUrlFactory( urlFactory );
    cg.createContent();
View Full Code Here

    assertNotNull( "contentGenerator is null", contentGenerator ); //$NON-NLS-1$
    assertNotNull( "Logger is null", contentGenerator.getLogger() ); //$NON-NLS-1$

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler( out, false );

    String baseUrl = "http://testhost:testport/testcontent"; //$NON-NLS-1$
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter( "path", "/StubService" ); //$NON-NLS-1$//$NON-NLS-2$
    parameterProviders.put( "path", pathParams ); //$NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory( baseUrl + "?" ); //$NON-NLS-1$
    List<String> messages = new ArrayList<String>();
    contentGenerator.setOutputHandler( outputHandler );
    MimeTypeListener mimeTypeListener = new MimeTypeListener();
    outputHandler.setMimeTypeListener( mimeTypeListener );
    contentGenerator.setMessagesList( messages );
    contentGenerator.setParameterProviders( parameterProviders );
    contentGenerator.setSession( session );
    contentGenerator.setUrlFactory( urlFactory );
    try {
View Full Code Here

    assertNotNull( "contentGenerator is null", contentGenerator ); //$NON-NLS-1$
    assertNotNull( "Logger is null", contentGenerator.getLogger() ); //$NON-NLS-1$

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler( out, false );

    String baseUrl = "http://testhost:testport/testcontent"; //$NON-NLS-1$
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
    SimpleUrlFactory urlFactory = new SimpleUrlFactory( baseUrl + "?" ); //$NON-NLS-1$
    List<String> messages = new ArrayList<String>();
    contentGenerator.setOutputHandler( outputHandler );
    MimeTypeListener mimeTypeListener = new MimeTypeListener();
    outputHandler.setMimeTypeListener( mimeTypeListener );
    contentGenerator.setMessagesList( messages );
    contentGenerator.setParameterProviders( parameterProviders );
    contentGenerator.setSession( session );
    contentGenerator.setUrlFactory( urlFactory );
    try {
View Full Code Here

    assertNotNull( "contentGenerator is null", contentGenerator ); //$NON-NLS-1$
    assertNotNull( "Logger is null", contentGenerator.getLogger() ); //$NON-NLS-1$

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler( out, false );

    String baseUrl = "http://testhost:testport/testcontent"; //$NON-NLS-1$
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    parameterProviders.put( "path", pathParams ); //$NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory( baseUrl + "?" ); //$NON-NLS-1$
    List<String> messages = new ArrayList<String>();
    contentGenerator.setOutputHandler( outputHandler );
    MimeTypeListener mimeTypeListener = new MimeTypeListener();
    outputHandler.setMimeTypeListener( mimeTypeListener );
    contentGenerator.setMessagesList( messages );
    contentGenerator.setParameterProviders( parameterProviders );
    contentGenerator.setSession( session );
    contentGenerator.setUrlFactory( urlFactory );
    try {
View Full Code Here

    assertNotNull( "contentGenerator is null", contentGenerator ); //$NON-NLS-1$
    assertNotNull( "Logger is null", contentGenerator.getLogger() ); //$NON-NLS-1$

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler( out, false );

    String baseUrl = "http://testhost:testport/testcontent"; //$NON-NLS-1$
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter( "path", "/bogus" ); //$NON-NLS-1$//$NON-NLS-2$
    parameterProviders.put( "path", pathParams ); //$NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory( baseUrl + "?" ); //$NON-NLS-1$
    List<String> messages = new ArrayList<String>();
    contentGenerator.setOutputHandler( outputHandler );
    MimeTypeListener mimeTypeListener = new MimeTypeListener();
    outputHandler.setMimeTypeListener( mimeTypeListener );
    contentGenerator.setMessagesList( messages );
    contentGenerator.setParameterProviders( parameterProviders );
    contentGenerator.setSession( session );
    contentGenerator.setUrlFactory( urlFactory );
    try {
View Full Code Here

    OutputStream outputStream = null;
    if ( testName != null && fileExtension != null ) {
      outputStream = getOutputStream( testName, fileExtension );
    }
    IOutputHandler outputHandler = null;
    if ( outputStream != null ) {
      outputHandler = getOutputHandler( outputStream );
    } else {
      outputHandler = getOutputHandler( (OutputStream) null );
    }
    String instanceId = null;
    StandaloneSession initialSession =
        new StandaloneSession( Messages.getInstance().getString( "BaseTest.DEBUG_JUNIT_SESSION" ) ); //$NON-NLS-1$
    IPentahoSession session = sessionStartup( initialSession );
    if ( outputHandler != null ) {
      outputHandler.setSession( session );
    }

    return run( actionPath, instanceId, false, parameterProvider, outputHandler, session );
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.engine.IOutputHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.