Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/server/auth/UserClient.java @ 5861:172338b1407f
GWT client: Added copyright header.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 14:30:15 +0200 |
parents | 5aa05a7a34b7 |
children | ea9eef426962 |
rev | line source |
---|---|
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
9 package org.dive4elements.river.client.server.auth; |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 import javax.xml.xpath.XPathConstants; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import org.w3c.dom.Document; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 import org.w3c.dom.Element; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 import org.w3c.dom.Node; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 import org.w3c.dom.NodeList; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
19 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
20 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
21 import org.dive4elements.artifacts.common.utils.XMLUtils; |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
23 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
24 import org.dive4elements.artifacts.httpclient.http.HttpClient; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
25 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 /** |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 * UserClient is a class to allow easier communication |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 * with the REST based artifact user protocol |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 */ |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 public class UserClient { |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 private static final Logger logger = Logger.getLogger(UserClient.class); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 private String url; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 public UserClient(String url) { |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 this.url = url; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 } |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 public boolean userExists(User user) throws ConnectionException { |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
42 if (user == null) { |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 return false; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 } |
3695
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
45 |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
46 Element data = this.findUser(user); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
47 |
3524
2c306a3dacef
Use xml namespace for XPath query to get the accout name attribute.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3507
diff
changeset
|
48 String XPATH_USERACCOUNT = "/art:user/art:account/@art:name"; |
3505
637d114232b2
Don't use XPath Query to get attribute of a XML Node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
2984
diff
changeset
|
49 |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
50 String account = XMLUtils.xpathString( |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
51 data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
52 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
53 if (account == null) { |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
54 return false; |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 } |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
56 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
57 return account.equals(user.getAccount()); |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 } |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
59 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 public boolean createUser(User user) throws ConnectionException { |
3696 | 61 if(user == null) { |
62 logger.warn("createUser: given user is null"); | |
63 return false; | |
64 } | |
3697
2e12518ff5b4
Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3696
diff
changeset
|
65 |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
66 logger.debug("Creating new user " + user.getName()); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 HttpClient client = new HttpClientImpl(this.url); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 Document document = XMLUtils.newDocument(); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
71 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 document, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 ArtifactNamespaceContext.NAMESPACE_URI, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
74 ArtifactNamespaceContext.NAMESPACE_PREFIX |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 ); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
76 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 Element action = creator.create("action"); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
78 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 Element type = creator.create("type"); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 type.setAttribute("name", "create"); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 Element artuser = creator.create("user"); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
82 artuser.setAttribute("name", user.getName()); |
3506
f2a4e6e92ffd
Send account data to artifact rest interface to create a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3505
diff
changeset
|
83 Element account = creator.create("account"); |
f2a4e6e92ffd
Send account data to artifact rest interface to create a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3505
diff
changeset
|
84 account.setAttribute("name", user.getAccount()); |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
85 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
86 //TODO create roles |
3506
f2a4e6e92ffd
Send account data to artifact rest interface to create a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3505
diff
changeset
|
87 artuser.appendChild(account); |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
88 action.appendChild(type); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
89 action.appendChild(artuser); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
90 document.appendChild(action); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
91 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
92 logger.debug("Create user request xml: " + XMLUtils.toString(document)); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
93 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
94 Document resp = client.createUser(document); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
95 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
96 logger.debug("Create user response xml: " + XMLUtils.toString(resp)); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
97 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
98 String XPATH_RESPONSE = "/art:result"; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
99 Node nresult = (Node) XMLUtils.xpath( |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
100 resp, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
101 XPATH_RESPONSE, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
102 XPathConstants.NODE, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
103 ArtifactNamespaceContext.INSTANCE); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
104 String result = nresult.getTextContent(); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
105 return (result != null && result.equalsIgnoreCase("success")); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
106 } |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
107 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
108 public NodeList listUsers() throws ConnectionException { |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
109 HttpClient client = new HttpClientImpl(this.url); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
110 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
111 Document users = (Document) client.listUsers(); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
112 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
113 String XPATH_USERS = "/art:users/art:user"; |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
114 |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
115 return (NodeList) XMLUtils.xpath( |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
116 users, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
117 XPATH_USERS, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
118 XPathConstants.NODESET, |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
119 ArtifactNamespaceContext.INSTANCE); |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
120 } |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
121 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
122 public Element findUser(User user) throws ConnectionException { |
3696 | 123 if(user == null) { |
124 throw new IllegalArgumentException("user is null"); | |
125 } | |
3697
2e12518ff5b4
Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3696
diff
changeset
|
126 |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
127 HttpClient client = new HttpClientImpl(this.url); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
128 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
129 Document document = XMLUtils.newDocument(); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
130 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
131 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
132 document, |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
133 ArtifactNamespaceContext.NAMESPACE_URI, |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
134 ArtifactNamespaceContext.NAMESPACE_PREFIX |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
135 ); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
136 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
137 Element action = creator.create("action"); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
138 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
139 Element type = creator.create("type"); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
140 type.setAttribute("name", "find"); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
141 Element account = creator.create("account"); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
142 account.setAttribute("name", user.getAccount()); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
143 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
144 action.appendChild(type); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
145 action.appendChild(account); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
146 document.appendChild(action); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
147 |
3695
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
148 boolean debug = logger.isDebugEnabled(); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
149 |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
150 if (debug) { |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
151 logger.debug("Find user request xml: " + |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
152 XMLUtils.toString(document)); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
153 } |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
154 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
155 Document resp = client.findUser(document); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
156 |
3695
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
157 if (debug) { |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
158 logger.debug("Find user request response xml: " + |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
159 XMLUtils.toString(resp)); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3524
diff
changeset
|
160 } |
3507
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
161 |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
162 return resp.getDocumentElement(); |
59c77a9551c8
User new find-user REST service in UserClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3506
diff
changeset
|
163 } |
2984
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
164 } |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
165 // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80: |
06d999e95615
Add UserClient class to handle REST communication for user related interfaces.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
166 |