Changeset 71:326369d4bc4d in AnnotationManagerN4J
- Timestamp:
- Mar 7, 2014, 12:48:50 PM (11 years ago)
- Branch:
- default
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pom.xml
r70 r71 8 8 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 9 9 <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> 12 12 </properties> 13 13 <repositories> -
src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java
r70 r71 31 31 import java.util.Hashtable; 32 32 import java.util.Properties; 33 import java.util.concurrent.ConcurrentMap; 33 34 34 35 import javax.naming.NamingEnumeration; … … 51 52 import org.restlet.Application; 52 53 import org.restlet.Context; 54 import org.restlet.Restlet; 55 import org.restlet.data.LocalReference; 53 56 54 57 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 62 65 */ 63 66 protected Properties consumerKeys; 64 public String CONSUMER_KEYS_PATH = " WEB-INF/consumerkeys.property";67 public String CONSUMER_KEYS_PATH = "consumerkeys.property"; 65 68 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys"; 66 69 … … 69 72 */ 70 73 protected Properties serverConfig; 71 public String CONFIG_PROPS_PATH = " WEB-INF/serverconfig.property";74 public String CONFIG_PROPS_PATH = "serverconfig.property"; 72 75 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig"; 73 76 … … 78 81 public static final String GRAPHDB_KEY = "annotationmanager.graphdb"; 79 82 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"; 81 84 82 85 /** … … 134 137 public BaseRestlet(Context context) { 135 138 super(context); 136 configure( );139 configure(context); 137 140 } 138 141 … … 141 144 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb. 142 145 * 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() 146 157 .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) { 149 161 // TODO: is this the right place to run the log4j configurator? 150 162 BasicConfigurator.configure(); 151 sc.setAttribute("annotationserver.log4j.configured", "done");163 attrs.put("annotationserver.log4j.configured", "done"); 152 164 } 153 165 logger.info(getVersion() + " starting..."); … … 156 168 * read config from webapp 157 169 */ 158 serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);170 serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY); 159 171 if (serverConfig == null) { 160 172 serverConfig = new Properties(); … … 192 204 } 193 205 // store config 194 sc.setAttribute(SERVERCONFIG_KEY, serverConfig);206 attrs.put(SERVERCONFIG_KEY, serverConfig); 195 207 } 196 208 // look for database service in context 197 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);209 graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY); 198 210 if (graphDb == null) { 199 211 /* … … 208 220 registerShutdownHook(graphDb); 209 221 // store in context 210 sc.setAttribute(GRAPHDB_KEY, graphDb);222 attrs.put(GRAPHDB_KEY, graphDb); 211 223 // AnnotationStore 212 224 store = new AnnotationStore(graphDb); 213 sc.setAttribute(ANNSTORE_KEY, store);225 attrs.put(ANNSTORE_KEY, store); 214 226 // admin server 215 227 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb); 216 228 logger.debug("Starting DB admin server..."); 217 229 // store in context 218 sc.setAttribute(GRAPHDBSRV_KEY, srv);230 attrs.put(GRAPHDBSRV_KEY, srv); 219 231 srv.start(); 220 232 } else { … … 223 235 } else { 224 236 // get existing AnnotationStore 225 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);237 store = (AnnotationStore) attrs.get(ANNSTORE_KEY); 226 238 } 227 239 /* 228 240 * read consumerKeys from webapp 229 241 */ 230 consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);242 consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY); 231 243 if (consumerKeys == null) { 232 244 consumerKeys = new Properties(); … … 245 257 } 246 258 // store config 247 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);259 attrs.put(CONSUMERKEYS_KEY, consumerKeys); 248 260 } 249 261 } else { … … 342 354 */ 343 355 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 } 354 371 } 355 372 } … … 371 388 File f = new File(filename); 372 389 // is the filename absolute? 373 if (!f.isAbsolute() ) {390 if (!f.isAbsolute() && sc != null) { 374 391 // relative path -> use getRealPath to resolve in webapp 375 392 filename = sc.getRealPath(filename);
Note: See TracChangeset
for help on using the changeset viewer.