use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIController method read.
/**
* Get an individual remote API's page
*
* @param apiId
* The ID of the api
* @param model
* Model for the view
* @param locale
* the locale specified by the browser.
* @return The name of the remote api details page view
*/
@RequestMapping("/{apiId}")
public String read(@PathVariable Long apiId, Model model, Locale locale) {
RemoteAPI remoteApi = remoteAPIService.read(apiId);
model.addAttribute("remoteApi", remoteApi);
try {
RemoteAPIToken token = tokenService.getToken(remoteApi);
model.addAttribute("tokenExpiry", dateTimeFormatter.print(token.getExpiryDate(), locale));
} catch (EntityNotFoundException ex) {
// Not returning a token here is acceptable. The view will have to
// handle a state if the token does not exist
logger.trace("No token for service " + remoteApi);
}
return DETAILS_PAGE;
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OAuthTokenRestTemplateIT method testRequestWithBadToken.
@Test(expected = IridaOAuthException.class)
public void testRequestWithBadToken() throws URISyntaxException {
RemoteAPI remoteAPI = apiService.read(1L);
URI serviceURI = new URI(remoteAPI.getServiceURI());
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo(serviceURI)).andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
restTemplate.getForEntity(serviceURI, String.class);
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OAuthTokenRestTemplateIT method testOAuthRequest.
@Test
public void testOAuthRequest() throws URISyntaxException {
RemoteAPI remoteAPI = apiService.read(1L);
URI serviceURI = new URI(remoteAPI.getServiceURI());
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
String responseMessage = "{ \"message\" : \"all good\" }";
mockServer.expect(requestTo(serviceURI)).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(responseMessage, MediaType.APPLICATION_JSON));
ResponseEntity<String> forEntity = restTemplate.getForEntity(serviceURI, String.class);
assertNotNull(forEntity);
assertEquals(responseMessage, forEntity.getBody());
mockServer.verify();
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OAuthTokenRestTemplateIT method testRequestWithNoToken.
@Test(expected = IridaOAuthException.class)
public void testRequestWithNoToken() throws URISyntaxException {
RemoteAPI remoteAPI = apiService.read(3L);
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
URI serviceURI = new URI(remoteAPI.getServiceURI());
restTemplate.getForEntity(serviceURI, String.class);
}
Aggregations