use of org.apache.sling.models.factory.MissingExporterException in project sling by apache.
the class ExportServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Map<String, String> options = createOptionMap(request);
ScriptHelper scriptHelper = new ScriptHelper(bundleContext, null, request, response);
try {
addScriptBindings(scriptHelper, request, response);
String exported;
try {
exported = accessor.getExportedString(request, options, modelFactory, exporterName);
} catch (ExportException e) {
logger.error("Could not perform export with " + exporterName + " requested by model.", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
} catch (MissingExporterException e) {
logger.error("Could not get exporter " + exporterName + " requested by model.", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
if (exported == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
response.setContentType(request.getResponseContentType());
response.getWriter().write(exported);
} finally {
scriptHelper.cleanup();
}
}
use of org.apache.sling.models.factory.MissingExporterException in project sling by apache.
the class ExporterTest method testFailedExport.
@Test
public void testFailedExport() throws Exception {
boolean thrown = false;
try {
ResourceResolver resolver = null;
try {
resolver = rrFactory.getAdministrativeResourceResolver(null);
final Resource baseComponentResource = resolver.getResource(baseComponentPath);
Assert.assertNotNull(baseComponentResource);
String data = modelFactory.exportModelForResource(baseComponentResource, "jaxb", String.class, Collections.<String, String>emptyMap());
Assert.fail("Should have thrown missing serializer error.");
} finally {
if (resolver != null && resolver.isLive()) {
resolver.close();
}
}
} catch (MissingExporterException e) {
thrown = true;
Assert.assertEquals("No exporter named jaxb supports java.lang.String.", e.getMessage());
}
Assert.assertTrue(thrown);
}
Aggregations