Mercurial > dive4elements > http-client
annotate src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java @ 30:7687e5cee1c3 2.6 2.6.1 pre2.7-2012-03-16
Tagged RELEASE 0.5 of http-client.
http-client/trunk@2787 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Sep 2011 14:38:23 +0000 |
parents | c4431f39926a |
children | 875a5c409560 |
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 */ |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.artifacts.httpclient.http; |
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; |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
13 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
|
14 import java.util.List; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import org.apache.log4j.Logger; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.Client; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.Request; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 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
|
21 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
|
22 import org.restlet.data.Language; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.restlet.data.MediaType; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 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
|
25 import org.restlet.data.Preference; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 import org.restlet.data.Protocol; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import org.restlet.data.Status; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 import org.restlet.ext.xml.DomRepresentation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 import org.restlet.representation.Representation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 import org.w3c.dom.Document; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 import de.intevation.artifacts.httpclient.http.response.ResponseHandler; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 import de.intevation.artifacts.httpclient.objects.Artifact; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 import de.intevation.artifacts.httpclient.objects.ArtifactFactory; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils; |
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
|
40 import de.intevation.artifacts.httpclient.utils.ArtifactCreator; |
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
|
41 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 /** |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 * @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
|
45 */ |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 public class HttpClientImpl implements HttpClient { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 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
|
49 |
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
|
50 /** 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
|
51 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
|
52 |
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
|
53 /** 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
|
54 * 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
|
55 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
|
56 |
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
|
57 /** 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
|
58 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
|
59 |
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
|
60 /** 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
|
61 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
|
62 |
6
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
63 /** 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
|
64 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
|
65 |
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
|
66 /** 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
|
67 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
|
68 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 private String serverUrl; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
71 private String localeString; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
72 |
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
|
73 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
|
74 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
|
75 @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
|
76 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
|
77 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
|
78 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
|
79 } |
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
|
80 }; |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 public HttpClientImpl(String serverUrl) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 this.serverUrl = serverUrl; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
87 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
88 * 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
|
89 * 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
|
90 * 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
|
91 * 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
|
92 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
93 * @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
|
94 * @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
|
95 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
96 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
|
97 this(serverUrl); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
98 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
99 this.localeString = localeString; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
100 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
101 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
102 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 public ArtifactFactory[] getArtifactFactories() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 String url = serverUrl + "/factories"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 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
|
112 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 return ArtifactProtocolUtils.extractArtifactFactories(result); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 "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
|
118 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 |
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
|
122 /** |
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
|
123 * 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
|
124 * 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
|
125 * {@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
|
126 * |
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
|
127 * @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
|
128 * @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
|
129 * 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
|
130 * |
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
|
131 * @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
|
132 */ |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 @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
|
134 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
|
135 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
|
136 { |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 String url = serverUrl + "/create"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 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
|
142 |
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
|
143 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
|
144 ? 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
|
145 : creator.create(result); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 "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
|
150 } |
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 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 public Object describe( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 ResponseHandler handler) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
163 return handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
165 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
168 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 |
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 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 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
|
174 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
176 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
177 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 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
|
179 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
182 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 "Connection to server failed: " + ioe.getMessage()); |
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 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 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
|
191 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
192 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 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
|
196 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
198 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
199 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 "Connection to server failed: " + ioe.getMessage()); |
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 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
206 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 public void out( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 String target, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 OutputStream out) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 String url = |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 serverUrl |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 + "/artifact/" |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 + artifact.getUuid() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 + "/" + target; |
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 ResponseHandler handler = new StreamResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 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
|
224 try { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
225 byte[] b = new byte[4096]; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
226 int i; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
227 while ((i = stream.read(b)) >= 0) { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
228 out.write(b, 0, i); |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
229 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
230 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
231 finally { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
232 stream.close(); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
233 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
234 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
236 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
237 "Connection to server failed: " + ioe.getMessage()); |
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 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
241 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
242 //============================== |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
243 // HTTP specific methods |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
244 //============================== |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
245 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
250 |
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
|
251 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
|
252 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
|
253 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
254 Representation representation = new DomRepresentation( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
255 MediaType.APPLICATION_XML, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
256 body); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
257 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
258 request.setEntity(representation); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
260 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
261 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
262 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
263 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
264 throw new IOException(status.getDescription()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
265 } |
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 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
268 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
269 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
270 |
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
|
271 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
|
272 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
|
273 } |
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
|
274 |
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
|
275 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
280 |
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
|
281 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
|
282 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
|
283 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
284 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
285 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
286 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
287 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
288 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
289 throw new IOException(status.getDescription()); |
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 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
292 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
293 } |
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
|
294 |
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
|
295 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
296 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
297 * 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
|
298 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
299 * @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
|
300 * @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
|
301 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
302 * @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
|
303 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
304 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
|
305 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
|
306 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
307 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
|
308 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
309 setLocale(info); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
310 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
311 request.setClientInfo(info); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
312 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
313 return request; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
314 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
315 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
316 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
317 /** |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
318 * 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
|
319 * |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
320 * @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
|
321 */ |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
322 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
|
323 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
|
324 return; |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
325 } |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
326 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
327 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
|
328 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
|
329 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
330 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
|
331 |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 "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
|
336 } |
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
|
337 |
10
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
338 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
|
339 pref.setMetadata(lang); |
e79283dad6f2
Added the option to set the request's locale manually.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
9
diff
changeset
|
340 accepted.add(pref); |
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 info.setAcceptedLanguages(accepted); |
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 } |
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 |
6
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
347 //============================== |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
348 // 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
|
349 //============================== |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
350 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
351 /** |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
352 * 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
|
353 * 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
|
354 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
355 * @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
|
356 * @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
|
357 * @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
|
358 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
359 * @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
|
360 */ |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
367 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
|
368 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
369 try { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
370 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
|
371 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
372 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
|
373 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
|
374 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
375 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
376 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
377 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
378 /** |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
379 * 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
|
380 * 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
|
381 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
382 * @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
|
383 * @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
|
384 * @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
|
385 * |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
386 * @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
|
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 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
|
389 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
|
390 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
|
391 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
|
392 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
|
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 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
|
395 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
396 try { |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
397 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
|
398 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
399 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
|
400 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
|
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 } |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
403 |
09a84c6e263a
Enhanced the HttpClient with a method sto trigger a collection specific action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
5
diff
changeset
|
404 |
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
|
405 /** |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
406 * This method triggers the out() operation of a Collection. The result of |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
407 * this operation is written to <i>out</i> directly - there is no return |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
408 * value. |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
409 * |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
410 * @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
|
411 * @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
|
412 * @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
|
413 * @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
|
414 */ |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 { |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
422 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
|
423 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
|
424 |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
425 byte[] b = new byte[4096]; |
17
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
426 try { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
427 int i; |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
428 while ((i = stream.read(b)) >= 0) { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
429 out.write(b, 0, i); |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
430 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
431 } |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
432 finally { |
5cb8513b9e78
Improved the stream handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
433 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
|
434 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
435 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
436 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
|
437 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
|
438 } |
072e8d488f83
Enhanced the HttpClient with a method to trigger the out() operation of Collections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
7
diff
changeset
|
439 } |
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 |
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
|
442 /** |
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
|
443 * 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
|
444 * 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
|
445 * |
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
|
446 * @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
|
447 * @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
|
448 * @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
|
449 * |
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
|
450 * @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
|
451 */ |
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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 { |
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
|
458 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
|
459 |
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
|
460 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
|
461 |
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
|
462 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
|
463 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
|
464 } |
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
|
465 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
|
466 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
|
467 } |
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
|
468 } |
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
|
469 |
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
|
470 |
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
|
471 /******************************* |
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
|
472 * 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
|
473 *******************************/ |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
474 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
475 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
|
476 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
|
477 { |
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
|
478 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
|
479 |
26
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
480 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
|
481 } |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
482 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
483 |
26
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
484 public Object callService( |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
485 String url, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
486 String service, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
487 Document input, |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
488 ResponseHandler handler) |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
489 throws ConnectionException { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
490 if (logger.isDebugEnabled()) { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
491 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
|
492 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
493 |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
494 try { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
495 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
|
496 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
|
497 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
498 catch (IOException ioe) { |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
499 throw new ConnectionException( |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
500 "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
|
501 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
502 } |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
503 |
c4431f39926a
New method to call a service with a ResponseHandler.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
21
diff
changeset
|
504 |
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
|
505 /******************************* |
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
|
506 * 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
|
507 *******************************/ |
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
|
508 |
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
|
509 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
|
510 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
|
511 { |
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
|
512 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
|
513 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
|
514 |
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
|
515 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
|
516 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
|
517 } |
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
|
518 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
|
519 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
|
520 } |
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
|
521 } |
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
|
522 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
523 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
524 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
|
525 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
|
526 { |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
527 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
|
528 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
529 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
|
530 |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
531 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
|
532 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
|
533 } |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
534 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
|
535 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
|
536 } |
06e9e25632cd
Added a method to the HttpClient to list the collection of a user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
6
diff
changeset
|
537 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
538 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
539 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |