Search in sources :

Example 1 with NotesException

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();
    }
}
Also used : Arrays(java.util.Arrays) XSPErrorPage(com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage) Context(jakarta.ws.rs.core.Context) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) JsonGeneratorFactory(jakarta.json.stream.JsonGeneratorFactory) WebApplicationException(jakarta.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) Response(jakarta.ws.rs.core.Response) Controller(jakarta.mvc.Controller) OutputStreamWriter(java.io.OutputStreamWriter) Priority(jakarta.annotation.Priority) Produces(jakarta.ws.rs.Produces) Request(jakarta.ws.rs.core.Request) Method(java.lang.reflect.Method) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) NotesException(lotus.domino.NotesException) PrintWriter(java.io.PrintWriter) ConstraintViolation(jakarta.validation.ConstraintViolation) NotFoundException(jakarta.ws.rs.NotFoundException) IOException(java.io.IOException) ConstraintViolationException(jakarta.validation.ConstraintViolationException) UriInfo(jakarta.ws.rs.core.UriInfo) JsonGenerator(jakarta.json.stream.JsonGenerator) StandardCharsets(java.nio.charset.StandardCharsets) Json(jakarta.json.Json) Priorities(jakarta.ws.rs.Priorities) Objects(java.util.Objects) List(java.util.List) MediaType(jakarta.ws.rs.core.MediaType) ExceptionMapper(jakarta.ws.rs.ext.ExceptionMapper) ResourceInfo(jakarta.ws.rs.container.ResourceInfo) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Collections(java.util.Collections) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) IOException(java.io.IOException) JsonGeneratorFactory(jakarta.json.stream.JsonGeneratorFactory) ServletException(javax.servlet.ServletException) NotesException(lotus.domino.NotesException) ConstraintViolation(jakarta.validation.ConstraintViolation) MediaType(jakarta.ws.rs.core.MediaType) ConstraintViolationException(jakarta.validation.ConstraintViolationException) JsonGenerator(jakarta.json.stream.JsonGenerator) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(java.util.List) PrintWriter(java.io.PrintWriter)

Example 2 with NotesException

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);
    }
}
Also used : NotesException(lotus.domino.NotesException) Database(lotus.domino.Database) Document(jakarta.nosql.document.Document)

Example 3 with NotesException

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();
    }
}
Also used : NotesException(lotus.domino.NotesException) HealthCheckResponseBuilder(org.eclipse.microprofile.health.HealthCheckResponseBuilder) NoteCollection(lotus.domino.NoteCollection) Database(lotus.domino.Database)

Example 4 with NotesException

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];
}
Also used : NotesException(lotus.domino.NotesException) ACLEntry(lotus.domino.ACLEntry) HttpService(com.ibm.designer.runtime.domino.adapter.HttpService) Database(lotus.domino.Database) ACL(lotus.domino.ACL) Session(lotus.domino.Session)

Example 5 with NotesException

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NotesException(lotus.domino.NotesException) Database(lotus.domino.Database) AdministrationProcess(lotus.domino.AdministrationProcess) ExecutionException(java.util.concurrent.ExecutionException) Session(lotus.domino.Session)

Aggregations

NotesException (lotus.domino.NotesException)105 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)29 ArrayList (java.util.ArrayList)28 List (java.util.List)19 ViewNavigator (org.openntf.domino.ViewNavigator)13 Vector (java.util.Vector)11 Database (lotus.domino.Database)11 Database (org.openntf.domino.Database)10 IOException (java.io.IOException)8 ViewColumn (org.openntf.domino.ViewColumn)8 DocumentCollection (org.openntf.domino.DocumentCollection)7 EmbeddedObject (org.openntf.domino.EmbeddedObject)7 RichTextItem (org.openntf.domino.RichTextItem)7 Session (lotus.domino.Session)6 MIMEEntity (org.openntf.domino.MIMEEntity)5 Date (java.util.Date)4 Document (org.openntf.domino.Document)4 DocumentCollection (lotus.domino.DocumentCollection)3 DominoQuery (lotus.domino.DominoQuery)3 Item (org.openntf.domino.Item)3