Changeset 72:4c2cea836bc0 in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java
r71 r72 130 130 public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations"; 131 131 132 /** 133 * constructor134 * 135 * @param context136 */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(); 140 140 } 141 141 … … 147 147 */ 148 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() 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) { 161 153 // TODO: is this the right place to run the log4j configurator? 162 154 BasicConfigurator.configure(); 163 attrs.put("annotationserver.log4j.configured", "done");155 sc.setAttribute("annotationserver.log4j.configured", "done"); 164 156 } 165 157 logger.info(getVersion() + " starting..."); … … 168 160 * read config from webapp 169 161 */ 170 serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY);162 serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY); 171 163 if (serverConfig == null) { 172 164 serverConfig = new Properties(); … … 204 196 } 205 197 // store config 206 attrs.put(SERVERCONFIG_KEY, serverConfig);198 sc.setAttribute(SERVERCONFIG_KEY, serverConfig); 207 199 } 208 200 // look for database service in context 209 graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY);201 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY); 210 202 if (graphDb == null) { 211 203 /* … … 220 212 registerShutdownHook(graphDb); 221 213 // store in context 222 attrs.put(GRAPHDB_KEY, graphDb);214 sc.setAttribute(GRAPHDB_KEY, graphDb); 223 215 // AnnotationStore 224 216 store = new AnnotationStore(graphDb); 225 attrs.put(ANNSTORE_KEY, store);217 sc.setAttribute(ANNSTORE_KEY, store); 226 218 // admin server 227 219 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb); 228 220 logger.debug("Starting DB admin server..."); 229 221 // store in context 230 attrs.put(GRAPHDBSRV_KEY, srv);222 sc.setAttribute(GRAPHDBSRV_KEY, srv); 231 223 srv.start(); 232 224 } else { … … 235 227 } else { 236 228 // get existing AnnotationStore 237 store = (AnnotationStore) attrs.get(ANNSTORE_KEY);229 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY); 238 230 } 239 231 /* 240 232 * read consumerKeys from webapp 241 233 */ 242 consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY);234 consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY); 243 235 if (consumerKeys == null) { 244 236 consumerKeys = new Properties(); … … 257 249 } 258 250 // store config 259 attrs.put(CONSUMERKEYS_KEY, consumerKeys);251 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys); 260 252 } 261 253 } else { … … 356 348 InputStream ps = null; 357 349 if (sc == null) { 350 // no servlet context -> use class loader 358 351 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(); */ 359 355 } else { 356 // try path in webapp first 360 357 ps = sc.getResourceAsStream(path); 361 358 if (ps == null) { 362 359 // try as file 363 360 File pf = new File(sc.getRealPath(path)); 364 if (pf != null) {361 if (pf.canRead()) { 365 362 logger.debug("trying file for: " + pf); 366 363 try { … … 369 366 logger.error(e); 370 367 } 368 } else { 369 // use class loader 370 ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); 371 371 } 372 372 }
Note: See TracChangeset
for help on using the changeset viewer.