use of javax.json.JsonObject in project sling by apache.
the class JSONRecordingTest method logsWithCaller.
@Test
public void logsWithCaller() throws Exception {
StringWriter sw = new StringWriter();
final JSONRecording r = new JSONRecording("abc", request, true);
TracerConfig config = new TracerConfig(TracerContext.QUERY_LOGGER, Level.INFO, new CallerStackReporter(20));
r.log(config, Level.INFO, "foo", tuple("foo"));
r.done();
r.render(sw);
JsonObject json = Json.createReader(new StringReader(sw.toString())).readObject();
JsonObject l1 = json.getJsonArray("logs").getJsonObject(0);
assertTrue(l1.containsKey("caller"));
assertTrue(l1.getJsonArray("caller").size() > 0);
}
use of javax.json.JsonObject in project sling by apache.
the class JSONRecordingTest method logQueries.
@Test
public void logQueries() throws Exception {
StringWriter sw = new StringWriter();
when(request.getMethod()).thenReturn("GET");
JSONRecording r = new JSONRecording("abc", request, true);
MDC.put(MDC_QUERY_ID, "1");
r.log(tc, Level.DEBUG, "org.apache.jackrabbit.oak.query.QueryEngineImpl", tuple("Parsing {} statement: {}", "XPATH", "SELECT FOO"));
r.log(tc, Level.DEBUG, QE_LOGGER, tuple("query plan FOO PLAN"));
r.done();
r.render(sw);
JsonObject json = Json.createReader(new StringReader(sw.toString())).readObject();
assertEquals("GET", json.getString("method"));
assertTrue(json.containsKey("time"));
assertTrue(json.containsKey("timestamp"));
assertEquals(1, json.getJsonArray("queries").size());
}
use of javax.json.JsonObject in project sling by apache.
the class LogTracerTest method recordingWithoutTracing.
@Test
public void recordingWithoutTracing() throws Exception {
activateTracerAndServlet();
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.bundleContext()) {
@Override
public RequestProgressTracker getRequestProgressTracker() {
return createTracker("x", "y");
}
@Override
public String getRequestURI() {
return "foo";
}
};
request.setHeader(TracerLogServlet.HEADER_TRACER_RECORDING, "true");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
//No TurboFilter should be registered if tracing is not requested
assertNull(context.getService(TurboFilter.class));
}
};
prepareChain(chain).doFilter(request, response);
String requestId = getRequestId(response);
assertNotNull(requestId);
Recording r = ((TracerLogServlet) context.getService(Servlet.class)).getRecording(requestId);
assertTrue(r instanceof JSONRecording);
JSONRecording jr = (JSONRecording) r;
StringWriter sw = new StringWriter();
jr.render(sw);
JsonObject json = Json.createReader(new StringReader(sw.toString())).readObject();
assertEquals(2, json.getJsonArray("requestProgressLogs").size());
}
use of javax.json.JsonObject in project sling by apache.
the class TracerLogServletTest method gzipResponse.
@Test
public void gzipResponse() throws Exception {
TracerLogServlet logServlet = new TracerLogServlet(context.bundleContext());
when(request.getMethod()).thenReturn("GET");
when(request.getHeader(TracerLogServlet.HEADER_TRACER_RECORDING)).thenReturn("true");
when(request.getHeader("Accept-Encoding")).thenReturn("gzip, deflate");
Recording recording = logServlet.startRecording(request, response);
recording.registerTracker(createTracker("x", "y"));
logServlet.endRecording(request, recording);
ArgumentCaptor<String> requestIdCaptor = ArgumentCaptor.forClass(String.class);
verify(response).setHeader(eq(TracerLogServlet.HEADER_TRACER_REQUEST_ID), requestIdCaptor.capture());
verify(response).setHeader(TracerLogServlet.HEADER_TRACER_PROTOCOL_VERSION, String.valueOf(TracerLogServlet.TRACER_PROTOCOL_VERSION));
ByteArrayServletOutputStream sos = new ByteArrayServletOutputStream();
when(response.getOutputStream()).thenReturn(sos);
when(request.getRequestURI()).thenReturn("/system/console/" + requestIdCaptor.getValue() + ".json");
logServlet.renderContent(request, response);
byte[] data = IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(sos.baos.toByteArray())));
JsonObject json = Json.createReader(new StringReader(new String(data, "UTF-8"))).readObject();
assertEquals("GET", json.getString("method"));
assertEquals(2, json.getJsonArray("requestProgressLogs").size());
verify(response).setHeader("Content-Encoding", "gzip");
}
use of javax.json.JsonObject in project sling by apache.
the class FsMountHelper method getCurrentConfigurations.
/**
* Return all file provider configs for this project
* @param targetUrl The targetUrl of the webconsole
* @return A map (may be empty) with the pids as keys and the configurations as values
* @throws MojoExecutionException
*/
public Map<String, FsResourceConfiguration> getCurrentConfigurations(final String targetUrl) throws MojoExecutionException {
log.debug("Getting current file provider configurations.");
final Map<String, FsResourceConfiguration> result = new HashMap<>();
final String getUrl = targetUrl + "/configMgr/(service.factoryPid=" + FS_FACTORY + ").json";
final GetMethod get = new GetMethod(getUrl);
try {
final int status = httpClient.executeMethod(get);
if (status == 200) {
String contentType = get.getResponseHeader(HEADER_CONTENT_TYPE).getValue();
int pos = contentType.indexOf(';');
if (pos != -1) {
contentType = contentType.substring(0, pos);
}
if (!JsonSupport.JSON_MIME_TYPE.equals(contentType)) {
log.debug("Response type from web console is not JSON, but " + contentType);
throw new MojoExecutionException("The Apache Felix Web Console is too old to mount " + "the initial content through file system provider configs. " + "Either upgrade the web console or disable this feature.");
}
final String jsonText;
try (InputStream jsonResponse = get.getResponseBodyAsStream()) {
jsonText = IOUtils.toString(jsonResponse, CharEncoding.UTF_8);
}
try {
JsonArray array = JsonSupport.parseArray(jsonText);
for (int i = 0; i < array.size(); i++) {
final JsonObject obj = array.getJsonObject(i);
final String pid = obj.getString("pid");
final JsonObject properties = obj.getJsonObject("properties");
final String fsmode = getConfigPropertyValue(properties, PROPERTY_FSMODE);
final String path = getConfigPropertyValue(properties, PROPERTY_PATH);
final String initialContentImportOptions = getConfigPropertyValue(properties, PROPERTY_INITIAL_CONTENT_IMPORT_OPTIONS);
final String fileVaultFilterXml = getConfigPropertyValue(properties, PROPERTY_FILEVAULT_FILTER_XML);
String root = getConfigPropertyValue(properties, PROPERTY_ROOTS);
if (root == null) {
root = getConfigPropertyValue(properties, PROPERTY_ROOT);
}
if (path != null && path.startsWith(this.project.getBasedir().getAbsolutePath()) && root != null) {
FsResourceConfiguration cfg = new FsResourceConfiguration().fsMode(fsmode).providerRootPath(path).contentRootDir(root).initialContentImportOptions(initialContentImportOptions).fileVaultFilterXml(fileVaultFilterXml);
log.debug("Found configuration with pid: " + pid + ", " + cfg);
result.put(pid, cfg);
}
}
} catch (JsonException ex) {
throw new MojoExecutionException("Reading configuration from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
}
}
} catch (HttpException ex) {
throw new MojoExecutionException("Reading configuration from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new MojoExecutionException("Reading configuration from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
} finally {
get.releaseConnection();
}
return result;
}
Aggregations