annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java @ 86:e3f0613b2f2d

renamed getFullname to make it configurable. fixed Restlet at 2.2.3.
author casties
date Mon, 02 Feb 2015 11:32:53 +0100
parents 4724fc7b4733
children 247cbbb385de
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%
86
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
23 * Author: Robert Casties (casties@mpiwg-berlin.mpg.de),
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
24 * Dirk Wintergruen (dwinter@mpiwg-berlin.mpg.de)
70
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
25 */
2b1e6df5e21a added lgpl_v3 license information.
casties
parents: 66
diff changeset
26
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
27 import java.io.File;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
28 import java.io.FileInputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
29 import java.io.FileNotFoundException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30 import java.io.IOException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
31 import java.io.InputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32 import java.util.Hashtable;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
33 import java.util.Properties;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
34 import java.util.concurrent.ConcurrentMap;
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
35 import java.util.logging.Logger;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
36
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
37 import javax.naming.NamingEnumeration;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
38 import javax.naming.NamingException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
39 import javax.naming.directory.Attribute;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 import javax.naming.directory.DirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41 import javax.naming.directory.InitialDirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
42 import javax.naming.directory.SearchControls;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
43 import javax.naming.directory.SearchResult;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
44 import javax.servlet.ServletContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
45
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;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
54
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
55 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
57 public abstract class BaseRestlet extends Application {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
58
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
59 public static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.restlet.BaseRestlet");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
60
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
61 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
62 * Properties holding consumer keys and secrets.
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
63 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
64 protected Properties consumerKeys;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
65 public String CONSUMER_KEYS_PATH = "consumerkeys.property";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
66 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
67
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
68 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
69 * 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
70 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
71 protected Properties serverConfig;
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
72 public String CONFIG_PROPS_PATH = "serverconfig.property";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
73 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
74
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
75 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
76 * database instance;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
77 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
78 protected GraphDatabaseService graphDb;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
79 public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
80 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
81 public String graphdbPath = "neo4j-annotation-db";
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
82
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
83 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
84 * 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
85 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
86 protected WrappingNeoServerBootstrapper srv;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
87 public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
88
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
89 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
90 * annotation store instance.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
91 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
92 protected AnnotationStore store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
93 public static final String ANNSTORE_KEY = "annotationmanager.store";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
94
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
95 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
96 * 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
97 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
98 protected String ldapServerUrl;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
99 public static final String LDAP_SERVER_KEY = "annotationmanager.ldapserver.url";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
100
86
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
101 /**
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
102 * web frontend admin user name
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
103 */
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
104 public static final String ADMIN_USER_KEY = "annotationmanager.admin.user";
86
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
105 /**
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
106 * web frontend admin user password
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
107 */
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
108 public static final String ADMIN_PASSWORD_KEY = "annotationmanager.admin.password";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
109
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
110 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
111 * 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
112 */
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
113 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
114 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
115
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
116 /**
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
117 * prefix to create uris for tags in store.
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 public static String TAGS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
120 public static final String TAGS_URI_KEY = "annotationmanager.uris.tags";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
121
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
122 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
123 * prefix to create uris for persons in store.
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 public static String PERSONS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
126 public static final String PERSONS_URI_KEY = "annotationmanager.uris.persons";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
127
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
128 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
129 * prefix to create uris for groups in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
130 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
131 public static String GROUPS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
132 public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
133
59
e2f86ef9b871 make annotation uri in store configurable. fix npe with no tags.
casties
parents: 58
diff changeset
134 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
135
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
136
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
137 /* (non-Javadoc)
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
138 * @see org.restlet.Application#start()
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
139 */
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
140 @Override
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
141 public synchronized void start() throws Exception {
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
142 configure(getContext());
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
143 super.start();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
144 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
145
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
146 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
147 * Configures the restlet.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
148 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
149 * Uses config from webapp context if already initialized.
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
150 * @param context
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
151 */
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
152 protected void configure(Context context) {
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
153 ConcurrentMap<String, Object> attrs = context.getAttributes();
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
154 ServletContext sc = (ServletContext) attrs.get("org.restlet.ext.servlet.ServletContext");
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
155 if (sc != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
156 logger = context.getLogger();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
157 logger.info(getVersion() + " starting...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
158
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
159 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
160 * read config from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
161 */
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
162 serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
163 if (serverConfig == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
164 serverConfig = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
165 InputStream ps = getResourceAsStream(sc, CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
166 if (ps != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
167 logger.fine("loading config from " + CONFIG_PROPS_PATH);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
168 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
169 serverConfig.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
170 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
171 * read serverconfig options
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
172 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
173 graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
174 ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null);
60
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
175 /*
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
176 * uri prefixes
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
177 */
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
178 if (serverConfig.containsKey(PERSONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
179 BaseRestlet.PERSONS_URI_PREFIX = serverConfig.getProperty(PERSONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
180 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
181 if (serverConfig.containsKey(GROUPS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
182 BaseRestlet.GROUPS_URI_PREFIX = serverConfig.getProperty(GROUPS_URI_KEY);
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 if (serverConfig.containsKey(TAGS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
185 BaseRestlet.TAGS_URI_PREFIX = serverConfig.getProperty(TAGS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
186 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
187 if (serverConfig.containsKey(ANNOTATIONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
188 AnnotationStore.ANNOTATION_URI_PREFIX = serverConfig.getProperty(ANNOTATIONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
189 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
190 } catch (IOException e) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
191 logger.warning("Error loading server config: "+e.toString());
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
192 }
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
193 logger.fine("config: " + serverConfig);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
194 } else {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
195 logger.severe("Unable to get resource " + CONFIG_PROPS_PATH);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
196 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
197 // store config
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
198 sc.setAttribute(SERVERCONFIG_KEY, serverConfig);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
199 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
200 // look for database service in context
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
201 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
202 if (graphDb == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
203 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
204 * open database
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
205 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
206 String dbFn = getResourcePath(sc, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
207 if (dbFn != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
208 logger.fine("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
209 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
210 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
211 graphDb = graphDbBuilder.newGraphDatabase();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
212 registerShutdownHook(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
213 // store in context
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
214 sc.setAttribute(GRAPHDB_KEY, graphDb);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
215 // AnnotationStore
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
216 store = new AnnotationStore(graphDb);
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
217 sc.setAttribute(ANNSTORE_KEY, store);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
218 // 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
219 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb);
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
220 logger.fine("Starting DB admin server...");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
221 // store in context
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
222 sc.setAttribute(GRAPHDBSRV_KEY, srv);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
223 srv.start();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
224 } else {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
225 logger.severe("Unable to get resource " + dbFn);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
226 }
22
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
227 } else {
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
228 // get existing AnnotationStore
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
229 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
230 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
231 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
232 * read consumerKeys from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
233 */
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
234 consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
235 if (consumerKeys == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
236 consumerKeys = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
237 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
238 if (ps != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
239 logger.fine("loading consumer keys from " + CONSUMER_KEYS_PATH);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
240 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
241 consumerKeys.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
242 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
243 // TODO Auto-generated catch block
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
244 e.printStackTrace();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
245 }
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
246 logger.fine("consumer keys: " + consumerKeys);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
247 } else {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
248 logger.severe("Unable to get resource " + CONSUMER_KEYS_PATH);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
249 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
250 // store config
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
251 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
252 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
253 } else {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
254 logger.severe("Unable to get ServletContext!");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
255 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
256 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
257
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
258 public abstract String getVersion();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
259
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
260 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
261 * @return the authorizationMode
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
262 */
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
263 public boolean isAuthorizationMode() {
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
264 return authorizationMode;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
265 }
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
266
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
267 /**
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
268 * @return the store
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
269 */
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
270 public AnnotationStore getAnnotationStore() {
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
271 return store;
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
272 }
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
273
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
274 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
275 * returns consumer secret for consumer key. returns null if consumer key
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
276 * doesn't exist.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
277 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
278 * @param consumerKey
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
279 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
280 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
281 public String getConsumerSecret(String consumerKey) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
282 return consumerKeys.getProperty(consumerKey);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
283 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
284
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
285 /**
86
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
286 * Return the full name (String) of the person with the given user-id.
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
287 *
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
288 * Contacts a naming service (currently LDAP).
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
289 *
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
290 * @param userId
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
291 * @return full-name
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
292 */
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
293 public String getFullNameForId(String userId) {
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
294 return getFullNameFromLdap(userId);
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
295 }
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
296
e3f0613b2f2d renamed getFullname to make it configurable.
casties
parents: 80
diff changeset
297 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
298 * Hole den vollen Benutzernamen aus dem LDAP
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
299 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
300 * @param creator
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
301 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
302 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
303 public String getFullNameFromLdap(String creator) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
304 String retString = creator; // falls nichts gefunden wird einfach den
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
305 // creator zurueckgeben
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
306 if (ldapServerUrl == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
307 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
308 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
309 Hashtable<String, String> env = new Hashtable<String, String>();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
310 String sp = "com.sun.jndi.ldap.LdapCtxFactory";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
311 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
312 env.put(javax.naming.Context.PROVIDER_URL, ldapServerUrl);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
313
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
314 DirContext dctx;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
315 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
316 dctx = new InitialDirContext(env);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
317 } catch (NamingException e) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
318 logger.warning("Error in getFullNameFromLDAP! "+e);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
319 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
320 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
321
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
322 String base = "ou=people";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
323
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
324 SearchControls sc = new SearchControls();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
325 String[] attributeFilter = { "cn", "mail" };
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
326 sc.setReturningAttributes(attributeFilter);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
327 sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
328
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
329 String filter = "(uid=" + creator + ")";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
330
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
331 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
332 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
333 while (results.hasMore()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
334 SearchResult sr = (SearchResult) results.next();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
335 javax.naming.directory.Attributes attrs = sr.getAttributes();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
336
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
337 Attribute attr = attrs.get("cn");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
338 retString = (String) attr.get();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
339 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
340 } catch (NamingException e) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
341 logger.warning("Error in getFullNameFromLDAP!"+e);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
342 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
343
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
344 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
345 dctx.close();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
346 } catch (NamingException e) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
347 logger.warning("Error in getFullNameFromLDAP!"+e);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
348 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
349 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
350 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
351
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
352 /**
74
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
353 * returns resource from path as InputStream.
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
354 *
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
355 * Tries path in webapp first, then uses classpath loader.
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
356 * Relative paths in webapp start in /WEB-INF/.
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
357 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
358 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
359 * @param path
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
360 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
361 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
362 protected InputStream getResourceAsStream(ServletContext sc, String path) {
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
363 InputStream ps = null;
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
364 if (sc == null) {
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
365 // no servlet context -> use class loader
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
366 ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
367 } else {
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
368 // try path in webapp first
74
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
369 String webPath = path;
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
370 if (!webPath.startsWith("/")) {
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
371 // relative path in webapp starts in WEB-INF
80
4724fc7b4733 add slashes to paths for getRealPath to work with Tomcat 8.
casties
parents: 75
diff changeset
372 webPath = "/WEB-INF/" + webPath;
74
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
373 }
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
374 ps = sc.getResourceAsStream(webPath);
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
375 if (ps == null) {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
376 // try as file
74
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
377 File pf = new File(sc.getRealPath(webPath));
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
378 if (pf.canRead()) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
379 logger.fine("trying file for: " + pf);
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
380 try {
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
381 ps = new FileInputStream(pf);
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
382 } catch (FileNotFoundException e) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
383 logger.severe(e.toString());
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
384 }
72
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
385 } else {
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
386 // use class loader
4c2cea836bc0 restlet 2.1 works now. (it's the start() method, stupid!)
casties
parents: 71
diff changeset
387 ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
388 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
389 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
390 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
391 return ps;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
392 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
393
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
394 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
395 * get a real file name for a web app file pathname.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
396 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
397 * If filename starts with "/" its treated as absolute else the path is
74
e5ff09208c28 search files in webapp in WEB-INF folder.
casties
parents: 73
diff changeset
398 * appended to the /WEB-INF/ directory in the web-app.
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
399 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
400 * @param filename
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
401 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
402 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
403 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
404 public static String getResourcePath(ServletContext sc, String filename) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
405 File f = new File(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
406 // is the filename absolute?
71
326369d4bc4d trying restlet 2.1. doesn't work yet.
casties
parents: 70
diff changeset
407 if (!f.isAbsolute() && sc != null) {
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
408 // relative path -> use getRealPath to resolve in webapp
80
4724fc7b4733 add slashes to paths for getRealPath to work with Tomcat 8.
casties
parents: 75
diff changeset
409 filename = sc.getRealPath("/WEB-INF/" + filename);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
410 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
411 return filename;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
412 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
413
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
414 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
415 * (non-Javadoc)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
416 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
417 * @see org.restlet.Application#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 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
420 public synchronized void stop() throws Exception {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
421 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
422 * trying to clean up databases, not sure if this is the right way...
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
423 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
424 if (srv != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
425 logger.info("Stopping DB admin server...");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
426 srv.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
427 srv = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
428 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
429 if (graphDb != null) {
75
25eb2e1df106 change logging to java.util.logging.
casties
parents: 74
diff changeset
430 logger.info("Stopping DB...");
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
431 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
432 graphDb = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
433 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
434 super.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
435 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
436
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
437 private static void registerShutdownHook(final GraphDatabaseService graphDb) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
438 // Registers a shutdown hook for the Neo4j instance so that it
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
439 // shuts down nicely when the VM exits (even if you "Ctrl-C" the
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
440 // running example before it's completed)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
441 Runtime.getRuntime().addShutdownHook(new Thread() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
442 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
443 public void run() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
444 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
445 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
446 });
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
447 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
448
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
449 }