Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java @ 47:f35b7d7a04d6
Read the Status-Code from the Response and throw an Exception which Message will be visualized in the GUI. gnv/issue18
gnv/trunk@189 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 06 Oct 2009 10:18:57 +0000 |
parents | 23a4f196d7d6 |
children | d6b82c585f1f |
comparison
equal
deleted
inserted
replaced
46:3bbb95f43549 | 47:f35b7d7a04d6 |
---|---|
116 server)); | 116 server)); |
117 } | 117 } |
118 } | 118 } |
119 } catch (IOException e) { | 119 } catch (IOException e) { |
120 log.error(e, e); | 120 log.error(e, e); |
121 throw new ArtifactDatabaseClientException(e); | |
121 } | 122 } |
122 return resultValues; | 123 return resultValues; |
123 } | 124 } |
124 | 125 |
125 private Collection<ArtifactObject> getArtifactFactories(Document document, | 126 private Collection<ArtifactObject> getArtifactFactories(Document document, |
187 * @param requestUrl | 188 * @param requestUrl |
188 * @param requestBody | 189 * @param requestBody |
189 * @return | 190 * @return |
190 */ | 191 */ |
191 private Representation doGetRequestInternal(String requestUrl, | 192 private Representation doGetRequestInternal(String requestUrl, |
192 Document requestBody) { | 193 Document requestBody) throws IOException { |
193 Client client = new Client(Protocol.HTTP); | 194 Client client = new Client(Protocol.HTTP); |
194 Request request = initialize(new Request(Method.GET, requestUrl)); | 195 Request request = initialize(new Request(Method.GET, requestUrl)); |
195 if (requestBody != null) { | 196 if (requestBody != null) { |
196 String documentBody = new XMLUtils() | 197 String documentBody = new XMLUtils() |
197 .writeDocument2String(requestBody); | 198 .writeDocument2String(requestBody); |
198 Representation representation = new StringRepresentation( | 199 Representation representation = new StringRepresentation( |
199 documentBody); | 200 documentBody); |
200 request.setEntity(representation); | 201 request.setEntity(representation); |
201 } | 202 } |
202 Response response = client.handle(request); | 203 Response response = client.handle(request); |
203 // TODO RESPONSESTATUS AUSWERTEN. | 204 if (response.getStatus().getCode() != 200){ |
205 throw new IOException(response.getStatus().getDescription()); | |
206 } | |
204 Representation output = response.getEntity(); | 207 Representation output = response.getEntity(); |
205 return output; | 208 return output; |
206 } | 209 } |
207 | 210 |
208 /** | 211 /** |
217 Request request = initialize(new Request(Method.POST, requestUrl)); | 220 Request request = initialize(new Request(Method.POST, requestUrl)); |
218 String documentBody = new XMLUtils().writeDocument2String(requestBody); | 221 String documentBody = new XMLUtils().writeDocument2String(requestBody); |
219 Representation representation = new StringRepresentation(documentBody); | 222 Representation representation = new StringRepresentation(documentBody); |
220 request.setEntity(representation); | 223 request.setEntity(representation); |
221 Response response = client.handle(request); | 224 Response response = client.handle(request); |
225 if (response.getStatus().getCode() != 200){ | |
226 throw new IOException(response.getStatus().getDescription()); | |
227 } | |
222 // TODO RESPONSESTATUS AUSWERTEN. | 228 // TODO RESPONSESTATUS AUSWERTEN. |
223 Representation output = response.getEntity(); | 229 Representation output = response.getEntity(); |
224 return output.getStream(); | 230 return output.getStream(); |
225 } | 231 } |
226 | 232 |