use of com.yahoo.elide.core.exceptions.BadRequestException in project elide by yahoo.
the class SubscriptionWebSocketTest method testErrorInStream.
@Test
void testErrorInStream() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
Book book1 = new Book();
book1.setTitle("Book 1");
book1.setId(1);
Book book2 = new Book();
book2.setTitle("Book 2");
book2.setId(2);
reset(dataStoreTransaction);
when(dataStoreTransaction.getAttribute(any(), any(), any())).thenThrow(new BadRequestException("Bad Request"));
when(dataStoreTransaction.loadObjects(any(), any())).thenReturn(new DataStoreIterableBuilder(List.of(book1, book2)).build());
ConnectionInit init = new ConnectionInit();
endpoint.onOpen(session);
endpoint.onMessage(session, mapper.writeValueAsString(init));
Subscribe subscribe = Subscribe.builder().id("1").payload(Subscribe.Payload.builder().query("subscription {book(topic: ADDED) {id title}}").build()).build();
endpoint.onMessage(session, mapper.writeValueAsString(subscribe));
List<String> expected = List.of("{\"type\":\"connection_ack\"}", "{\"type\":\"next\",\"id\":\"1\",\"payload\":{\"data\":{\"book\":{\"id\":\"1\",\"title\":null}},\"errors\":[{\"message\":\"Exception while fetching data (/book/title) : Bad Request\",\"locations\":[{\"line\":1,\"column\":38}],\"path\":[\"book\",\"title\"],\"extensions\":{\"classification\":\"DataFetchingException\"}}]}}", "{\"type\":\"next\",\"id\":\"1\",\"payload\":{\"data\":{\"book\":{\"id\":\"2\",\"title\":null}},\"errors\":[{\"message\":\"Exception while fetching data (/book/title) : Bad Request\",\"locations\":[{\"line\":1,\"column\":38}],\"path\":[\"book\",\"title\"],\"extensions\":{\"classification\":\"DataFetchingException\"}}]}}", "{\"type\":\"complete\",\"id\":\"1\"}");
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
verify(remote, times(4)).sendText(message.capture());
assertEquals(expected, message.getAllValues());
}
use of com.yahoo.elide.core.exceptions.BadRequestException in project elide by yahoo.
the class ConfigFile method fromId.
public static String fromId(String id) {
String idString;
try {
idString = URLDecoder.decode(id, "UTF-8");
idString = new String(Base64.getDecoder().decode(idString.getBytes()));
} catch (IllegalArgumentException | UnsupportedEncodingException e) {
throw new BadRequestException("Invalid ID: " + id);
}
int hyphenIndex = idString.lastIndexOf(".hjson-");
String path;
if (hyphenIndex < 0) {
path = idString;
} else {
path = idString.substring(0, idString.lastIndexOf('-'));
}
return path;
}
use of com.yahoo.elide.core.exceptions.BadRequestException in project elide by yahoo.
the class FilterPredicateTest method parse.
private Map<String, Set<FilterPredicate>> parse(MultivaluedMap<String, String> queryParams) {
PredicateExtractionVisitor visitor = new PredicateExtractionVisitor();
Map<String, FilterExpression> expressionMap;
try {
expressionMap = strategy.parseTypedExpression("/book", queryParams, NO_VERSION);
} catch (ParseException e) {
throw new BadRequestException(e.getMessage());
}
Map<String, Set<FilterPredicate>> returnMap = new HashMap<>();
for (Map.Entry<String, FilterExpression> entry : expressionMap.entrySet()) {
String typeName = entry.getKey();
FilterExpression expression = entry.getValue();
if (!returnMap.containsKey(typeName)) {
returnMap.put(typeName, new HashSet<>());
}
returnMap.get(typeName).addAll(expression.accept(visitor));
}
return returnMap;
}
use of com.yahoo.elide.core.exceptions.BadRequestException in project elide by yahoo.
the class JSONAPITableExportOperation method getRequestScope.
@Override
public RequestScope getRequestScope(TableExport export, RequestScope scope, DataStoreTransaction tx, Map<String, List<String>> additionalRequestHeaders) {
UUID requestId = UUID.fromString(export.getRequestId());
User user = scope.getUser();
String apiVersion = scope.getApiVersion();
URIBuilder uri;
try {
uri = new URIBuilder(export.getQuery());
} catch (URISyntaxException e) {
throw new BadRequestException(e.getMessage());
}
MultivaluedMap<String, String> queryParams = JSONAPIAsyncQueryOperation.getQueryParams(uri);
// Call with additionalHeader alone
if (scope.getRequestHeaders().isEmpty()) {
return new RequestScope("", JSONAPIAsyncQueryOperation.getPath(uri), apiVersion, null, tx, user, queryParams, additionalRequestHeaders, requestId, getService().getElide().getElideSettings());
}
// Combine additionalRequestHeaders and existing scope's request headers
Map<String, List<String>> finalRequestHeaders = new HashMap<String, List<String>>();
scope.getRequestHeaders().forEach((entry, value) -> finalRequestHeaders.put(entry, value));
// additionalRequestHeaders will override any headers in scope.getRequestHeaders()
additionalRequestHeaders.forEach((entry, value) -> finalRequestHeaders.put(entry, value));
return new RequestScope("", JSONAPIAsyncQueryOperation.getPath(uri), apiVersion, null, tx, user, queryParams, scope.getRequestHeaders(), requestId, getService().getElide().getElideSettings());
}
use of com.yahoo.elide.core.exceptions.BadRequestException in project elide by yahoo.
the class JSONAPITableExportOperation method getProjections.
@Override
public Collection<EntityProjection> getProjections(TableExport export, RequestScope scope) {
EntityProjection projection = null;
try {
URIBuilder uri = new URIBuilder(export.getQuery());
Elide elide = getService().getElide();
projection = new EntityProjectionMaker(elide.getElideSettings().getDictionary(), scope).parsePath(JSONAPIAsyncQueryOperation.getPath(uri));
} catch (URISyntaxException e) {
throw new BadRequestException(e.getMessage());
}
return Collections.singletonList(projection);
}
Aggregations