Mercurial > dive4elements > http-client
annotate src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java @ 5:7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
http-client/trunk@1430 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 08 Mar 2011 18:23:45 +0000 |
parents | 19b3ba7f2568 |
children | 09a84c6e263a |
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; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import org.apache.log4j.Logger; |
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.restlet.Client; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import org.restlet.Request; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.Response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.data.MediaType; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import org.restlet.data.Method; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import org.restlet.data.Protocol; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import org.restlet.data.Status; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.restlet.ext.xml.DomRepresentation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import org.restlet.representation.Representation; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 import org.w3c.dom.Document; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 /** |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 * @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
|
40 */ |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 public class HttpClientImpl implements HttpClient { |
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 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
|
44 |
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
|
45 /** 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
|
46 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
|
47 |
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
|
48 /** 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
|
49 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
|
50 |
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
|
51 /** 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
|
52 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
|
53 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 private String serverUrl; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 public HttpClientImpl(String serverUrl) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 this.serverUrl = serverUrl; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 public ArtifactFactory[] getArtifactFactories() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 String url = serverUrl + "/factories"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 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
|
71 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 return ArtifactProtocolUtils.extractArtifactFactories(result); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 "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
|
77 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 |
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
|
81 /** |
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
|
82 * 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
|
83 * 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
|
84 * {@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
|
85 * |
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
|
86 * @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
|
87 * @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
|
88 * 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
|
89 * |
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
|
90 * @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
|
91 */ |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 @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
|
93 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
|
94 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
|
95 { |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 ResponseHandler handler = new DocumentResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 String url = serverUrl + "/create"; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 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
|
101 |
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
|
102 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
|
103 ? 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
|
104 : creator.create(result); |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 "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
|
109 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 |
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
|
113 /** |
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
|
114 * This method triggers the artifact servers resource to create a new |
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
|
115 * artifact 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
|
116 * |
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
|
117 * @param create The CREATE document for the 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
|
118 * @param ownerId The uuid of the creator. |
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
|
119 * @param handler The handler that is used to create the result object. |
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
|
120 * |
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
|
121 * @return a result object created by <i>handler</i>. |
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
|
122 */ |
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
|
123 public Object createCollection( |
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
|
124 Document create, |
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
|
125 String ownerId, |
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
|
126 ResponseHandler handler) |
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
|
127 throws ConnectionException |
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
|
128 { |
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
|
129 String url = serverUrl + PATH_CREATE_COLLECTION + "/" + ownerId; |
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
|
130 |
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
|
131 try { |
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
|
132 return handler.handle(doPost(url, create)); |
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
|
133 } |
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
|
134 catch (IOException ioe) { |
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
|
135 throw new ConnectionException(ioe.getMessage(), ioe); |
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
|
136 } |
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
|
137 } |
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
|
138 |
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
|
139 |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 public Object describe( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 ResponseHandler handler) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 throws ConnectionException |
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 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 return handler.handle(doPost(url, doc)); |
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 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 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
|
160 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
163 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 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
|
165 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
168 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 "Connection to server failed: " + ioe.getMessage()); |
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 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
176 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
|
177 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
179 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 String url = serverUrl + "/artifact/" + artifact.getUuid(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 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
|
182 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 return result; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 "Connection to server failed: " + ioe.getMessage()); |
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 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
192 @Override |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 public void out( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 Artifact artifact, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 Document doc, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
196 String target, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 OutputStream out) |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
198 throws ConnectionException |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
199 { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 try { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 String url = |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
202 serverUrl |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
203 + "/artifact/" |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 + artifact.getUuid() |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
205 + "/" + target; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
206 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 ResponseHandler handler = new StreamResponseHandler(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 InputStream stream = (InputStream) handler.handle(doPost(url, doc)); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 byte[] b = new byte[4096]; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 int i = -1; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 while ((i = stream.read(b)) > 0) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 out.write(b, 0, i); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 catch (IOException ioe) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 throw new ConnectionException( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 "Connection to server failed: " + ioe.getMessage()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
221 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 private Response doPost(String url, Document body) throws IOException { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
225 logger.info("Start HTTP-POST request to: "+ url); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 Client client = new Client(Protocol.HTTP); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
228 Request request = new Request(Method.POST, url); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
229 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
230 Representation representation = new DomRepresentation( |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
231 MediaType.APPLICATION_XML, |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
232 body); |
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 request.setEntity(representation); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
236 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
237 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
238 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
239 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 throw new IOException(status.getDescription()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
241 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
242 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
243 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
244 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
245 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
246 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
247 private Response doGet(String url) throws IOException { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
248 logger.info("Start HTTP-POST request to: "+ url); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
249 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
250 Client client = new Client(Protocol.HTTP); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
251 Request request = new Request(Method.GET, url); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
252 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
253 Response response = client.handle(request); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
254 |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
255 Status status = response.getStatus(); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
256 if (status.getCode() != 200) { |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
257 logger.error("Response status: " + status.getCode()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
258 throw new IOException(status.getDescription()); |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 } |
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 return response; |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
262 } |
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
|
263 |
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
|
264 |
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
|
265 /******************************* |
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
|
266 * 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
|
267 *******************************/ |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
268 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
269 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
|
270 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
|
271 { |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
272 logger.info("Start service call to '" + 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
|
273 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
274 DocumentResponseHandler handler = new DocumentResponseHandler(); |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
275 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
276 try { |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
277 String serverUrl = url + 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
|
278 return (Document) handler.handle(doPost(serverUrl, 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
|
279 } |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
280 catch (IOException ioe) { |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
281 throw new 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
|
282 "Connection to server failed: " + ioe.getMessage()); |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
283 } |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
284 } |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
285 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
286 |
7917c21fad01
Enabled the HttpClient to call services that are registered at the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4
diff
changeset
|
287 /******************************* |
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
|
288 * 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
|
289 *******************************/ |
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
|
290 |
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
|
291 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
|
292 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
|
293 { |
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 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
|
295 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
|
296 |
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
|
297 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
|
298 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
|
299 } |
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
|
300 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
|
301 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
|
302 } |
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
|
303 } |
1
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
304 } |
c9ac6642973c
Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
305 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |