Mercurial > dive4elements > http-client
comparison src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java @ 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.
http-client/trunk@1325 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Feb 2011 11:19:02 +0000 |
parents | c9ac6642973c |
children | 19a617578b88 |
comparison
equal
deleted
inserted
replaced
1:c9ac6642973c | 2:2fdfa20cfa63 |
---|---|
30 import de.intevation.artifacts.httpclient.http.response.ResponseHandler; | 30 import de.intevation.artifacts.httpclient.http.response.ResponseHandler; |
31 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; | 31 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; |
32 import de.intevation.artifacts.httpclient.objects.Artifact; | 32 import de.intevation.artifacts.httpclient.objects.Artifact; |
33 import de.intevation.artifacts.httpclient.objects.ArtifactFactory; | 33 import de.intevation.artifacts.httpclient.objects.ArtifactFactory; |
34 import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils; | 34 import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils; |
35 import de.intevation.artifacts.httpclient.utils.XMLUtils; | 35 import de.intevation.artifacts.httpclient.utils.ArtifactCreator; |
36 | |
36 | 37 |
37 /** | 38 /** |
38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 39 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
39 */ | 40 */ |
40 public class HttpClientImpl implements HttpClient { | 41 public class HttpClientImpl implements HttpClient { |
66 "Connection to server failed. No Factories recieved."); | 67 "Connection to server failed. No Factories recieved."); |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 | 71 |
71 @Override | 72 /** |
72 public Artifact create(Document doc) throws ConnectionException { | 73 * This method creates a new artifact in the artifact server and returns |
74 * this artifact. The new artifact is created using <i>creator</i>. If no | |
75 * {@link ArtifactCreator} is given (null), an {@link Artifact} is returned. | |
76 * | |
77 * @param doc The CREATE document. | |
78 * @param creator The {@link ArtifactCreator} that is used to extract the | |
79 * new artifact from response document of the server. | |
80 * | |
81 * @return the new artifact. | |
82 */ | |
83 @Override | |
84 public Object create(Document doc, ArtifactCreator creator) | |
85 throws ConnectionException | |
86 { | |
73 ResponseHandler handler = new DocumentResponseHandler(); | 87 ResponseHandler handler = new DocumentResponseHandler(); |
74 | 88 |
75 try { | 89 try { |
76 String url = serverUrl + "/create"; | 90 String url = serverUrl + "/create"; |
77 Document result = (Document) handler.handle(doPost(url, doc)); | 91 Document result = (Document) handler.handle(doPost(url, doc)); |
78 | 92 |
79 return ArtifactProtocolUtils.extractArtifact(result); | 93 return creator == null |
94 ? ArtifactProtocolUtils.extractArtifact(result) | |
95 : creator.create(result); | |
80 } | 96 } |
81 catch (IOException ioe) { | 97 catch (IOException ioe) { |
82 throw new ConnectionException( | 98 throw new ConnectionException( |
83 "Connection to server failed. No Artifact created."); | 99 "Connection to server failed. No Artifact created."); |
84 } | 100 } |