Ignore:
Timestamp:
Mar 11, 2014, 4:43:00 PM (10 years ago)
Author:
casties
Branch:
default
Message:

restlet 2.1 works now. (it's the start() method, stupid!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java

    r71 r72  
    130130    public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations";
    131131
    132     /**
    133      * constructor
    134      *
    135      * @param context
    136      */
    137     public BaseRestlet(Context context) {
    138         super(context);
    139         configure(context);
     132
     133    /* (non-Javadoc)
     134     * @see org.restlet.Application#start()
     135     */
     136    @Override
     137    public synchronized void start() throws Exception {
     138        configure(getContext());
     139        super.start();
    140140    }
    141141
     
    147147     */
    148148    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()
    157                 .get("org.restlet.ext.servlet.ServletContext");
    158         }
    159         if (attrs != null) {
    160             if (attrs.get("annotationserver.log4j.configured") == null) {
     149        ConcurrentMap<String, Object> attrs = context.getAttributes();
     150        ServletContext sc = (ServletContext) attrs.get("org.restlet.ext.servlet.ServletContext");
     151        if (sc != null) {
     152            if (sc.getAttribute("annotationserver.log4j.configured") == null) {
    161153                // TODO: is this the right place to run the log4j configurator?
    162154                BasicConfigurator.configure();
    163                 attrs.put("annotationserver.log4j.configured", "done");
     155                sc.setAttribute("annotationserver.log4j.configured", "done");
    164156            }
    165157            logger.info(getVersion() + " starting...");
     
    168160             * read config from webapp
    169161             */
    170             serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY);
     162            serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);
    171163            if (serverConfig == null) {
    172164                serverConfig = new Properties();
     
    204196                }
    205197                // store config
    206                 attrs.put(SERVERCONFIG_KEY, serverConfig);
     198                sc.setAttribute(SERVERCONFIG_KEY, serverConfig);
    207199            }
    208200            // look for database service in context
    209             graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY);
     201            graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
    210202            if (graphDb == null) {
    211203                /*
     
    220212                    registerShutdownHook(graphDb);
    221213                    // store in context
    222                     attrs.put(GRAPHDB_KEY, graphDb);
     214                    sc.setAttribute(GRAPHDB_KEY, graphDb);
    223215                    // AnnotationStore
    224216                    store = new AnnotationStore(graphDb);
    225                     attrs.put(ANNSTORE_KEY, store);
     217                    sc.setAttribute(ANNSTORE_KEY, store);
    226218                    // admin server
    227219                    srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb);
    228220                    logger.debug("Starting DB admin server...");
    229221                    // store in context
    230                     attrs.put(GRAPHDBSRV_KEY, srv);
     222                    sc.setAttribute(GRAPHDBSRV_KEY, srv);
    231223                    srv.start();
    232224                } else {
     
    235227            } else {
    236228                // get existing AnnotationStore
    237                 store = (AnnotationStore) attrs.get(ANNSTORE_KEY);
     229                store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);
    238230            }
    239231            /*
    240232             * read consumerKeys from webapp
    241233             */
    242             consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY);
     234            consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);
    243235            if (consumerKeys == null) {
    244236                consumerKeys = new Properties();
     
    257249                }
    258250                // store config
    259                 attrs.put(CONSUMERKEYS_KEY, consumerKeys);
     251                sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
    260252            }
    261253        } else {
     
    356348        InputStream ps = null;
    357349        if (sc == null) {
     350            // no servlet context -> use class loader
    358351            ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
     352            /* Request request = new Request(Method.GET, "riap://component/ping");
     353               Response response = getContext().getClientDispatcher().handle(request);
     354               Representation repr = response.getEntity(); */
    359355        } else {
     356            // try path in webapp first
    360357            ps = sc.getResourceAsStream(path);
    361358            if (ps == null) {
    362359                // try as file
    363360                File pf = new File(sc.getRealPath(path));
    364                 if (pf != null) {
     361                if (pf.canRead()) {
    365362                    logger.debug("trying file for: " + pf);
    366363                    try {
     
    369366                        logger.error(e);
    370367                    }
     368                } else {
     369                    // use class loader
     370                    ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);                   
    371371                }
    372372            }
Note: See TracChangeset for help on using the changeset viewer.