Search in sources :

Example 6 with ConfigFinder

use of org.collectionspace.csp.helper.core.ConfigFinder in project application by collectionspace.

the class TenantServlet method serviceWTenant.

/**
 * If you know the tenant id then
 * Check for global issues and if not run set up and then test if this is a init request, a composite request or a single request and
 * do the right thing
 * @param tenantid
 * @param pathparts
 * @param initcheck
 * @param servlet_request
 * @param servlet_response
 * @throws ServletException
 * @throws IOException
 * @throws BadRequestException
 * @throws UnauthorizedException
 */
protected void serviceWTenant(String tenantid, List<String> pathparts, String initcheck, HttpServletRequest servlet_request, HttpServletResponse servlet_response) throws ServletException, IOException, BadRequestException, UnauthorizedException {
    if (locked_down != null) {
        // this ended up with a status 200 hmmmm not great so changed it to return a 400... hopefully that wont break anythign else
        servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Servlet is locked down in a hard fail because of fatal error: " + locked_down);
        // servlet_response.getWriter().append("Servlet is locked down in a hard fail because of fatal error: "+locked_down);
        return;
    }
    if (initcheck.equals("init")) {
        tenantCSPM.put(tenantid, new CSPManagerImpl());
        tenantInit.put(tenantid, false);
        setup(tenantid);
        ConfigFinder cfg = new ConfigFinder(getServletContext());
        try {
            InputSource cfg_stream = cfg.resolveEntity("-//CSPACE//ROOT", "cspace-config-" + tenantid + ".xml");
            String test = IOUtils.toString(cfg_stream.getByteStream());
            // servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "cspace-config re-loaded"+test);
            servlet_response.getWriter().append("cspace-config re-loaded" + test);
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "cspace-config re-loadedfailed");
        }
        return;
    }
    if (!tenantInit.containsKey(tenantid) || !tenantInit.get(tenantid)) {
        setup(tenantid);
    }
    if (locked_down != null) {
        // this ended up with a status 200 hmmmm not great so changed it to return a 400... hopefully that wont break anythign else
        servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Servlet is locked down in a hard fail because of fatal error: " + locked_down);
        // servlet_response.getWriter().append("Servlet is locked down in a hard fail because of fatal error: "+locked_down);
        return;
    }
    if (perhapsServeFixedContent(servlet_request, servlet_response)) {
        return;
    }
    // Setup our request object
    UI web = tenantCSPM.get(tenantid).getUI("web");
    if (!tenantUmbrella.containsKey(tenantid)) {
        synchronized (getClass()) {
            if (!tenantUmbrella.containsKey(tenantid)) {
                tenantUmbrella.put(tenantid, new WebUIUmbrella((WebUI) web));
            }
        }
    }
    try {
        ConfigRoot root = tenantCSPM.get(tenantid).getConfigRoot();
        Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
        WebUIRequest req = new WebUIRequest(tenantUmbrella.get(tenantid), servlet_request, servlet_response, spec.getAdminData().getCookieLife(), pathparts);
        if (is_composite(req)) {
            serve_composite(web, req);
        } else {
            web.serviceRequest(req);
            req.solidify(true);
        }
    } catch (UIException e) {
        throw new BadRequestException("UIException", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException) WebUI(org.collectionspace.chain.csp.webui.main.WebUI) WebUI(org.collectionspace.chain.csp.webui.main.WebUI) UI(org.collectionspace.csp.api.ui.UI) UIException(org.collectionspace.csp.api.ui.UIException) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 7 with ConfigFinder

use of org.collectionspace.csp.helper.core.ConfigFinder in project application by collectionspace.

the class TenantServlet method load_config.

/**
 * retrieve the correct config file based on the tenantId
 * @param ctx
 * @param tenantId
 * @throws CSPDependencyException
 */
protected void load_config(ServletContext ctx, String tenantId) throws CSPDependencyException {
    try {
        ConfigFinder cfg = new ConfigFinder(ctx);
        InputSource cfg_stream = cfg.resolveEntity("-//CSPACE//ROOT", "cspace-config-" + tenantId + ".xml");
        if (cfg_stream == null) {
            locked_down = "Cannot find cspace config xml file";
        } else {
            tenantCSPM.get(tenantId).configure(cfg_stream, cfg, false);
        }
    } catch (UnsupportedEncodingException e) {
        throw new CSPDependencyException("Config has bad character encoding", e);
    } catch (IOException e) {
        throw new CSPDependencyException("Cannot load config", e);
    } catch (SAXException e) {
        throw new CSPDependencyException("Cannot parse config file", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException)

Example 8 with ConfigFinder

use of org.collectionspace.csp.helper.core.ConfigFinder in project application by collectionspace.

the class TestData method getSpec.

public final Spec getSpec(ServletTester tester) {
    if (this.spec == null) {
        CSPManager cspm = new CSPManagerImpl();
        cspm.register(new CoreConfig());
        cspm.register(new Spec());
        try {
            cspm.go();
            tester.getAttribute("config-filename");
            String filename = (String) tester.getAttribute("config-filename");
            cspm.configure(getSource(filename), new ConfigFinder(null), false);
        } catch (CSPDependencyException e) {
            log.info("CSPManagerImpl failed");
            log.info(tester.getAttribute("config-filename").toString());
            log.info(e.getLocalizedMessage());
        }
        ConfigRoot root = cspm.getConfigRoot();
        Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
        this.spec = spec;
    }
    return this.spec;
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) Spec(org.collectionspace.chain.csp.schema.Spec) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 9 with ConfigFinder

use of org.collectionspace.csp.helper.core.ConfigFinder in project application by collectionspace.

the class TestServices method getServiceManager.

private CSPManager getServiceManager(String filename) {
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    cspm.register(new ServicesStorageGenerator());
    try {
        cspm.go();
        cspm.configure(getSource(filename), new ConfigFinder(null), false);
    } catch (CSPDependencyException e) {
        log.error("CSPManagerImpl failed");
        log.error(e.getLocalizedMessage());
    }
    return cspm;
}
Also used : ServicesStorageGenerator(org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 10 with ConfigFinder

use of org.collectionspace.csp.helper.core.ConfigFinder in project application by collectionspace.

the class TestConfigFinder method getConfigStream.

// used to test multi tenancy
public static InputSource getConfigStream(String filename, boolean isFromBuild) throws CSPDependencyException {
    InputSource result = null;
    try {
        InputSource out = null;
        ConfigFinder cfg = new ConfigFinder(null);
        if (isFromBuild == true) {
            out = cfg.resolveEntity("-//CSPACE//TESTROOT", filename);
        } else {
            out = cfg.resolveEntity("-//CSPACE//ROOT", filename);
        }
        if (out != null) {
            result = out;
        } else {
            throw new CSPDependencyException("No config file found by any method");
        }
    } catch (SAXException x) {
        throw new CSPDependencyException("Parsing failed", x);
    } catch (IOException x) {
        throw new CSPDependencyException("Parsing failed", x);
    }
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) IOException(java.io.IOException) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException)

Aggregations

ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)11 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)8 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)7 Spec (org.collectionspace.chain.csp.schema.Spec)7 CSPManager (org.collectionspace.csp.api.container.CSPManager)7 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)6 ConfigRoot (org.collectionspace.chain.csp.config.ConfigRoot)5 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)5 InputSource (org.xml.sax.InputSource)4 SAXException (org.xml.sax.SAXException)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 File (java.io.File)2 ServicesStorageGenerator (org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator)2 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 WebUI (org.collectionspace.chain.csp.webui.main.WebUI)1 UI (org.collectionspace.csp.api.ui.UI)1 UIException (org.collectionspace.csp.api.ui.UIException)1 JSONException (org.json.JSONException)1