Search in sources :

Example 1 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class PentahoSystem method init.

public static boolean init(final IApplicationContext pApplicationContext, final Map listenerMap) {
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "PentahoSystem init called");
    }
    if (PentahoSystem.initializedStatus == PentahoSystem.SYSTEM_INITIALIZED_OK) {
        // tests call init more than once without an intervening shutdown().
        try {
            throw new IllegalStateException("'Init' method was run twice without 'shutdown'");
        } catch (IllegalStateException e) {
            Logger.error(PentahoSystem.class, "PentahoSystem was already initialized when init() called again without a preceding shutdown(). " + "This is likely in error", e);
        }
    }
    PentahoSystem.initializedStatus = PentahoSystem.SYSTEM_INITIALIZED_OK;
    // PDI-3438 Scheduled job fails to open a transformation
    // Kettle jobs spawn threads which may require authentication to load transformations from
    // the kettle repository, by using the INHERITABLETHREADLOCAL strategy, spawned threads will
    // enjoy the same SecurityContext as their parent!
    SecurityContextHolder.setStrategyName(securityContextHolderStrategy);
    PentahoSystem.globalAttributes = Collections.synchronizedMap(new HashMap());
    PentahoSystem.globalParameters = new SimpleParameterProvider(PentahoSystem.globalAttributes);
    PentahoSystem.applicationContext = pApplicationContext;
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Setting property path");
    }
    // $NON-NLS-1$
    System.setProperty("pentaho.solutionpath", "solution:");
    if (LocaleHelper.getLocale() == null) {
        LocaleHelper.setLocale(Locale.getDefault());
    }
    if (PentahoSystem.systemSettingsService != null) {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Reading ACL list from pentaho.xml");
        }
        // Set Up ACL File Extensions by reading pentaho.xml for acl-files
        // 
        // Read the files that are permitted to have ACLs on them from
        // the pentaho.xml.
        // 
        // $NON-NLS-1$ //$NON-NLS-2$
        String aclFiles = PentahoSystem.getSystemSetting("acl-files", "xaction,url");
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(aclFiles, ",");
        String extn;
        while (st.hasMoreElements()) {
            extn = st.nextToken();
            if (!extn.startsWith(".")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                extn = "." + extn;
            }
            PentahoSystem.ACLFileExtensionList.add(extn);
        }
    }
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Set Java System Properties");
    }
    PentahoSystem.setSystemProperties();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Initialize XML Factories");
    }
    PentahoSystem.initXMLFactories();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Set Logging Level from pentaho.xml setting");
    }
    PentahoSystem.loggingLevel = ILogger.ERROR;
    if (PentahoSystem.systemSettingsService != null) {
        PentahoSystem.loggingLevel = // $NON-NLS-1$//$NON-NLS-2$
        Logger.getLogLevel(PentahoSystem.systemSettingsService.getSystemSetting("log-level", "ERROR"));
    }
    Logger.setLogLevel(PentahoSystem.loggingLevel);
    // to guarantee hostnames in SSL mode are not being spoofed
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Register host name verifier");
    }
    PentahoSystem.registerHostnameVerifier();
    // $NON-NLS-1$
    assert null != aggObjectFactory : "aggObjectFactory must be non-null";
    try {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Validating object factory");
        }
        PentahoSystem.validateObjectFactory();
    } catch (PentahoSystemException e1) {
        // this is fatal
        throw new RuntimeException(e1);
    }
    // store a list of the system listeners
    try {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Start System Listeners");
        }
        PentahoSystem.notifySystemListenersOfStartup();
    } catch (PentahoSystemException e) {
        String msg = e.getLocalizedMessage();
        Logger.error(PentahoSystem.class.getName(), msg, e);
        PentahoSystem.initializedStatus |= PentahoSystem.SYSTEM_LISTENERS_FAILED;
        PentahoSystem.addInitializationFailureMessage(PentahoSystem.SYSTEM_LISTENERS_FAILED, msg);
        return false;
    }
    // once everything else is initialized, start global actions
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Global startup");
    }
    PentahoSystem.globalStartup();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "PentahoSystem Init Complete");
    }
    return true;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 2 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class FileResourceTest method testDoIsParameterizable.

@Test
public void testDoIsParameterizable() throws Exception {
    String path = "path";
    doReturn(path).when(fileResource.fileService).idToPath(PATH_ID);
    RepositoryFile mockRepositoryFile = mock(RepositoryFile.class);
    doReturn(mockRepositoryFile).when(fileResource.repository).getFile(path);
    doReturn(true).when(fileResource).hasParameterUi(mockRepositoryFile);
    IContentGenerator mockContentGenerator = mock(IContentGenerator.class);
    doReturn(mockContentGenerator).when(fileResource).getContentGenerator(mockRepositoryFile);
    SimpleParameterProvider mockSimpleParameterProvider = mock(SimpleParameterProvider.class);
    doReturn(mockSimpleParameterProvider).when(fileResource).getSimpleParameterProvider();
    String repositoryPath = "repositoryPath";
    doReturn(repositoryPath).when(mockRepositoryFile).getPath();
    String encodedPath = "encodedPath";
    doReturn(encodedPath).when(fileResource).encode(repositoryPath);
    IPentahoSession mockPentahoSession = mock(IPentahoSession.class);
    doReturn(mockPentahoSession).when(fileResource).getSession();
    ByteArrayOutputStream mockByteArrayOutputStream = mock(ByteArrayOutputStream.class);
    doReturn(mockByteArrayOutputStream).when(fileResource).getByteArrayOutputStream();
    doReturn(1).when(mockByteArrayOutputStream).size();
    String outputStreamToString = "outputStreamToString";
    doReturn(outputStreamToString).when(mockByteArrayOutputStream).toString();
    Document mockDocument = mock(Document.class);
    doReturn(mockDocument).when(fileResource).parseText(outputStreamToString);
    String selectNodesParam = "parameters/parameter";
    List<Element> elements = new ArrayList<Element>();
    doReturn(elements).when(mockDocument).selectNodes(selectNodesParam);
    Element mockElement = mock(Element.class);
    doReturn("output-target").when(mockElement).attributeValue("name");
    doReturn("true").when(mockElement).attributeValue("is-mandatory");
    // Test 1
    String testString = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.FALSE.toString(), testString);
    // Test 2
    elements.add(mockElement);
    testString = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.TRUE.toString(), testString);
    // Test 3
    doReturn("false").when(mockElement).attributeValue("is-mandatory");
    testString = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.TRUE.toString(), testString);
    // Test 4
    Element mockAttribElement = mock(Element.class);
    doReturn(mockAttribElement).when(mockElement).selectSingleNode("attribute[@namespace='http://reporting.pentaho" + ".org/namespaces/engine/parameter-attributes/core' and @name='role']");
    testString = fileResource.doIsParameterizable(PATH_ID);
    assertEquals(Boolean.TRUE.toString(), testString);
    verify(fileResource.fileService, times(4)).idToPath(PATH_ID);
    verify(fileResource.repository, times(4)).getFile(path);
    verify(fileResource, times(4)).hasParameterUi(mockRepositoryFile);
    verify(fileResource, times(4)).getContentGenerator(mockRepositoryFile);
    verify(mockContentGenerator, times(4)).setOutputHandler(any(SimpleOutputHandler.class));
    verify(mockContentGenerator, times(4)).setMessagesList(anyList());
    verify(fileResource, times(4)).getSimpleParameterProvider();
    verify(mockRepositoryFile, times(4)).getPath();
    verify(fileResource, times(4)).encode(repositoryPath);
    verify(mockSimpleParameterProvider, times(4)).setParameter("path", encodedPath);
    verify(mockSimpleParameterProvider, times(4)).setParameter("renderMode", "PARAMETER");
    verify(mockContentGenerator, times(4)).setParameterProviders(anyMap());
    verify(fileResource, times(4)).getSession();
    verify(mockContentGenerator, times(4)).setSession(mockPentahoSession);
    verify(mockContentGenerator, times(4)).createContent();
    verify(fileResource, times(4)).getByteArrayOutputStream();
    verify(mockDocument, times(4)).selectNodes(selectNodesParam);
    verify(mockElement, times(3)).attributeValue("name");
    verify(mockElement, times(3)).attributeValue("is-mandatory");
    verify(mockAttribElement, times(1)).attributeValue("value");
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Element(org.dom4j.Element) IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 3 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunPost.

@Test
public void testRunPost() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService");
    pathParams.setParameter("remoteaddr", "http:test");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("POST");
    request.setRequestURI("/pentaho/content/ws-run/StubService");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService");
    request.setRemoteAddr(REMOTE_ADDRESS);
    request.setContentType("application/soap+xml; charset=UTF-8; action=\"urn:getString\"");
    String xml = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://www.w3" + ".org/2003/05/soap-envelope\"><soapenv:Body><ns2:getString xmlns:ns2=\"http://webservice.pentaho" + ".com\"></ns2:getString></soapenv:Body></soapenv:Envelope>";
    request.setBodyContent(xml);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubTransportSender.transportOutStr = null;
        StubService.getStringCalled = false;
        contentGenerator.createContent();
        assertTrue(StubService.getStringCalled);
        String content = StubTransportSender.transportOutStr;
        assertEquals("result are wrong", "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://www.w3" + ".org/2003/05/soap-envelope\"><soapenv:Body><ns:getStringResponse xmlns:ns=\"" + "http://webservices.services" + ".plugin.platform.test.pentaho.org\"><return>test " + "result</return></ns:getStringResponse></soapenv:Body></soapenv:Envelope>", content);
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 4 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunGet.

@Test
public void testRunGet() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService/getString");
    pathParams.setParameter("remoteaddr", "http:test");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.setRequestURI("/pentaho/content/ws-run/StubService/getString");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService/getString");
    request.setRemoteAddr(REMOTE_ADDRESS);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubTransportSender.transportOutStr = null;
        StubService.getStringCalled = false;
        contentGenerator.createContent();
        assertTrue(StubService.getStringCalled);
        String content = StubTransportSender.transportOutStr;
        assertEquals("result are wrong", "<ns:getStringResponse xmlns:ns=\"http://webservices.services.plugin.platform.test.pentaho.org\"><return>test" + " result</return></ns:getStringResponse>", content);
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 5 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunGetThrowError.

@Test
public void testRunGetThrowError() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService/throwsError1");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.setRequestURI("/pentaho/content/ws-run/StubService/throwsError1");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService/throwsError1");
    request.setRemoteAddr(REMOTE_ADDRESS);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubService.throwsError1Called = false;
        StubTransportSender.transportOutStr = null;
        contentGenerator.createContent();
        assertTrue(StubService.throwsError1Called);
        String content = StubTransportSender.transportOutStr;
        assertNull("Content should be empty", content);
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Aggregations

SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)72 HashMap (java.util.HashMap)32 ArrayList (java.util.ArrayList)23 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)23 OutputStream (java.io.OutputStream)21 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)21 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)21 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)16 Test (org.junit.Test)13 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 Map (java.util.Map)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)5 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)5 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5 Iterator (java.util.Iterator)4