Search in sources :

Example 1 with CmisNotSupportedException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException in project copper-cms by PogeyanOSS.

the class AkkaCmisBrowserBindingServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        final ActorSystem system = (ActorSystem) request.getServletContext().getAttribute("ActorSystem");
        // CSRF token check
        String method = request.getMethod();
        if (!METHOD_GET.equals(method) && !METHOD_HEAD.equals(method)) {
            checkCsrfToken(request, response, false, false);
        }
        // set default headers
        response.addHeader("Cache-Control", "private, max-age=0");
        response.addHeader("Server", ServerVersion.OPENCMIS_SERVER);
        // split path
        String[] pathFragments = HttpUtils.splitPath(request);
        final AsyncContext ctx = request.startAsync(request, response);
        if (Helpers.isPerfMode()) {
            MetricsInputs.get().getCounter("counter_requests_total").inc();
        }
        if (pathFragments != null && pathFragments.length > 0 && StringUtils.isBlank(pathFragments[0])) {
            BaseMessage bm = gettingBaseMessage(method, pathFragments, null, request, response);
            if (bm != null) {
                // create actor on-the-fly
                ActorRef servletActor = system.actorOf(Props.create(ServletActor.class, ctx));
                servletActor.tell(bm, ActorRef.noSender());
            } else {
                throw new CmisNotSupportedException("Unsupported method");
            }
        } else {
            this.verifyLogin(request, pathFragments, system, (s) -> {
                try {
                    IUserObject loginSession = (IUserObject) s;
                    BaseMessage bm = gettingBaseMessage(method, pathFragments, loginSession, request, response);
                    if (bm != null) {
                        // create actor on-the-fly
                        ActorRef servletActor = system.actorOf(Props.create(ServletActor.class, ctx));
                        servletActor.tell(bm, ActorRef.noSender());
                    } else {
                        throw new CmisNotSupportedException("Unsupported method");
                    }
                } catch (Exception e1) {
                    MetricsInputs.markBindingServletErrorMeter();
                    LOG.error("Service execution exception: {}, stack: {}", e1.getMessage(), ExceptionUtils.getStackTrace(e1));
                    ServletHelpers.printError(e1, request, response);
                }
            }, (err) -> {
                HttpServletResponse asyncResponse = (HttpServletResponse) ctx.getResponse();
                asyncResponse.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
                try {
                    asyncResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
                } catch (Exception e1) {
                    MetricsInputs.markBindingServletErrorMeter();
                    ServletHelpers.printError(e1, (HttpServletRequest) ctx.getRequest(), asyncResponse);
                }
                ctx.complete();
            });
        }
    } catch (Exception e) {
        MetricsInputs.markBindingServletErrorMeter();
        if (e instanceof CmisUnauthorizedException) {
            response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
        } else if (e instanceof CmisPermissionDeniedException) {
            response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
        } else {
            ServletHelpers.printError(e, request, response);
        }
    } finally {
    // in any case close the content stream if one has been provided
    // if (request instanceof POSTHttpServletRequestWrapper) {
    // InputStream stream = ((POSTHttpServletRequestWrapper)
    // request).getStream();
    // if (stream != null) {
    // try {
    // stream.close();
    // } catch (IOException e) {
    // LOG.error("Could not close POST stream: {}", e.toString(), e);
    // }
    // }
    // }
    // // we are done.
    // try {
    // response.flushBuffer();
    // } catch (IOException ioe) {
    // LOG.error("Could not flush resposne: {}", ioe.toString(), ioe);
    // }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) ActorRef(akka.actor.ActorRef) IUserObject(com.pogeyan.cmis.api.auth.IUserObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncContext(javax.servlet.AsyncContext) ServletException(javax.servlet.ServletException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) BaseMessage(com.pogeyan.cmis.api.BaseMessage) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException)

Example 2 with CmisNotSupportedException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException in project copper-cms by PogeyanOSS.

the class ServletHelpers method postToBaseMessage.

static BaseMessage postToBaseMessage(POSTHttpServletRequestWrapper request, String[] pathFragments, IUserObject userObject) {
    PostRequest postRequest = new PostRequest();
    ControlParser controlParser = new ControlParser(request);
    if (controlParser != null) {
        CmisRequestParameter requestParameter = new CmisRequestParameter();
        postRequest.setPropertyData(controlParser.getProperties());
        postRequest.setAddAcl(requestParameter.createAddAcl(controlParser, postRequest));
        postRequest.setRemoveAcl(requestParameter.createRemoveAcl(controlParser, postRequest));
        postRequest.setPolicies(requestParameter.createPolicies(controlParser, postRequest));
        postRequest.setMultipart(request.isMultiPart());
        postRequest.setContentStream(requestParameter.createContentStream(request));
        postRequest.setObjectIds(requestParameter.getObjectIds(controlParser, postRequest));
        postRequest.setChangeTokens(requestParameter.getChangeTokens(controlParser, postRequest));
        postRequest.setAddSecondaryTypes(requestParameter.addSecondaryTypes(controlParser, postRequest));
        postRequest.setRemoveSecondaryTypes(requestParameter.getChangeTokens(controlParser, postRequest));
        postRequest.setPolicyId(requestParameter.getPolicyId(controlParser, postRequest));
        postRequest.setAclPropagation(requestParameter.getAclPropagation(controlParser, postRequest));
    }
    postRequest.setParameterMap(request.getParameterMap());
    postRequest.setBaseUrl((String) request.getAttribute(BrowserConstants.BASE_URL_ATTRIBUTE));
    postRequest.setScheme(request.getScheme());
    postRequest.setServerName(request.getServerName());
    postRequest.setServerPort(request.getServerPort());
    postRequest.setContextPath(request.getContextPath());
    postRequest.setServletPath(request.getServletPath());
    String cmisAction = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_CMISACTION);
    postRequest.setCmisAction(cmisAction);
    String objectId = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_OBJECT_ID);
    postRequest.setObjectId(objectId);
    if (pathFragments.length > 0) {
        postRequest.setRepositoryId(pathFragments[0]);
        if (objectId != null) {
            ObjectData object = ServletHelpers.getObjectDataFor(pathFragments[0], objectId, pathFragments);
            String typeId = getStringPropertyValue(object, PropertyIds.OBJECT_TYPE_ID);
            postRequest.setTypeId(typeId);
            BaseTypeId baseTypeId = BaseTypeId.fromValue(getStringPropertyValue(object, PropertyIds.BASE_TYPE_ID));
            postRequest.setBaseTypeId(baseTypeId);
        }
    }
    String token = HttpUtils.getStringParameter(request, BrowserConstants.CONTROL_TOKEN);
    postRequest.setToken(token);
    postRequest.setRequestBody(request.getRequestBody());
    if (cmisAction == null || cmisAction.length() == 0) {
        throw new CmisNotSupportedException("Unknown action");
    }
    postRequest.setPathFragments(pathFragments);
    if (userObject != null) {
        postRequest.setUserName(userObject.getUserDN());
        postRequest.setUserObject(userObject);
    }
    BaseMessage bm = BaseMessage.create("", cmisAction, postRequest);
    return bm;
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) PostRequest(com.pogeyan.cmis.api.messages.PostRequest) BaseMessage(com.pogeyan.cmis.api.BaseMessage) ControlParser(com.pogeyan.cmis.browser.shared.ControlParser) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CmisRequestParameter(com.pogeyan.cmis.browser.shared.CmisRequestParameter)

Example 3 with CmisNotSupportedException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException in project copper-cms by PogeyanOSS.

the class SetAndDeleteContentTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    if (getContentStreamUpdatesCapbility(session) == CapabilityContentStreamUpdates.NONE) {
        addResult(createResult(SKIPPED, "Stream updates are not supported. Test skipped!"));
        return;
    }
    try {
        // create folder and document
        Folder testFolder = createTestFolder(session);
        Document doc = createDocument(session, testFolder, "contenttest.txt", CONTENT1);
        Document workDoc = doc;
        DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
        // test if check out is required and possible
        boolean checkedout = false;
        if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
            if (!docType.isVersionable()) {
                addResult(createResult(SKIPPED, "The test document does not accept a new content stream. Test skipped!"));
                doc.delete(true);
                return;
            } else {
                workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
                checkedout = true;
                if (!workDoc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
                    addResult(createResult(SKIPPED, "The test PWC does not accept a new content stream. Test skipped!"));
                    workDoc.cancelCheckOut();
                    doc.delete(true);
                    return;
                }
            }
        }
        // test if the content stream can be deleted
        if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
            addResult(createResult(SKIPPED, "A content stream is required for this document type. deleteContentStream() test skipped!"));
        } else {
            // delete content stream
            try {
                ObjectId newObjectId = workDoc.deleteContentStream(true);
                // deleteContentStream may have created a new version
                Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "deleteContentStream()");
                f = createResult(FAILURE, "Document still has content after deleteContentStream() has been called!");
                addResult(assertNull(contentDoc.getContentStream(), null, f));
                f = createResult(FAILURE, "Document still has a MIME type after deleteContentStream() has been called: " + contentDoc.getContentStreamMimeType());
                addResult(assertNull(contentDoc.getContentStreamMimeType(), null, f));
                f = createResult(FAILURE, "Document still has a content length after deleteContentStream() has been called: " + contentDoc.getContentStreamLength());
                addResult(assertEquals(-1L, contentDoc.getContentStreamLength(), null, f));
                f = createResult(FAILURE, "Document still has a file name after deleteContentStream() has been called: " + contentDoc.getContentStreamFileName());
                addResult(assertNull(contentDoc.getContentStreamFileName(), null, f));
                workDoc = contentDoc;
            } catch (CmisNotSupportedException e) {
                addResult(createResult(WARNING, "deleteContentStream() is not supported!"));
            }
        }
        // set a new content stream
        byte[] contentBytes = IOUtils.toUTF8Bytes(CONTENT2);
        try {
            ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
            ObjectId newObjectId = workDoc.setContentStream(contentStream, true, true);
            IOUtils.closeQuietly(contentStream);
            // setContentStream may have created a new version
            Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "setContentStream()");
            // test new content
            try {
                String content = getStringFromContentStream(contentDoc.getContentStream());
                f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream()!");
                addResult(assertEquals(CONTENT2, content, null, f));
            } catch (IOException e) {
                addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
            }
            workDoc = contentDoc;
        } catch (CmisNotSupportedException e) {
            addResult(createResult(WARNING, "setContentStream() is not supported!"));
        }
        // test appendContentStream
        if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
            contentBytes = IOUtils.toUTF8Bytes(CONTENT3);
            try {
                ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
                ObjectId newObjectId = workDoc.appendContentStream(contentStream, true);
                // appendContentStream may have created a new version
                Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "appendContentStream()");
                // test new content
                try {
                    String content = getStringFromContentStream(contentDoc.getContentStream());
                    f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream() followed by appendContentStream()!");
                    addResult(assertEquals(CONTENT2 + CONTENT3, content, null, f));
                } catch (IOException e) {
                    addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
                }
                // test append stream
                testAppendStream(session, testFolder, 16 * 1024);
                testAppendStream(session, testFolder, 8);
                testAppendStream(session, testFolder, 0);
            } catch (CmisNotSupportedException e) {
                addResult(createResult(WARNING, "appendContentStream() is not supported!"));
            }
        }
        // cancel a possible check out
        if (checkedout) {
            workDoc.cancelCheckOut();
        }
        // remove the document
        deleteObject(doc);
    } finally {
        deleteTestFolder();
    }
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) IOException(java.io.IOException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 4 with CmisNotSupportedException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException in project structr by structr.

the class CMISObjectService method deleteTree.

@Override
public FailedToDeleteData deleteTree(final String repositoryId, final String folderId, final Boolean allVersions, final UnfileObject unfileObjects, final Boolean continueOnFailure, final ExtensionsData extension) {
    if (UnfileObject.UNFILE.equals(unfileObjects)) {
        throw new CmisNotSupportedException("Unfiling not supported");
    }
    final App app = StructrApp.getInstance(securityContext);
    final FailedToDeleteDataImpl result = new FailedToDeleteDataImpl();
    result.setIds(new LinkedList<String>());
    try (final Tx tx = app.tx()) {
        final Folder folder = app.get(Folder.class, folderId);
        if (folder != null) {
            recursivelyCheckAndDeleteFiles(app, result, folder, continueOnFailure);
        } else {
            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
        }
        tx.success();
    } catch (final FrameworkException fex) {
        logger.warn("", fex);
    }
    return result;
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) FailedToDeleteDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl) Folder(org.structr.web.entity.Folder)

Example 5 with CmisNotSupportedException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException in project copper-cms by PogeyanOSS.

the class AkkaCmisBrowserBindingServlet method gettingBaseMessage.

private BaseMessage gettingBaseMessage(String method, String[] pathFragments, IUserObject loginSession, HttpServletRequest request, HttpServletResponse response) {
    BaseMessage bm = null;
    try {
        // check HTTP method
        if (METHOD_GET.equals(method)) {
            QueryStringHttpServletRequestWrapper qRequest = new QueryStringHttpServletRequestWrapper(request);
            bm = ServletHelpers.queryHttpToBaseMessage((QueryStringHttpServletRequestWrapper) qRequest, pathFragments, loginSession);
        } else if (METHOD_POST.equals(method)) {
            POSTHttpServletRequestWrapper pRequest = new POSTHttpServletRequestWrapper(request);
            bm = ServletHelpers.postToBaseMessage((POSTHttpServletRequestWrapper) pRequest, pathFragments, loginSession);
        } else {
            throw new CmisNotSupportedException("Unsupported method");
        }
    } catch (Exception e1) {
        LOG.error("Service execution exception: {}, stack: {}", e1.getMessage(), ExceptionUtils.getStackTrace(e1));
        ServletHelpers.printError(e1, request, response);
    }
    return bm;
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) QueryStringHttpServletRequestWrapper(com.pogeyan.cmis.browser.shared.QueryStringHttpServletRequestWrapper) BaseMessage(com.pogeyan.cmis.api.BaseMessage) POSTHttpServletRequestWrapper(com.pogeyan.cmis.browser.shared.POSTHttpServletRequestWrapper) ServletException(javax.servlet.ServletException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)6 BaseMessage (com.pogeyan.cmis.api.BaseMessage)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ServletException (javax.servlet.ServletException)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)2 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)2 CmisUnauthorizedException (org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 IUserObject (com.pogeyan.cmis.api.auth.IUserObject)1 PostRequest (com.pogeyan.cmis.api.messages.PostRequest)1 CmisRequestParameter (com.pogeyan.cmis.browser.shared.CmisRequestParameter)1 ControlParser (com.pogeyan.cmis.browser.shared.ControlParser)1 POSTHttpServletRequestWrapper (com.pogeyan.cmis.browser.shared.POSTHttpServletRequestWrapper)1 QueryStringHttpServletRequestWrapper (com.pogeyan.cmis.browser.shared.QueryStringHttpServletRequestWrapper)1