Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java @ 4196:e10d60d4f35b
Don't always redirect if user isn't authenticated
Only redirect a user if he is accessing the redirect url (FLYS.html by default).
In other cases only send a 403 Forbidden to indicate that a user isn't allowed
to access the url.
Should improve flys/issue856 (Timeout in der Authentifizierung führt zu Fehlern)
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 22 Oct 2012 10:35:49 +0200 |
parents | f2039d030b5e |
children | 2dac0e5b927e |
rev | line source |
---|---|
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
3 import org.w3c.dom.Document; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
4 import org.w3c.dom.Element; |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
6 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
7 |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
10 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
11 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
12 import de.intevation.artifacts.common.utils.XMLUtils; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
13 |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.client.shared.exceptions.ServerException; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.client.client.services.MetaDataService; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
18 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
19 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
20 import de.intevation.artifacts.httpclient.http.HttpClient; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
21 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
22 |
278
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
23 import de.intevation.flys.client.shared.model.DataCageTree; |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
24 |
286
0fa8bf8a2295
Datacage: Better converter for incoming XML tree
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
278
diff
changeset
|
25 import de.intevation.flys.client.server.meta.Converter; |
0fa8bf8a2295
Datacage: Better converter for incoming XML tree
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
278
diff
changeset
|
26 |
3346
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
27 /** |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
28 * Service that returns certain meta-data from the backends data, polished to |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
29 * inclusion into current project. |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
30 */ |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public class MetaDataServiceImpl |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 extends RemoteServiceServlet |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 implements MetaDataService |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 { |
3346
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
35 /** Our very own logger. */ |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
36 private static final Logger logger = |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
37 Logger.getLogger(MetaDataServiceImpl.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
38 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
39 public static final String ERROR_NO_META_DATA_FOUND = |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
40 "error_no_meta_data_found"; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
41 |
3346
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
42 |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
43 /** |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
44 * @param locale needed for i18n. |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
45 * @param artifactId ID of masterartifact (can be null) |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
46 * @param userId can be null |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
47 * @param outs can be null |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
48 * @param parameters can be null |
f2039d030b5e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1442
diff
changeset
|
49 */ |
827
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
50 @Override |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
51 public DataCageTree getMetaData( |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
52 String locale, |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
53 String artifactId, |
827
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
54 String userId, |
916
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
55 String outs, |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
56 String parameters |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
57 ) throws ServerException |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
916
diff
changeset
|
59 logger.info("MetaDataService.getMetaData"); |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
60 |
1442
4a6814be92ba
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1425
diff
changeset
|
61 // Create the query document. |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
62 String url = getServletContext().getInitParameter("server-url"); |
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
63 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
64 Document doc = XMLUtils.newDocument(); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
65 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
66 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
67 doc, |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
68 ArtifactNamespaceContext.NAMESPACE_URI, |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
69 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
70 |
812
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
71 Element meta = ec.create("meta"); |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
72 |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
73 if (artifactId != null) { |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
74 Element artifactEl = ec.create("artifact-id"); |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
75 artifactEl.setAttribute("value", artifactId); |
812
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
76 meta.appendChild(artifactEl); |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
77 } |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
78 |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
79 if (userId != null) { |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
80 Element userEl = ec.create("user-id"); |
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
81 userEl.setAttribute("value", userId); |
812
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
82 meta.appendChild(userEl); |
811
8fa303586f14
Pass user id to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
615
diff
changeset
|
83 } |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
84 |
827
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
85 if (outs != null) { |
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
86 Element outsEl = ec.create("outs"); |
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
87 outsEl.setAttribute("value", outs); |
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
88 meta.appendChild(outsEl); |
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
89 } |
bd56dc762e7f
Datacage: Re-added the outs parameter to the meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
812
diff
changeset
|
90 |
916
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
91 if (parameters != null) { |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
92 Element paramsEl = ec.create("parameters"); |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
93 paramsEl.setAttribute("value", parameters); |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
94 meta.appendChild(paramsEl); |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
95 } |
a1a5dc2b9e34
Improved the DEM datacage panel to display the DEMs only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
827
diff
changeset
|
96 |
812
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
97 doc.appendChild(meta); |
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
98 |
1442
4a6814be92ba
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1425
diff
changeset
|
99 // Fire. |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
100 HttpClient client = new HttpClientImpl(url, locale); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
101 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
102 try { |
286
0fa8bf8a2295
Datacage: Better converter for incoming XML tree
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
278
diff
changeset
|
103 Converter converter = new Converter(); |
0fa8bf8a2295
Datacage: Better converter for incoming XML tree
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
278
diff
changeset
|
104 return converter.convert(client.callService(url, "metadata", doc)); |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
105 } |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
106 catch (ConnectionException ce) { |
812
70b728a9f4e8
Meta data service: Create correct request document now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
811
diff
changeset
|
107 ce.printStackTrace(); |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
108 } |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
109 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
110 throw new ServerException(ERROR_NO_META_DATA_FOUND); |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |