public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
    IOException {
    if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) {
      return;
    }

    if ( log.isDebug() ) {
      logDebug( BaseMessages.getString( PKG, "ExecuteTransServlet.Log.ExecuteTransRequested" ) );
    }

    // Options taken from PAN
    //
    String[] knownOptions = new String[] { REP, USER, PASS, TRANS, LEVEL };

    String repOption = request.getParameter( REP );
    String userOption = request.getParameter( USER );
    String passOption = Encr.decryptPasswordOptionallyEncrypted( request.getParameter( PASS ) );
    String transOption = request.getParameter( TRANS );
    String levelOption = request.getParameter( LEVEL );

    response.setStatus( HttpServletResponse.SC_OK );

    String encoding = System.getProperty( "KETTLE_DEFAULT_SERVLET_ENCODING", null );
    if ( encoding != null && !Utils.isEmpty( encoding.trim() ) ) {
      response.setCharacterEncoding( encoding );
      response.setContentType( "text/html; charset=" + encoding );
    }

    PrintWriter out = response.getWriter();

    if ( transOption == null ) {
      response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
      out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
              PKG, "ExecuteTransServlet.Error.MissingMandatoryParameter", TRANS ) ) );
      return;
    }

    try {

      final Repository repository = openRepository( repOption, userOption, passOption );
      final TransMeta transMeta = loadTransformation( repository, transOption );

      // Set the servlet parameters as variables in the transformation
      //
      String[] parameters = transMeta.listParameters();
      Enumeration<?> parameterNames = request.getParameterNames();
      while ( parameterNames.hasMoreElements() ) {
        String parameter = (String) parameterNames.nextElement();
        String[] values = request.getParameterValues( parameter );

        // Ignore the known options. set the rest as variables
        //
        if ( Const.indexOfString( parameter, knownOptions ) < 0 ) {
          // If it's a trans parameter, set it, otherwise simply set the variable
          //
          if ( Const.indexOfString( parameter, parameters ) < 0 ) {
            transMeta.setVariable( parameter, values[0] );
          } else {
            transMeta.setParameterValue( parameter, values[0] );
          }
        }
      }

      TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration();
      LogLevel logLevel = LogLevel.getLogLevelForCode( levelOption );
      transExecutionConfiguration.setLogLevel( logLevel );
      TransConfiguration transConfiguration = new TransConfiguration( transMeta, transExecutionConfiguration );

      String carteObjectId = UUID.randomUUID().toString();
      SimpleLoggingObject servletLoggingObject =
        new SimpleLoggingObject( CONTEXT_PATH, LoggingObjectType.CARTE, null );
      servletLoggingObject.setContainerObjectId( carteObjectId );
      servletLoggingObject.setLogLevel( logLevel );

      // Create the transformation and store in the list...
      //
      final Trans trans = new Trans( transMeta, servletLoggingObject );

      trans.setRepository( repository );
      trans.setSocketRepository( getSocketRepository() );

      getTransformationMap().addTransformation( transMeta.getName(), carteObjectId, trans, transConfiguration );
      trans.setContainerObjectId( carteObjectId );

      if ( repository != null ) {
        // The repository connection is open: make sure we disconnect from the repository once we
        // are done with this transformation.
        //
        trans.addTransListener( new TransAdapter() {
          @Override public void transFinished( Trans trans ) {
            repository.disconnect();
          }
        } );
      }

      // Pass the servlet print writer to the transformation...
      //
      trans.setServletPrintWriter( out );
      trans.setServletReponse( response );
      trans.setServletRequest( request );

      try {
        // Execute the transformation...
        //
        executeTrans( trans );
        String logging = KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), false ).toString();
        if ( trans.isFinishedOrStopped() && trans.getErrors() > 0 ) {
          response.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
          out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
            PKG, "ExecuteTransServlet.Error.ErrorExecutingTrans", logging ) ) );
        }
        out.flush();
      } catch ( Exception executionException ) {
        String logging = KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), false ).toString();
        throw new KettleException( BaseMessages.getString( PKG, "ExecuteTransServlet.Error.ErrorExecutingTrans", logging ), executionException );
      }
    } catch ( Exception ex ) {
      // When we get to this point KettleAuthenticationException has already been wrapped in an Execution Exception
      // and that in a KettleException
      Throwable kettleExceptionCause = ex.getCause();
      if ( kettleExceptionCause != null && kettleExceptionCause instanceof ExecutionException ) {
        Throwable executionExceptionCause = kettleExceptionCause.getCause();
        if ( executionExceptionCause != null && executionExceptionCause instanceof KettleAuthenticationException ) {
          response.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
          out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
                  PKG, "ExecuteTransServlet.Error.Authentication", getContextPath() ) ) );
        }
      } else if ( ex.getMessage().contains( UNABLE_TO_FIND_TRANS ) ) {
        response.setStatus( HttpServletResponse.SC_NOT_FOUND );
        out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
                PKG, "ExecuteTransServlet.Error.UnableToFindTransformation", transOption ) ) );
      } else {
        response.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
        out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
          PKG, "ExecuteTransServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker( ex ) ) ) );
      }
    }
  }
@Test
  public void doGetTransformationSucceedsTest() throws Exception {
    HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
    HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
    Trans trans = initMocksForTransExecution( mockHttpServletRequest, mockHttpServletResponse );
    when( trans.isFinishedOrStopped() ).thenReturn( true );
    when( trans.getErrors() ).thenReturn( 0 );

    executeTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );

    verify( mockHttpServletResponse ).setStatus( HttpServletResponse.SC_OK );
//    verify( mockHttpServletResponse, Mockito.times( 0 ) ).setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
    verify( mockHttpServletResponse, Mockito.times( 0 ) ).setStatus( HttpServletResponse.SC_BAD_REQUEST );
    verify( mockHttpServletResponse, Mockito.times( 0 ) ).setStatus( HttpServletResponse.SC_NOT_FOUND );
    verify( mockHttpServletResponse, Mockito.times( 0 ) ).setStatus( HttpServletResponse.SC_UNAUTHORIZED );
  }