@@ -132,19 +132,19 @@ private URI uri(String path) {
132132 }
133133 }
134134
135- private <T > T get (String path , Class <T > type ) throws ParseException , IOException {
135+ private <T > T get (String path , Class <T > type ) throws IOException {
136136 return get (path , SimpleType .constructUnsafe (type ));
137137 }
138138
139- private <T > T get (String path , JavaType type ) throws ParseException , IOException {
139+ private <T > T get (String path , JavaType type ) throws IOException {
140140 return read (header (new HttpGet (uri (path ))), type , HttpStatus .SC_OK );
141141 }
142142
143- private <T > T delete (String path , Class <T > type ) throws ParseException , IOException {
143+ private <T > T delete (String path , Class <T > type ) throws IOException {
144144 return delete (path , SimpleType .constructUnsafe (type ));
145145 }
146146
147- private <T > T delete (String path , JavaType type ) throws ParseException , IOException {
147+ private <T > T delete (String path , JavaType type ) throws IOException {
148148 return read (header (new HttpDelete (uri (path ))), type , HttpStatus .SC_OK );
149149 }
150150
@@ -153,19 +153,19 @@ private ClassicHttpRequest header(ClassicHttpRequest request) {
153153 return request ;
154154 }
155155
156- private <T > T post (String path , Object request , Class <T > responseType ) throws ParseException , IOException {
156+ private <T > T post (String path , Object request , Class <T > responseType ) throws IOException {
157157 return post (path , request , SimpleType .constructUnsafe (responseType ));
158158 }
159159
160- private <T > T post (String path , Object request , JavaType responseType ) throws ParseException , IOException {
160+ private <T > T post (String path , Object request , JavaType responseType ) throws IOException {
161161 HttpPost post = new HttpPost (uri (path ));
162162 String json = objectMapper .writeValueAsString (request );
163163 log .debug ("POST {}" , json );
164164 post .setEntity (new StringEntity (json ));
165165 return read (header (post ), responseType , HttpStatus .SC_OK );
166166 }
167167
168- private <T > T read (ClassicHttpRequest request , JavaType type , int successCode ) throws IOException , ParseException {
168+ private <T > T read (ClassicHttpRequest request , JavaType type , int successCode ) throws IOException {
169169 HttpHost target = new HttpHost (protocol , host , port );
170170 HttpClientContext localContext = HttpClientContext .create ();
171171 if (credentials != null ) {
@@ -174,19 +174,33 @@ private <T> T read(ClassicHttpRequest request, JavaType type, int successCode) t
174174 localContext .resetAuthExchange (target , basicAuth );
175175 }
176176 CloseableHttpResponse response = client .execute (request , localContext );
177- String json = EntityUtils .toString (response .getEntity ());
177+ String json ;
178+ try {
179+ json = EntityUtils .toString (response .getEntity ());
180+ } catch (ParseException e ) {
181+ throw new HttpResponseParsingException ("Could not parse response" , e );
182+ }
178183 if (response .getCode () == successCode ) {
179184 return objectMapper .readValue (json , type );
180185 }
181186 throw new HttpResponseException (response .getCode (), response .getReasonPhrase () + " " + json );
182187 }
183188
184- public List <InstalledModule > getModules () throws ParseException , IOException {
189+ private static class HttpResponseParsingException extends IOException {
190+
191+ private static final long serialVersionUID = 1L ;
192+
193+ public HttpResponseParsingException (String message , Throwable cause ) {
194+ super (message , cause );
195+ }
196+ }
197+
198+ public List <InstalledModule > getModules () throws IOException {
185199 return get (v1 (MODULES ),
186200 objectMapper .getTypeFactory ().constructCollectionType (List .class , InstalledModule .class ));
187201 }
188202
189- public Database createDatabase (Database database ) throws ParseException , IOException {
203+ public Database createDatabase (Database database ) throws IOException {
190204 Map <String , InstalledModule > installedModules = new HashMap <>();
191205 for (InstalledModule module : getModules ()) {
192206 installedModules .put (module .getName (), module );
@@ -212,7 +226,7 @@ public Database createDatabase(Database database) throws ParseException, IOExcep
212226 return response ;
213227 }
214228
215- public List <Database > getDatabases () throws ParseException , IOException {
229+ public List <Database > getDatabases () throws IOException {
216230 return get (v1 (BDBS ), objectMapper .getTypeFactory ().constructCollectionType (List .class , Database .class ));
217231 }
218232
@@ -231,8 +245,7 @@ public void deleteDatabase(long uid) {
231245 });
232246 }
233247
234- public ModuleInstallResponse installModule (String filename , InputStream inputStream )
235- throws ParseException , IOException {
248+ public ModuleInstallResponse installModule (String filename , InputStream inputStream ) throws IOException {
236249 HttpPost post = new HttpPost (uri (v2 (MODULES )));
237250 MultipartEntityBuilder builder = MultipartEntityBuilder .create ();
238251 builder .setMode (HttpMultipartMode .STRICT );
@@ -261,15 +274,15 @@ public void waitForBoostrap() {
261274
262275 }
263276
264- private Bootstrap getBootstrap () throws ParseException , IOException {
277+ private Bootstrap getBootstrap () throws IOException {
265278 return get (v1 (BOOTSTRAP ), Bootstrap .class );
266279 }
267280
268- private Action getAction (String uid ) throws ParseException , IOException {
281+ private Action getAction (String uid ) throws IOException {
269282 return get (v1 (ACTIONS , uid ), Action .class );
270283 }
271284
272- public CommandResponse executeCommand (long bdb , Command command ) throws ParseException , IOException {
285+ public CommandResponse executeCommand (long bdb , Command command ) throws IOException {
273286 return post (v1 (BDBS , String .valueOf (bdb ), COMMAND ), command , CommandResponse .class );
274287 }
275288
0 commit comments