use of lotus.domino.NotesException in project org.openntf.xsp.jakartaee by OpenNTF.
the class GenericThrowableMapper method createResponseFromException.
protected Response createResponseFromException(final Throwable throwable, final int status, ResourceInfo resourceInfo, HttpServletRequest req) {
MediaType type = getMediaType(resourceInfo);
if (MediaType.TEXT_HTML_TYPE.isCompatible(type)) {
// Handle as HTML
return Response.status(status).type(MediaType.TEXT_HTML_TYPE).entity((StreamingOutput) out -> {
try (PrintWriter w = new PrintWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8))) {
XSPErrorPage.handleException(w, throwable, req.getRequestURL().toString(), false);
} catch (ServletException e) {
throw new IOException(e);
}
}).build();
} else {
// Handle as JSON
return Response.status(status).type(MediaType.APPLICATION_JSON_TYPE).entity((StreamingOutput) out -> {
Objects.requireNonNull(out);
String message = "";
Throwable t = throwable;
while ((message == null || message.length() == 0) && t != null) {
if (t instanceof NotesException) {
message = ((NotesException) t).text;
} else if (t instanceof ConstraintViolationException) {
message = t.getMessage();
if (message == null || message.isEmpty()) {
List<String> cvMsgList = new ArrayList<>();
for (@SuppressWarnings("rawtypes") ConstraintViolation cv : ((ConstraintViolationException) t).getConstraintViolations()) {
String cvMsg = cv.getPropertyPath() + ": " + cv.getMessage();
cvMsgList.add(cvMsg);
}
message = String.join(",", cvMsgList);
}
} else {
message = t.getMessage();
}
t = t.getCause();
}
JsonGeneratorFactory jsonFac = Json.createGeneratorFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
try (JsonGenerator json = jsonFac.createGenerator(out)) {
json.writeStartObject();
json.write("message", throwable.getClass().getName() + ": " + message);
json.writeKey("stackTrace");
json.writeStartArray();
for (Throwable cause = throwable; cause != null; cause = cause.getCause()) {
json.writeStartArray();
json.write(cause.getClass().getName() + ": " + cause.getLocalizedMessage());
Arrays.stream(cause.getStackTrace()).map(String::valueOf).map(line -> " at " + line).forEach(json::write);
json.writeEnd();
}
json.writeEnd();
json.writeEnd();
}
}).build();
}
}
use of lotus.domino.NotesException in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method update.
@Override
public DocumentEntity update(DocumentEntity entity) {
try {
Database database = supplier.get();
Document id = entity.find(EntityConverter.ID_FIELD).orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("Unable to find {0} in entity", EntityConverter.ID_FIELD)));
lotus.domino.Document target = database.getDocumentByUNID((String) id.get());
EntityConverter.convert(entity, target);
target.save();
return entity;
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
use of lotus.domino.NotesException in project org.openntf.xsp.jakartaee by OpenNTF.
the class PassingHealthCheck method call.
@Override
public HealthCheckResponse call() {
HealthCheckResponseBuilder response = HealthCheckResponse.named("I am the liveliness check");
try {
Database database = NotesContext.getCurrent().getCurrentDatabase();
NoteCollection notes = database.createNoteCollection(true);
notes.buildCollection();
return response.status(true).withData("noteCount", notes.getCount()).build();
} catch (NotesException e) {
return response.status(false).withData("exception", e.text).build();
}
}
use of lotus.domino.NotesException in project org.openntf.xsp.jakartaee by OpenNTF.
the class PostInstallFactory method getServices.
@Override
public HttpService[] getServices(LCDEnvironment env) {
System.out.println("postinstall start");
try {
Session session = NotesFactory.createSession();
try {
for (String nsfName : NSFS) {
Database database = session.getDatabase("", nsfName);
if (database == null || !database.isOpen()) {
throw new RuntimeException("Could not find " + nsfName);
}
ACL acl = database.getACL();
ACLEntry anon = acl.getEntry("Anonymous");
if (anon == null) {
anon = acl.createACLEntry("Anonymous", ACL.LEVEL_AUTHOR);
} else {
anon.setLevel(ACL.LEVEL_AUTHOR);
}
ACLEntry admin = acl.createACLEntry("CN=Jakarta EE Test/O=OpenNTFTest", ACL.LEVEL_MANAGER);
try {
admin.enableRole("[Admin]");
} catch (NotesException e) {
// Failing here is fine, in case the NSF doesn't have the role
}
acl.save();
database.getView("Persons");
session.sendConsoleCommand("", "load updall " + nsfName);
}
session.sendConsoleCommand("", "tell http osgi diag");
} finally {
session.recycle();
}
} catch (NotesException e) {
e.printStackTrace();
} finally {
System.out.println("Done with postinstall");
}
return new HttpService[0];
}
use of lotus.domino.NotesException in project org.openntf.nsfodp by OpenNTF.
the class DeployNSFTask method run.
@Override
public void run() {
try {
Session session = NotesFactory.createSession();
try {
String server, filePath;
// $NON-NLS-1$
int bangIndex = destPath.indexOf("!!");
if (bangIndex > -1) {
server = destPath.substring(0, bangIndex);
filePath = destPath.substring(bangIndex + 2);
} else {
// $NON-NLS-1$
server = "";
filePath = destPath;
}
Database dest = session.getDatabase(server, filePath, true);
if (dest.isOpen() && !replaceDesign) {
throw new IllegalStateException(MessageFormat.format(Messages.DeployNSFTask_dbExists, destPath));
}
if (dest.isOpen()) {
// Then do a replace design
ReplaceDesignTaskLocal task = new ReplaceDesignTaskLocal(filePath, nsfFile, new NullProgressMonitor());
DominoThreadFactory.getExecutor().submit(task).get();
} else {
// $NON-NLS-1$
Database source = session.getDatabase("", nsfFile.toAbsolutePath().toString());
dest = source.createFromTemplate(server, filePath, false);
}
if (this.signDatabase) {
AdministrationProcess adminp = session.createAdministrationProcess(server);
adminp.signDatabaseWithServerID(server, filePath);
// $NON-NLS-1$
session.sendConsoleCommand(server, "tell adminp p im");
}
} finally {
session.recycle();
}
} catch (NotesException | ExecutionException | InterruptedException ne) {
throw new RuntimeException(Messages.DeployNSFTask_exceptionDeploying, ne);
}
}
Aggregations