use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigChangeActionsSlimeConverterTest method toJson.
private static String toJson(ConfigChangeActions actions) throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
new ConfigChangeActionsSlimeConverter(actions).toSlime(root);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
new JsonFormat(false).encode(outputStream, slime);
return outputStream.toString();
}
use of com.yahoo.slime.Slime 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));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class Dispatcher method toSlime.
private static Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) {
Slime slime = new Slime();
Cursor root = slime.setObject();
if (summaryClass != null) {
root.setString("class", summaryClass);
}
if (sessionId != null) {
root.setData("sessionid", sessionId.asUtf8String().getBytes());
}
if (docType != null) {
root.setString("doctype", docType);
}
if (rankProfile != null) {
root.setString("ranking", rankProfile);
}
Cursor gids = root.setArray("gids");
for (FastHit hit : hits) {
gids.addData(hit.getGlobalId().getRawId());
}
return slime;
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ProjectBundleClassPaths method save.
static void save(OutputStream out, ProjectBundleClassPaths mappings) throws IOException {
Slime slime = new Slime();
Cursor rootCursor = slime.setObject();
Cursor mainBundleCursor = rootCursor.setObject("mainBundle");
BundleClasspathMapping.save(mainBundleCursor, mappings.mainBundle);
Cursor dependenciesCursor = rootCursor.setArray("providedDependencies");
mappings.providedDependencies.forEach(d -> BundleClasspathMapping.save(dependenciesCursor.addObject(), d));
new JsonFormat(false).encode(out, slime);
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ProjectBundleClassPaths method load.
static ProjectBundleClassPaths load(byte[] bytes) {
Slime slime = new Slime();
new JsonDecoder().decode(slime, bytes);
Inspector inspector = slime.get();
BundleClasspathMapping mainBundle = BundleClasspathMapping.load(inspector.field("mainBundle"));
Inspector dependenciesInspector = inspector.field("providedDependencies");
List<BundleClasspathMapping> providedDependencies = new ArrayList<>();
for (int i = 0; i < dependenciesInspector.entries(); i++) {
providedDependencies.add(BundleClasspathMapping.load(dependenciesInspector.entry(i)));
}
return new ProjectBundleClassPaths(mainBundle, providedDependencies);
}
Aggregations