use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AbstractMusicBrainzClient method executeWSRequest.
protected String executeWSRequest(WebserviceInvocation invocation, String path, List<NameValuePair> params) throws ApplicationException {
String response = null;
HttpGet httpGet = new HttpGet(getURI(path, params));
httpGet.setHeader(USER_AGENT, CLIENT_INFO);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
long elapsedMs = -currentTimeMillis();
response = httpClient.execute(httpGet, responseHandler);
elapsedMs += currentTimeMillis();
sleep(Math.max(INTERVAL_MS - elapsedMs, 0));
} catch (HttpResponseException e) {
LOG.warn(format("MusicBrainz internal error: %d, %s", e.getStatusCode(), e.getMessage()));
throw new ApplicationException("MusicBrainz internal error!", e);
} catch (IOException e) {
throw new ApplicationException("MusicBrainz communication failed!", e);
} catch (InterruptedException e) {
LOG.warn("MusicBrainz sleep interrupted!", e);
}
webserviceHistoryService.logWebserviceInvocation(invocation);
return response;
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AbstractMusicBrainzClient method getURI.
protected URI getURI(String path, List<NameValuePair> params) throws ApplicationException {
URI uri = null;
try {
URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme(HTTP);
uriBuilder.setHost(HOST);
uriBuilder.setPath(path);
for (NameValuePair param : params) {
uriBuilder.addParameter(param.getName(), param.getValue());
}
uri = uriBuilder.build();
} catch (URISyntaxException e) {
throw new ApplicationException("Could not create MusicBrainz URI!", e);
}
return uri;
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class MusicBrainzServiceTest method handlesArtistFailureDuringUpdate.
@Test
public void handlesArtistFailureDuringUpdate() throws ApplicationException {
final String revName = reverse(artistName);
submitFile(additionDao, getFile(revName, albumName, trackName));
Mockito.when(service.artistQueryClient.get(revName)).thenThrow(new ApplicationException("Fail", new HttpResponseException(503, "Overloaded")));
service.updateDiscography();
List<MBAlbum> albums = service.getMissingAlbums(artistName, asList(TYPE_EP), null, -1, 0);
Assert.assertEquals(2, albums.size());
assertEquals("Switchblade / Cult of Luna", albums.get(0).getTitle());
assertEquals("Bodies / Recluse", albums.get(1).getTitle());
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class LibraryScannerService method update.
public void update(Set<String> paths, boolean isRootPaths) throws ApplicationException {
isLibraryBeingScanned = true;
try {
clearImport();
startReceivingServices();
Set<String> rootPaths = getRootPaths(paths);
for (String path : rootPaths) {
Files.walkFileTree(Paths.get(path), new LibraryScanner(libraryPresenceChannel));
}
if (isRootPaths) {
libraryPresenceChannel.send(msg(null, rootPaths, new HashSet<File>()));
}
libraryPresenceChannel.send(FINISHED_MESSAGE);
workerThreads.await();
updateLibrary();
} catch (IOException | InterruptedException e) {
throw new ApplicationException("Scanning aborted due to error!", e);
}
isLibraryBeingScanned = false;
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AbstractWSClient method authenticateParameterList.
protected void authenticateParameterList(List<NameValuePair> params) throws ApplicationException {
Collections.sort(params, paramComparator);
StringBuilder sb = new StringBuilder();
for (NameValuePair param : params) {
sb.append(param.getName()).append(param.getValue());
}
sb.append(API_SEC);
try {
MessageDigest md = MessageDigest.getInstance("md5");
params.add(new BasicNameValuePair(PARAM_API_SIG, new String(encodeHex(md.digest(sb.toString().getBytes(UTF8))))));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ApplicationException("Can not make authenticated call!", e);
}
}
Aggregations