annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java @ 71:326369d4bc4d

trying restlet 2.1. doesn't work yet.
author casties
date Fri, 07 Mar 2014 13:48:50 +0100
parents 2b1e6df5e21a
children 4c2cea836bc0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
1 package de.mpiwg.itgroup.annotations.restlet;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
2
70
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
3 /*
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
4 * #%L
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
5 * AnnotationManager
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
6 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
7 * Copyright (C) 2012 - 2014 MPIWG Berlin
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
8 * %%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
9 * This program is free software: you can redistribute it and/or modify
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
10 * it under the terms of the GNU Lesser General Public License as
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
12 * License, or (at your option) any later version.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
13 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
14 * This program is distributed in the hope that it will be useful,
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
17 * GNU General Lesser Public License for more details.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
18 *
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
19 * You should have received a copy of the GNU General Lesser Public
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
20 * License along with this program. If not, see
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
22 * #L%
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
23 * Author: Robert Casties (casties@mpiwg-berlin.mpg.de)
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
24 */
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
25
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
26 import java.io.File;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
27 import java.io.FileInputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
28 import java.io.FileNotFoundException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
29 import java.io.IOException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30 import java.io.InputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
31 import java.util.Hashtable;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32 import java.util.Properties;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
33 import java.util.concurrent.ConcurrentMap;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
34
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
35 import javax.naming.NamingEnumeration;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
36 import javax.naming.NamingException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
37 import javax.naming.directory.Attribute;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
38 import javax.naming.directory.DirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
39 import javax.naming.directory.InitialDirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 import javax.naming.directory.SearchControls;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41 import javax.naming.directory.SearchResult;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
42 import javax.servlet.ServletContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
43
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
44 import org.apache.log4j.BasicConfigurator;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
45 import org.apache.log4j.Logger;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
46 import org.neo4j.graphdb.GraphDatabaseService;
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
47 import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
48 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
49 import org.neo4j.graphdb.factory.GraphDatabaseSettings;
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
50 import org.neo4j.kernel.GraphDatabaseAPI;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
51 import org.neo4j.server.WrappingNeoServerBootstrapper;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
52 import org.restlet.Application;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
53 import org.restlet.Context;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
54 import org.restlet.Restlet;
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
55 import org.restlet.data.LocalReference;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
57 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
58
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
59 public abstract class BaseRestlet extends Application {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
60
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
61 public static Logger logger = Logger.getLogger(BaseRestlet.class);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
62
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
63 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
64 * Properties holding consumer keys and secrets.
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
65 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
66 protected Properties consumerKeys;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
67 public String CONSUMER_KEYS_PATH = "consumerkeys.property";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
68 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
69
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
70 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
71 * Properties holding server config.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
72 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
73 protected Properties serverConfig;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
74 public String CONFIG_PROPS_PATH = "serverconfig.property";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
75 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
76
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
77 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
78 * database instance;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
79 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
80 protected GraphDatabaseService graphDb;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
81 public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
82 public static final String GRAPHDB_PATH_KEY = "annotationmanager.graphdb.path";
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
83 public String graphdbPath = "neo4j-annotation-db";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
84
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
85 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
86 * database interface server instance.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
87 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
88 protected WrappingNeoServerBootstrapper srv;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
89 public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
90
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
91 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
92 * annotation store instance.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
93 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
94 protected AnnotationStore store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
95 public static final String ANNSTORE_KEY = "annotationmanager.store";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
96
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
97 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
98 * LDAP server URI (for looking up full user names).
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
99 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
100 protected String ldapServerUrl;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
101 public static final String LDAP_SERVER_KEY = "annotationmanager.ldapserver.url";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
102
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
103 public static final String ADMIN_USER_KEY = "annotationmanager.admin.user";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
104 public static final String ADMIN_PASSWORD_KEY = "annotationmanager.admin.password";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
105
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
106 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
107 * run in authorization mode i.e. with tokens.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
108 */
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
109 protected boolean authorizationMode = false;
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
110 public static final String AUTHORIZATION_MODE_KEY = "annotationmanager.authorization";
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
111
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
112 /**
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
113 * prefix to create uris for tags in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
114 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
115 public static String TAGS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
116 public static final String TAGS_URI_KEY = "annotationmanager.uris.tags";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
117
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
118 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
119 * prefix to create uris for persons in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
120 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
121 public static String PERSONS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
122 public static final String PERSONS_URI_KEY = "annotationmanager.uris.persons";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
123
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
124 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
125 * prefix to create uris for groups in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
126 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
127 public static String GROUPS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
128 public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
129
59
e2f86ef9b871 make annotation uri in store configurable. fix npe with no tags.
casties
parents: 58
diff changeset
130 public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations";
e2f86ef9b871 make annotation uri in store configurable. fix npe with no tags.
casties
parents: 58
diff changeset
131
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
132 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
133 * constructor
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
134 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
135 * @param context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
136 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
137 public BaseRestlet(Context context) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
138 super(context);
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
139 configure(context);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
140 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
141
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
142 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
143 * Configures the restlet.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
144 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
145 * Uses config from webapp context if already initialized.
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
146 * @param context
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
147 */
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
148 protected void configure(Context context) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
149 Context ctx = Context.getCurrent();
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
150 ConcurrentMap<String, Object> attrs = ctx.getAttributes();
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
151 ServletContext sc = null;
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
152 if (context != null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
153 Restlet a = context.getServerDispatcher();
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
154 Context b = a.getContext();
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
155 ConcurrentMap<String, Object> c = b.getAttributes();
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
156 sc = (ServletContext) context.getServerDispatcher().getContext().getAttributes()
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
157 .get("org.restlet.ext.servlet.ServletContext");
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
158 }
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
159 if (attrs != null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
160 if (attrs.get("annotationserver.log4j.configured") == null) {
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
161 // TODO: is this the right place to run the log4j configurator?
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
162 BasicConfigurator.configure();
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
163 attrs.put("annotationserver.log4j.configured", "done");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
164 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
165 logger.info(getVersion() + " starting...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
166
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
167 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
168 * read config from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
169 */
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
170 serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
171 if (serverConfig == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
172 serverConfig = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
173 InputStream ps = getResourceAsStream(sc, CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
174 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
175 logger.debug("loading config from " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
176 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
177 serverConfig.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
178 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
179 * read serverconfig options
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
180 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
181 graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
182 ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null);
60
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
183 /*
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
184 * uri prefixes
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
185 */
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
186 if (serverConfig.containsKey(PERSONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
187 BaseRestlet.PERSONS_URI_PREFIX = serverConfig.getProperty(PERSONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
188 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
189 if (serverConfig.containsKey(GROUPS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
190 BaseRestlet.GROUPS_URI_PREFIX = serverConfig.getProperty(GROUPS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
191 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
192 if (serverConfig.containsKey(TAGS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
193 BaseRestlet.TAGS_URI_PREFIX = serverConfig.getProperty(TAGS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
194 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
195 if (serverConfig.containsKey(ANNOTATIONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
196 AnnotationStore.ANNOTATION_URI_PREFIX = serverConfig.getProperty(ANNOTATIONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
197 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
198 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
199 logger.warn("Error loading server config: ", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
200 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
201 logger.debug("config: " + serverConfig);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
202 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
203 logger.error("Unable to get resource " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
204 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
205 // store config
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
206 attrs.put(SERVERCONFIG_KEY, serverConfig);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
207 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
208 // look for database service in context
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
209 graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
210 if (graphDb == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
211 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
212 * open database
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
213 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
214 String dbFn = getResourcePath(sc, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
215 if (dbFn != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
216 logger.debug("opening DB " + dbFn);
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
217 GraphDatabaseBuilder graphDbBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFn);
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
218 graphDbBuilder.setConfig(GraphDatabaseSettings.allow_store_upgrade, "true");
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
219 graphDb = graphDbBuilder.newGraphDatabase();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
220 registerShutdownHook(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
221 // store in context
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
222 attrs.put(GRAPHDB_KEY, graphDb);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
223 // AnnotationStore
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
224 store = new AnnotationStore(graphDb);
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
225 attrs.put(ANNSTORE_KEY, store);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
226 // admin server
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
227 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
228 logger.debug("Starting DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
229 // store in context
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
230 attrs.put(GRAPHDBSRV_KEY, srv);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
231 srv.start();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
232 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
233 logger.error("Unable to get resource " + dbFn);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
234 }
22
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
235 } else {
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
236 // get existing AnnotationStore
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
237 store = (AnnotationStore) attrs.get(ANNSTORE_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
238 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
239 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
240 * read consumerKeys from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
241 */
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
242 consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
243 if (consumerKeys == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
244 consumerKeys = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
245 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
246 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
247 logger.debug("loading consumer keys from " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
248 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
249 consumerKeys.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
250 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
251 // TODO Auto-generated catch block
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
252 e.printStackTrace();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
253 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
254 logger.debug("consumer keys: " + consumerKeys);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
255 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
256 logger.error("Unable to get resource " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
257 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
258 // store config
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
259 attrs.put(CONSUMERKEYS_KEY, consumerKeys);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
260 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
261 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
262 logger.error("Unable to get ServletContext!");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
263 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
264 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
265
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
266 public abstract String getVersion();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
267
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
268 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
269 * @return the authorizationMode
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
270 */
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
271 public boolean isAuthorizationMode() {
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
272 return authorizationMode;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
273 }
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
274
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
275 /**
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
276 * @return the store
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
277 */
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
278 public AnnotationStore getAnnotationStore() {
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
279 return store;
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
280 }
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
281
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
282 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
283 * returns consumer secret for consumer key. returns null if consumer key
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
284 * doesn't exist.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
285 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
286 * @param consumerKey
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
287 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
288 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
289 public String getConsumerSecret(String consumerKey) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
290 return consumerKeys.getProperty(consumerKey);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
291 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
292
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
293 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
294 * Hole den vollen Benutzernamen aus dem LDAP
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
295 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
296 * @param creator
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
297 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
298 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
299 public String getFullNameFromLdap(String creator) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
300 String retString = creator; // falls nichts gefunden wird einfach den
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
301 // creator zurueckgeben
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
302 if (ldapServerUrl == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
303 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
304 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
305 Hashtable<String, String> env = new Hashtable<String, String>();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
306 String sp = "com.sun.jndi.ldap.LdapCtxFactory";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
307 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
308 env.put(javax.naming.Context.PROVIDER_URL, ldapServerUrl);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
309
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
310 DirContext dctx;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
311 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
312 dctx = new InitialDirContext(env);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
313 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
314 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
315 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
316 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
317
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
318 String base = "ou=people";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
319
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
320 SearchControls sc = new SearchControls();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
321 String[] attributeFilter = { "cn", "mail" };
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
322 sc.setReturningAttributes(attributeFilter);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
323 sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
324
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
325 String filter = "(uid=" + creator + ")";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
326
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
327 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
328 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
329 while (results.hasMore()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
330 SearchResult sr = (SearchResult) results.next();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
331 javax.naming.directory.Attributes attrs = sr.getAttributes();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
332
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
333 Attribute attr = attrs.get("cn");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
334 retString = (String) attr.get();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
335 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
336 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
337 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
338 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
339
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
340 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
341 dctx.close();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
342 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
343 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
344 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
345 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
346 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
347
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
348 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
349 * returns resource from path (in webapp) as InputStream.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
350 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
351 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
352 * @param path
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
353 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
354 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
355 protected InputStream getResourceAsStream(ServletContext sc, String path) {
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
356 InputStream ps = null;
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
357 if (sc == null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
358 ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
359 } else {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
360 ps = sc.getResourceAsStream(path);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
361 if (ps == null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
362 // try as file
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
363 File pf = new File(sc.getRealPath(path));
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
364 if (pf != null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
365 logger.debug("trying file for: " + pf);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
366 try {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
367 ps = new FileInputStream(pf);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
368 } catch (FileNotFoundException e) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
369 logger.error(e);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
370 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
371 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
372 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
373 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
374 return ps;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
375 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
376
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
377 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
378 * get a real file name for a web app file pathname.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
379 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
380 * If filename starts with "/" its treated as absolute else the path is
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
381 * appended to the base directory of the web-app.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
382 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
383 * @param filename
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
384 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
385 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
386 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
387 public static String getResourcePath(ServletContext sc, String filename) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
388 File f = new File(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
389 // is the filename absolute?
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
390 if (!f.isAbsolute() && sc != null) {
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
391 // relative path -> use getRealPath to resolve in webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
392 filename = sc.getRealPath(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
393 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
394 return filename;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
395 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
396
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
397 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
398 * (non-Javadoc)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
399 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
400 * @see org.restlet.Application#stop()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
401 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
402 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
403 public synchronized void stop() throws Exception {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
404 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
405 * trying to clean up databases, not sure if this is the right way...
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
406 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
407 if (srv != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
408 logger.debug("Stopping DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
409 srv.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
410 srv = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
411 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
412 if (graphDb != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
413 logger.debug("Stopping DB...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
414 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
415 graphDb = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
416 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
417 super.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
418 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
419
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
420 private static void registerShutdownHook(final GraphDatabaseService graphDb) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
421 // Registers a shutdown hook for the Neo4j instance so that it
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
422 // shuts down nicely when the VM exits (even if you "Ctrl-C" the
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
423 // running example before it's completed)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
424 Runtime.getRuntime().addShutdownHook(new Thread() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
425 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
426 public void run() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
427 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
428 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
429 });
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
430 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
431
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
432 }