Changeset 71:326369d4bc4d in AnnotationManagerN4J


Ignore:
Timestamp:
Mar 7, 2014, 12:48:50 PM (10 years ago)
Author:
casties
Branch:
default
Message:

trying restlet 2.1. doesn't work yet.

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • pom.xml

    r70 r71  
    88    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    99    <neo4j-version>2.0.1</neo4j-version>
    10     <restlet-version>2.0.15</restlet-version>
    11     <!-- <restlet-version>2.1.7</restlet-version> -->
     10    <!-- <restlet-version>2.0.15</restlet-version> -->
     11    <restlet-version>2.1.7</restlet-version>
    1212  </properties>
    1313  <repositories>
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java

    r70 r71  
    3131import java.util.Hashtable;
    3232import java.util.Properties;
     33import java.util.concurrent.ConcurrentMap;
    3334
    3435import javax.naming.NamingEnumeration;
     
    5152import org.restlet.Application;
    5253import org.restlet.Context;
     54import org.restlet.Restlet;
     55import org.restlet.data.LocalReference;
    5356
    5457import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
     
    6265     */
    6366    protected Properties consumerKeys;
    64     public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property";
     67    public String CONSUMER_KEYS_PATH = "consumerkeys.property";
    6568    public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys";
    6669
     
    6972     */
    7073    protected Properties serverConfig;
    71     public String CONFIG_PROPS_PATH = "WEB-INF/serverconfig.property";
     74    public String CONFIG_PROPS_PATH = "serverconfig.property";
    7275    public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig";
    7376
     
    7881    public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
    7982    public static final String GRAPHDB_PATH_KEY = "annotationmanager.graphdb.path";
    80     public String graphdbPath = "WEB-INF/neo4j-annotation-db";
     83    public String graphdbPath = "neo4j-annotation-db";
    8184
    8285    /**
     
    134137    public BaseRestlet(Context context) {
    135138        super(context);
    136         configure();
     139        configure(context);
    137140    }
    138141
     
    141144     * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb.
    142145     * Uses config from webapp context if already initialized.
    143      */
    144     protected void configure() {
    145         ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes()
     146     * @param context
     147     */
     148    protected void configure(Context context) {
     149        Context ctx = Context.getCurrent();
     150        ConcurrentMap<String, Object> attrs = ctx.getAttributes();
     151        ServletContext sc = null;
     152        if (context != null) {
     153            Restlet a = context.getServerDispatcher();
     154            Context b = a.getContext();
     155            ConcurrentMap<String, Object> c = b.getAttributes();
     156            sc = (ServletContext) context.getServerDispatcher().getContext().getAttributes()
    146157                .get("org.restlet.ext.servlet.ServletContext");
    147         if (sc != null) {
    148             if (sc.getAttribute("annotationserver.log4j.configured") == null) {
     158        }
     159        if (attrs != null) {
     160            if (attrs.get("annotationserver.log4j.configured") == null) {
    149161                // TODO: is this the right place to run the log4j configurator?
    150162                BasicConfigurator.configure();
    151                 sc.setAttribute("annotationserver.log4j.configured", "done");
     163                attrs.put("annotationserver.log4j.configured", "done");
    152164            }
    153165            logger.info(getVersion() + " starting...");
     
    156168             * read config from webapp
    157169             */
    158             serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);
     170            serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY);
    159171            if (serverConfig == null) {
    160172                serverConfig = new Properties();
     
    192204                }
    193205                // store config
    194                 sc.setAttribute(SERVERCONFIG_KEY, serverConfig);
     206                attrs.put(SERVERCONFIG_KEY, serverConfig);
    195207            }
    196208            // look for database service in context
    197             graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
     209            graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY);
    198210            if (graphDb == null) {
    199211                /*
     
    208220                    registerShutdownHook(graphDb);
    209221                    // store in context
    210                     sc.setAttribute(GRAPHDB_KEY, graphDb);
     222                    attrs.put(GRAPHDB_KEY, graphDb);
    211223                    // AnnotationStore
    212224                    store = new AnnotationStore(graphDb);
    213                     sc.setAttribute(ANNSTORE_KEY, store);
     225                    attrs.put(ANNSTORE_KEY, store);
    214226                    // admin server
    215227                    srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb);
    216228                    logger.debug("Starting DB admin server...");
    217229                    // store in context
    218                     sc.setAttribute(GRAPHDBSRV_KEY, srv);
     230                    attrs.put(GRAPHDBSRV_KEY, srv);
    219231                    srv.start();
    220232                } else {
     
    223235            } else {
    224236                // get existing AnnotationStore
    225                 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);
     237                store = (AnnotationStore) attrs.get(ANNSTORE_KEY);
    226238            }
    227239            /*
    228240             * read consumerKeys from webapp
    229241             */
    230             consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);
     242            consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY);
    231243            if (consumerKeys == null) {
    232244                consumerKeys = new Properties();
     
    245257                }
    246258                // store config
    247                 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
     259                attrs.put(CONSUMERKEYS_KEY, consumerKeys);
    248260            }
    249261        } else {
     
    342354     */
    343355    protected InputStream getResourceAsStream(ServletContext sc, String path) {
    344         InputStream ps = sc.getResourceAsStream(path);
    345         if (ps == null) {
    346             // try as file
    347             File pf = new File(sc.getRealPath(path));
    348             if (pf != null) {
    349                 logger.debug("trying file for: " + pf);
    350                 try {
    351                     ps = new FileInputStream(pf);
    352                 } catch (FileNotFoundException e) {
    353                     logger.error(e);
     356        InputStream ps = null;
     357        if (sc == null) {
     358            ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
     359        } else {
     360            ps = sc.getResourceAsStream(path);
     361            if (ps == null) {
     362                // try as file
     363                File pf = new File(sc.getRealPath(path));
     364                if (pf != null) {
     365                    logger.debug("trying file for: " + pf);
     366                    try {
     367                        ps = new FileInputStream(pf);
     368                    } catch (FileNotFoundException e) {
     369                        logger.error(e);
     370                    }
    354371                }
    355372            }
     
    371388        File f = new File(filename);
    372389        // is the filename absolute?
    373         if (!f.isAbsolute()) {
     390        if (!f.isAbsolute() && sc != null) {
    374391            // relative path -> use getRealPath to resolve in webapp
    375392            filename = sc.getRealPath(filename);
Note: See TracChangeset for help on using the changeset viewer.