use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method validateSearchParams.
private void validateSearchParams(Map<String, List<String>> queryMap) {
List<String> rowsList = queryMap.get("rows");
if (rowsList != null && !rowsList.isEmpty()) {
try {
String rowsString = rowsList.get(0);
int rows = Integer.valueOf(rowsString);
if (rows < 0 || rows > OrcidSearchManager.MAX_SEARCH_ROWS) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception", OrcidSearchManager.MAX_SEARCH_ROWS));
}
} catch (NumberFormatException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception"));
}
} else {
// Set the default number of results
queryMap.put("rows", Arrays.asList(String.valueOf(OrcidSearchManager.DEFAULT_SEARCH_ROWS)));
}
}
use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class OrcidApiServiceDelegatorImpl method validateStart.
private void validateStart(Map<String, List<String>> queryMap) {
String clientId = orcidSecurityManager.getClientIdFromAPIRequest();
if (clientId == null) {
// only validate start param where no client credentials
List<String> startList = queryMap.get("start");
if (startList != null && !startList.isEmpty()) {
try {
String startString = startList.get(0);
int start = Integer.valueOf(startString);
if (start < 0 || start > OrcidSearchManager.MAX_SEARCH_START) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
}
} catch (NumberFormatException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
}
}
}
}
use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method apiDefaultVersionTest.
@Test
public void apiDefaultVersionTest() {
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/0000-0001-7510-9252/activities");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
}
use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class ApiVersionCheckFilterTest method invalidWebhooksShouldNotWork.
@Test
public void invalidWebhooksShouldNotWork() {
WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
URI requestUri = URI.create("http://localhost:8443/orcid-api-web/0000-0001-7510-9252/webhook/");
InBoundHeaders headers = new InBoundHeaders();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
try {
ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
filter.filter(containerRequest);
fail();
} catch (OrcidBadRequestException e) {
} catch (Exception e) {
fail();
}
}
use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorImpl method validateStart.
private void validateStart(Map<String, List<String>> queryMap) {
String clientId = orcidSecurityManager.getClientIdFromAPIRequest();
if (clientId == null) {
// only validate start param where no client credentials
List<String> startList = queryMap.get("start");
if (startList != null && !startList.isEmpty()) {
try {
String startString = startList.get(0);
int start = Integer.valueOf(startString);
if (start < 0 || start > OrcidSearchManager.MAX_SEARCH_START) {
throw new SearchStartParameterLimitExceededException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
}
} catch (NumberFormatException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
}
}
}
}
Aggregations