Mercurial > dive4elements > http-client
annotate src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java @ 92:fcbfc6c597b1
Renamed setEncoding to setOutEncoding.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 25 Sep 2013 10:38:54 +0200 |
parents | 8bd13f10d555 |
children | 30b7ca3951c7 |
rev | line source |
---|---|
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 /* |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 * |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 */ |
72
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
8 package org.dive4elements.artifacts.httpclient.http; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import java.io.InputStream; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.io.IOException; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import java.io.OutputStream; |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
13 import java.io.OutputStreamWriter; |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
14 |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
15 import java.nio.charset.Charset; |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
16 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
17 import java.util.ArrayList; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
18 import java.util.List; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import org.apache.log4j.Logger; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import org.restlet.Client; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.restlet.Request; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import org.restlet.Response; |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
25 import org.restlet.data.ClientInfo; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
26 import org.restlet.data.Language; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import org.restlet.data.MediaType; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 import org.restlet.data.Method; |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
29 import org.restlet.data.Preference; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 import org.restlet.data.Protocol; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 import org.restlet.data.Status; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 import org.restlet.ext.xml.DomRepresentation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 import org.restlet.representation.Representation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 import org.w3c.dom.Document; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
72
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
37 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
38 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
39 import org.dive4elements.artifacts.httpclient.http.response.ResponseHandler; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
40 import org.dive4elements.artifacts.httpclient.http.response.StreamResponseHandler; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
41 import org.dive4elements.artifacts.httpclient.objects.Artifact; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
42 import org.dive4elements.artifacts.httpclient.objects.ArtifactFactory; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
43 import org.dive4elements.artifacts.httpclient.utils.ArtifactProtocolUtils; |
133281653904
Renamed internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
71
diff
changeset
|
44 import org.dive4elements.artifacts.httpclient.utils.ArtifactCreator; |
2
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
45 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 /** |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
48 * Client to artifact-server. |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 */ |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 public class HttpClientImpl implements HttpClient { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 private static final Logger logger = Logger.getLogger(HttpClient.class); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
4
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
55 /** The URL part of the resource to list the existing users of the server.*/ |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
56 public static final String PATH_LIST_USERS = "/list-users"; |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
57 |
7
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
58 /** The URL part of the resource to list the Collections owned by a specific |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
59 * user.*/ |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
60 public static final String PATH_USER_COLLECTIONS = "/list-collections"; |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
61 |
34
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
62 /** The URL part og the resource to create a new user on the server.*/ |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
63 public static final String PATH_CREATE_USER = "/create-user"; |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
64 |
37
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
65 /** The URL part og the resource to find an existing user on the server.*/ |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
66 public static final String PATH_FIND_USER = "/find-user"; |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
67 |
5
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
68 /** The URL part of the resource to call a specific service.*/ |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
69 public static final String PATH_SERVICE = "/service"; |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
70 |
3
19a617578b88
Added a new method to the HttpClient that triggers the creation of a new artifact collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2
diff
changeset
|
71 /** The URL path of the resource to create new artifact collections.*/ |
19a617578b88
Added a new method to the HttpClient that triggers the creation of a new artifact collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2
diff
changeset
|
72 public static final String PATH_CREATE_COLLECTION = "/create-collection"; |
19a617578b88
Added a new method to the HttpClient that triggers the creation of a new artifact collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2
diff
changeset
|
73 |
6
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
74 /** The URL path of the resource to work with an artifact collections.*/ |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
75 public static final String PATH_ACTION_COLLECTION = "/collection"; |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
76 |
9
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
77 /** The URL path of the resource to work with an artifact collections.*/ |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
78 public static final String PATH_OUT_COLLECTION = "/collection"; |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
79 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 private String serverUrl; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
82 private String localeString; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
83 |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
84 /** |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
85 * The Charset used for encoding the collectionOut output. |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
86 * If not set, the system/java default will be used (UTF-8). |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
87 */ |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
88 private Charset charset; |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
89 |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
90 private static final ThreadLocal<Client> CLIENT = |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
91 new ThreadLocal<Client>() { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
92 @Override |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
93 protected Client initialValue() { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
94 logger.debug("create new HTTP client"); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
95 return new Client(Protocol.HTTP); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
96 } |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
97 }; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 public HttpClientImpl(String serverUrl) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 this.serverUrl = serverUrl; |
92
fcbfc6c597b1
Renamed setEncoding to setOutEncoding.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
90
diff
changeset
|
101 setOutEncoding(null); |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
102 } |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
103 |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
104 |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
105 /** |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
106 * Sets the encoding. |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
107 * |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
108 * Currently the encoding is only |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
109 * respected in the collectionOut-method! |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
110 * |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
111 * It was implemented to allow csv export to be in another than the |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
112 * sensible default (UTF-8) and allow easier integration |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
113 * e.g. in proprietary products. |
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
114 */ |
92
fcbfc6c597b1
Renamed setEncoding to setOutEncoding.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
90
diff
changeset
|
115 public void setOutEncoding(Charset charset) { |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
116 this.charset = charset; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
120 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
121 * This constructor might be used to modify the request's locale manually. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
122 * E.g. the localization should not be based on the configured browser |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
123 * locale, but site specific configuration - than you are able to set the |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
124 * locale in this constructor. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
125 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
126 * @param serverUrl The url that is used for the request. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
127 * @param localeString The string representation of the desired locale. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
128 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
129 public HttpClientImpl(String serverUrl, String localeString) { |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
130 this(serverUrl); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
131 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
132 this.localeString = localeString; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
133 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
134 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
135 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 public ArtifactFactory[] getArtifactFactories() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 String url = serverUrl + "/factories"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 Document result = (Document) handler.handle(doGet(url)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 return ArtifactProtocolUtils.extractArtifactFactories(result); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 "Connection to server failed. No Factories recieved."); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 |
2
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
155 /** |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
156 * This method creates a new artifact in the artifact server and returns |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
157 * this artifact. The new artifact is created using <i>creator</i>. If no |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
158 * {@link ArtifactCreator} is given (null), an {@link Artifact} is returned. |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
159 * |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
160 * @param doc The CREATE document. |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
161 * @param creator The {@link ArtifactCreator} that is used to extract the |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
162 * new artifact from response document of the server. |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
163 * |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
164 * @return the new artifact. |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
165 */ |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 @Override |
2
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
167 public Object create(Document doc, ArtifactCreator creator) |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
168 throws ConnectionException |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
169 { |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 String url = serverUrl + "/create"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 Document result = (Document) handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 |
2
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
176 return creator == null |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
177 ? ArtifactProtocolUtils.extractArtifact(result) |
2fdfa20cfa63
Added an interface that is used to create instances of artifacts depending on the framework that includes this lib. The create() method of the HttpClient makes use of this interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1
diff
changeset
|
178 : creator.create(result); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
179 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
182 "Connection to server failed. No Artifact created."); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 public Object describe( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 ResponseHandler handler) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
192 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
196 return handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
198 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
199 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
202 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
203 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
205 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
206 public Object feed(Artifact artifact, Document doc, ResponseHandler handler) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 Document result = (Document) handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
221 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 public Object advance(Artifact artifact, Document doc, ResponseHandler handler) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
225 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
228 Document result = (Document) handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
229 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
230 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
231 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
232 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
233 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
234 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
236 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
237 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
238 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
239 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 public void out( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
241 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
242 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
243 String target, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
244 OutputStream out) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
245 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
246 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
247 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
248 String url = |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
249 serverUrl |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
250 + "/artifact/" |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
251 + artifact.getUuid() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
252 + "/" + target; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
253 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
254 ResponseHandler handler = new StreamResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
255 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
256 InputStream stream = (InputStream) handler.handle(doPost(url, doc)); |
17
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
257 try { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
258 byte[] b = new byte[4096]; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
259 int i; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
260 while ((i = stream.read(b)) >= 0) { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
261 out.write(b, 0, i); |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
262 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
263 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
264 finally { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
265 stream.close(); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
266 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
267 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
268 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
269 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
270 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
271 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
272 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
273 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
274 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
275 //============================== |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
276 // HTTP specific methods |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
277 //============================== |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
278 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
279 private Response doPost(String url, Document body) throws IOException { |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
280 if (logger.isDebugEnabled()) { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
281 logger.debug("Start HTTP-POST request to: " + url); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
282 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
283 |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
284 Client client = getClient(); |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
285 Request request = prepareRequest(Method.POST, url); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
286 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
287 Representation representation = new DomRepresentation( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
288 MediaType.APPLICATION_XML, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
289 body); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
290 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
291 request.setEntity(representation); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
292 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
293 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
294 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
295 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
296 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
297 throw new IOException(status.getDescription()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
298 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
299 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
300 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
301 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
302 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
303 |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
304 private static Client getClient() { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
305 return CLIENT.get(); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
306 } |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
307 |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
308 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
309 private Response doGet(String url) throws IOException { |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
310 if (logger.isDebugEnabled()) { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
311 logger.debug("Start HTTP-POST request to: "+ url); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
312 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
313 |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
314 Client client = getClient(); |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
315 Request request = prepareRequest(Method.GET, url); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
316 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
317 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
318 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
319 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
320 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
321 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
322 throw new IOException(status.getDescription()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
323 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
324 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
325 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
326 } |
4
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
327 |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
328 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
329 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
330 * This method prepares the request object. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
331 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
332 * @param method The HTTP method (GET,POST). |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
333 * @param url The URL used for the request. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
334 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
335 * @return the request object. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
336 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
337 private Request prepareRequest(Method method, String url) { |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
338 Request request = new Request(method, url); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
339 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
340 ClientInfo info = request.getClientInfo(); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
341 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
342 setLocale(info); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
343 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
344 request.setClientInfo(info); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
345 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
346 return request; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
347 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
348 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
349 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
350 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
351 * This method is called to set the request's locale. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
352 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
353 * @param info The ClientInfo that is used to provide request information. |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
354 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
355 private void setLocale(ClientInfo info) { |
11
ea8b7e244e61
Bugfix: repaired a condition that prevented setting the locale of the request object.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
10
diff
changeset
|
356 if (localeString == null) { |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
357 return; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
358 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
359 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
360 List<Preference<Language>> accepted = |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
361 new ArrayList<Preference<Language>>(); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
362 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
363 Language lang = Language.valueOf(localeString); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
364 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
365 if (lang != null) { |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
366 if (logger.isDebugEnabled()) { |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
367 logger.debug( |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
368 "Set locale of the request object: " + lang.toString()); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
369 } |
11
ea8b7e244e61
Bugfix: repaired a condition that prevented setting the locale of the request object.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
10
diff
changeset
|
370 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
371 Preference<Language> pref = new Preference<Language>(); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
372 pref.setMetadata(lang); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
373 accepted.add(pref); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
374 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
375 info.setAcceptedLanguages(accepted); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
376 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
377 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
378 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
379 |
6
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
380 //============================== |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
381 // Collection API |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
382 //============================== |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
383 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
384 /** |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
385 * This method triggers the artifact servers resource to create a new |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
386 * artifact collection. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
387 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
388 * @param create The CREATE document for the collection. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
389 * @param ownerId The uuid of the creator. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
390 * @param handler The handler that is used to create the result object. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
391 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
392 * @return a result object created by <i>handler</i>. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
393 */ |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
394 public Object createCollection( |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
395 Document create, |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
396 String ownerId, |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
397 ResponseHandler handler) |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
398 throws ConnectionException |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
399 { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
400 String url = serverUrl + PATH_CREATE_COLLECTION + "/" + ownerId; |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
401 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
402 try { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
403 return handler.handle(doPost(url, create)); |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
404 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
405 catch (IOException ioe) { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
406 throw new ConnectionException(ioe.getMessage(), ioe); |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
407 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
408 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
409 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
410 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
411 /** |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
412 * This method might be used to trigger a collection specific action. The |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
413 * action that is executed depends on the document <i>actionDoc</i>. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
414 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
415 * @param actionDoc The document that describes the action to be executed. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
416 * @param uuid The uuid of the collection. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
417 * @param handler The handler that is used to create the result object. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
418 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
419 * @return a result object created by <i>handler</i>. |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
420 */ |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
421 public Object doCollectionAction( |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
422 Document actionDoc, |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
423 String uuid, |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
424 ResponseHandler handler) |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
425 throws ConnectionException |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
426 { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
427 String url = serverUrl + PATH_ACTION_COLLECTION + "/" + uuid; |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
428 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
429 try { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
430 return handler.handle(doPost(url, actionDoc)); |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
431 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
432 catch (IOException ioe) { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
433 throw new ConnectionException(ioe.getMessage(), ioe); |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
434 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
435 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
436 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
437 |
9
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
438 /** |
90
8bd13f10d555
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
72
diff
changeset
|
439 * Write out() operation of a Collection to <i>out</i>. |
9
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
440 * |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
441 * @param doc The request document for the out() operation. |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
442 * @param uuid The identifier of the Collection. |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
443 * @param type The name of the output type. |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
444 * @param out The OutputStream. |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
445 */ |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
446 public void collectionOut( |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
447 Document doc, |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
448 String uuid, |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
449 String type, |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
450 OutputStream out) |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
451 throws ConnectionException |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
452 { |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
453 try { |
12
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
454 InputStream stream = collectionOut(doc, uuid, type); |
9
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
455 |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
456 byte[] b = new byte[4096]; |
17
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
457 try { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
458 int i; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
459 while ((i = stream.read(b)) >= 0) { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
460 out.write(b, 0, i); |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
461 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
462 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
463 finally { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
464 stream.close(); |
9
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
465 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
466 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
467 catch (IOException ioe) { |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
468 throw new ConnectionException(ioe.getMessage(), ioe); |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
469 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
470 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
471 |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
472 |
12
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
473 /** |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
474 * This method triggers the out() operation of a Collection. The result of |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
475 * this operation is returned as an InputStream. |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
476 * |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
477 * @param doc The request document for the out() operation. |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
478 * @param uuid The identifier of the Collection. |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
479 * @param type The name of the output type. |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
480 * |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
481 * @return an InputStream. |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
482 */ |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
483 public InputStream collectionOut( |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
484 Document doc, |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
485 String uuid, |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
486 String type) |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
487 throws ConnectionException |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
488 { |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
489 String url = serverUrl + PATH_OUT_COLLECTION + "/" + uuid + "/" + type; |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
490 |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
491 ResponseHandler handler = new StreamResponseHandler(); |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
492 |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
493 try { |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
494 return (InputStream) handler.handle(doPost(url, doc)); |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
495 } |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
496 catch (IOException ioe) { |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
497 throw new ConnectionException(ioe.getMessage(), ioe); |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
498 } |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
499 } |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
500 |
5b62267a1c3c
The HttpClient got a new method that returns the InputStream of a Collection's OUT operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
11
diff
changeset
|
501 |
4
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
502 /******************************* |
5
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
503 * Service API |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
504 *******************************/ |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
505 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
506 public Document callService(String url, String service, Document input) |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
507 throws ConnectionException |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
508 { |
21
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
509 DocumentResponseHandler handler = new DocumentResponseHandler(); |
79a5a2455d6d
Use Apache HTTP Client as the underlaying transport agent. Use thread local instances to re-use agents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
510 |
26
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
511 return (Document) callService(url, service, input, handler); |
5
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
512 } |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
513 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
514 |
26
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
515 public Object callService( |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
516 String url, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
517 String service, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
518 Document input, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
519 ResponseHandler handler) |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
520 throws ConnectionException { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
521 if (logger.isDebugEnabled()) { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
522 logger.debug("Start service call to '" + service + "'"); |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
523 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
524 |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
525 try { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
526 String serverUrl = url + PATH_SERVICE + "/" + service; |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
527 return handler.handle(doPost(serverUrl, input)); |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
528 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
529 catch (IOException ioe) { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
530 throw new ConnectionException( |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
531 "Connection to server failed: " + ioe.getMessage()); |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
532 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
533 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
534 |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
535 |
5
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
536 /******************************* |
4
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
537 * Users API |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
538 *******************************/ |
5
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
539 |
4
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
540 public Document listUsers() |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
541 throws ConnectionException |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
542 { |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
543 ResponseHandler handler = new DocumentResponseHandler(); |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
544 String url = serverUrl + PATH_LIST_USERS; |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
545 |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
546 try { |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
547 return (Document) handler.handle(doGet(url)); |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
548 } |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
549 catch (IOException ioe) { |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
550 throw new ConnectionException(ioe.getMessage(), ioe); |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
551 } |
19b3ba7f2568
Added a method to the http client to list the existing users of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3
diff
changeset
|
552 } |
7
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
553 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
554 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
555 public Document listUserCollections(String userid) |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
556 throws ConnectionException |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
557 { |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
558 ResponseHandler handler = new DocumentResponseHandler(); |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
559 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
560 String url = serverUrl + PATH_USER_COLLECTIONS + "/" + userid; |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
561 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
562 try { |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
563 return (Document) handler.handle(doGet(url)); |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
564 } |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
565 catch (IOException ioe) { |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
566 throw new ConnectionException(ioe.getMessage(), ioe); |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
567 } |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
568 } |
34
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
569 |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
570 @Override |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
571 public Document createUser(Document doc) |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
572 throws ConnectionException { |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
573 ResponseHandler handler = new DocumentResponseHandler(); |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
574 |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
575 String url = this.serverUrl + PATH_CREATE_USER; |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
576 |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
577 try { |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
578 return (Document) handler.handle(doPost(url, doc)); |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
579 } |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
580 catch (IOException ioe) { |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
581 throw new ConnectionException( |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
582 "Connection to server failed: " + ioe.getMessage()); |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
583 } |
875a5c409560
Implemented a createUser method for HttpClient.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
26
diff
changeset
|
584 } |
37
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
585 |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
586 @Override |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
587 public Document findUser(Document doc) |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
588 throws ConnectionException { |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
589 ResponseHandler handler = new DocumentResponseHandler(); |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
590 |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
591 String url = this.serverUrl + PATH_FIND_USER; |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
592 |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
593 try { |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
594 return (Document) handler.handle(doPost(url, doc)); |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
595 } |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
596 catch (IOException ioe) { |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
597 throw new ConnectionException( |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
598 "Connection to server failed: " + ioe.getMessage()); |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
599 } |
874c25363dc9
Added new method findUser to HttpClient
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
34
diff
changeset
|
600 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
601 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
602 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |