use of com.yahoo.slime.JsonDecoder in project vespa by vespa-engine.
the class JRTConfigRequestBase method error_response_adds_common_elements.
@Test
public void error_response_adds_common_elements() {
serverReq.addErrorResponse(ErrorCode.APPLICATION_NOT_LOADED, ErrorCode.getName(ErrorCode.APPLICATION_NOT_LOADED));
assertThat(serverReq.getRequest().returnValues().size(), is(1));
Slime data = new JsonDecoder().decode(new Slime(), Utf8.toBytes(serverReq.getRequest().returnValues().get(0).asString()));
Inspector response = data.get();
assertThat(response.field(SlimeResponseData.RESPONSE_DEF_NAME).asString(), is(defName));
assertThat(response.field(SlimeResponseData.RESPONSE_DEF_NAMESPACE).asString(), is(defNamespace));
assertThat(response.field(SlimeResponseData.RESPONSE_DEF_MD5).asString(), is(defMd5));
assertThat(response.field(SlimeResponseData.RESPONSE_CONFIGID).asString(), is(configId));
assertThat(response.field(SlimeResponseData.RESPONSE_CLIENT_HOSTNAME).asString(), is(hostname));
Trace t = Trace.fromSlime(response.field(SlimeResponseData.RESPONSE_TRACE));
assertThat(t.toString(), is(trace.toString()));
}
use of com.yahoo.slime.JsonDecoder in project vespa by vespa-engine.
the class ConfigVerification method listConfigs.
private static Map<String, Stack<String>> listConfigs(List<String> urls) throws IOException {
Map<String, String> outputs = performRequests(urls);
Map<String, Stack<String>> recurseMappings = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : outputs.entrySet()) {
Slime slime = new JsonDecoder().decode(new Slime(), Utf8.toBytes(entry.getValue()));
final List<String> list = new ArrayList<>();
slime.get().field("configs").traverse(new ArrayTraverser() {
@Override
public void entry(int idx, Inspector inspector) {
list.add(inspector.asString());
}
});
Stack<String> stack = new Stack<>();
Collections.sort(list);
stack.addAll(list);
recurseMappings.put(entry.getKey(), stack);
}
return recurseMappings;
}
use of com.yahoo.slime.JsonDecoder in project vespa by vespa-engine.
the class SessionPrepareHandlerTest method getData.
private Slime getData(HttpResponse response) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.render(baos);
Slime data = new Slime();
new JsonDecoder().decode(data, baos.toByteArray());
return data;
}
use of com.yahoo.slime.JsonDecoder in project vespa by vespa-engine.
the class JSONString method inspect.
public Inspector inspect() {
if (value == null) {
JsonDecoder decoder = new JsonDecoder();
Slime slime = decoder.decode(new Slime(), Utf8.toBytes(content));
if (slime.get().field("error_message").valid() && slime.get().field("partial_result").valid() && slime.get().field("offending_input").valid()) {
// probably a json parse error...
value = new Value.StringValue(content);
} else if (slime.get().type() == com.yahoo.slime.Type.OBJECT || slime.get().type() == com.yahoo.slime.Type.ARRAY) {
// valid json object or array
value = new SlimeAdapter(slime.get());
} else {
// 'valid' json, but leaf value
value = new Value.StringValue(content);
}
}
return value;
}
use of com.yahoo.slime.JsonDecoder in project vespa by vespa-engine.
the class HttpHandlerTest method testResponse.
@Test
public void testResponse() throws IOException {
final String message = "failed";
HttpHandler httpHandler = new HttpTestHandler(new InvalidApplicationException(message));
HttpResponse response = httpHandler.handle(HttpRequest.createTestRequest("foo", com.yahoo.jdisc.http.HttpRequest.Method.GET));
assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.render(baos);
Slime data = new Slime();
new JsonDecoder().decode(data, baos.toByteArray());
assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.INVALID_APPLICATION_PACKAGE.name()));
assertThat(data.get().field("message").asString(), is(message));
}
Aggregations