Package org.structr.rest

Examples of org.structr.rest.RestMethodResult


    Thread.dumpStack();
    throw new IllegalStateException("Resource.doHead() called, this should not happen.");
  }

  public RestMethodResult doOptions() throws FrameworkException {
    return new RestMethodResult(HttpServletResponse.SC_OK);
  }
View Full Code Here


        }

      }
    }

    return new RestMethodResult(HttpServletResponse.SC_OK);
  }
View Full Code Here

        }

      }

      return new RestMethodResult(HttpServletResponse.SC_OK);

    }

    throw new IllegalPathException();
  }
View Full Code Here

  @Override
  protected void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

    SecurityContext securityContext = null;
    Authenticator authenticator     = null;
    RestMethodResult result         = null;
    Resource resource               = null;

    try {

      // first thing to do!
      request.setCharacterEncoding("UTF-8");
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/json; charset=utf-8");

      // isolate request authentication in a transaction
      try (final Tx tx = StructrApp.getInstance().tx()) {
        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }

      final App app = StructrApp.getInstance(securityContext);

      // isolate resource authentication
      try (final Tx tx = app.tx()) {

        resource = ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView, config.getDefaultIdProperty()), config.getDefaultIdProperty());
        authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));

        tx.success();
      }

      // isolate doDelete
      boolean retry = true;
      while (retry) {

        try (final Tx tx = app.tx()) {
          result = resource.doDelete();
          tx.success();
          retry = false;

        } catch (DeadlockDetectedException ddex) {
          retry = true;
        }
      }

      // isolate write output
      try (final Tx tx = app.tx()) {
        result.commitResponse(gson.get(), response);
        tx.success();
      }

    } catch (FrameworkException frameworkException) {
View Full Code Here

  @Override
  protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    SecurityContext securityContext = null;
    Authenticator authenticator     = null;
    RestMethodResult result         = null;
    Resource resource               = null;

    try {

      // first thing to do!
      request.setCharacterEncoding("UTF-8");
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/json; charset=utf-8");

      // isolate request authentication in a transaction
      try (final Tx tx = StructrApp.getInstance().tx()) {
        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }

      final App app = StructrApp.getInstance(securityContext);

      // isolate resource authentication
      try (final Tx tx = app.tx()) {

        resource = ResourceHelper.applyViewTransformation(request, securityContext,
          ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView,
            config.getDefaultIdProperty()), config.getDefaultIdProperty()), propertyView);
        authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));
        tx.success();
      }

      // isolate doOptions
      boolean retry = true;
      while (retry) {

        try (final Tx tx = app.tx()) {

          result = resource.doOptions();
          tx.success();
          retry = false;

        } catch (DeadlockDetectedException ddex) {
          retry = true;
        }
      }

      // isolate write output
      try (final Tx tx = app.tx()) {
        result.commitResponse(gson.get(), response);
        tx.success();
      }

    } catch (FrameworkException frameworkException) {
View Full Code Here

        // isolate write output
        try (final Tx tx = app.tx()) {

          if (!results.isEmpty()) {

            final RestMethodResult result = results.get(0);
            final int resultCount         = results.size();

            if (resultCount > 1) {

              for (final RestMethodResult r : results) {

                final GraphObject objectCreated = r.getContent().get(0);
                if (!result.getContent().contains(objectCreated)) {

                  result.addContent(objectCreated);
                }

              }

              // remove Location header if more than one object was
              // written because it may only contain a single URL
              result.addHeader("Location", null);
            }

            result.commitResponse(gson.get(), response);
             
          }

          tx.success();
        }

      } else {

        // isolate write output
        try (final Tx tx = app.tx()) {

          new RestMethodResult(HttpServletResponse.SC_FORBIDDEN).commitResponse(gson.get(), response);
          tx.success();
        }

      }
View Full Code Here

      final App app         = StructrApp.getInstance(securityContext);
      NodeInterface newNode = null;

      newNode = createNode(propertySet);

      final RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
      if (newNode != null) {

        result.addHeader("Location", buildLocationHeader(newNode));
        result.addContent(newNode);
      }

      result.serializeAsPrimitiveArray(true);
     
      // finally: return 201 Created
      return result;

    } else {

      final App app                         = StructrApp.getInstance(securityContext);
      final Relation template               = getRelationshipTemplate();
      final ErrorBuffer errorBuffer         = new ErrorBuffer();

      if (template != null) {

        final NodeInterface sourceNode        = identifyStartNode(template, propertySet);
        final NodeInterface targetNode        = identifyEndNode(template, propertySet);
        final PropertyMap properties          = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);
        RelationshipInterface newRelationship = null;

        if (sourceNode == null) {
          errorBuffer.add(entityClass.getSimpleName(), new EmptyPropertyToken(template.getSourceIdProperty()));
        }

        if (targetNode == null) {
          errorBuffer.add(entityClass.getSimpleName(), new EmptyPropertyToken(template.getTargetIdProperty()));
        }

        if (errorBuffer.hasError()) {
          throw new FrameworkException(422, errorBuffer);
        }

        newRelationship = app.create(sourceNode, targetNode, entityClass, properties);

        RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
        if (newRelationship != null) {

          result.addHeader("Location", buildLocationHeader(newRelationship));
        }

        result.serializeAsPrimitiveArray(true);
       
        // finally: return 201 Created
        return result;
      }
View Full Code Here

  @Override
  protected void doPut(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

    SecurityContext securityContext = null;
    Authenticator authenticator     = null;
    RestMethodResult result         = null;
    IJsonInput jsonInput            = null;
    Resource resource               = null;

    try {

      // first thing to do!
      request.setCharacterEncoding("UTF-8");
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/json; charset=utf-8");

      // isolate request authentication in a transaction
      try (final Tx tx = StructrApp.getInstance().tx()) {
        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }

      final App app = StructrApp.getInstance(securityContext);

      String input = IOUtils.toString(request.getReader());
      if (StringUtils.isBlank(input)) {
        input = "{}";
      }

      // isolate input parsing (will include read and write operations)
      try (final Tx tx = app.tx()) {
        jsonInput   = gson.get().fromJson(input, IJsonInput.class);
        tx.success();
      }

      if (securityContext != null) {

        // isolate resource authentication
        try (final Tx tx = app.tx()) {

          // evaluate constraint chain
          resource = ResourceHelper.applyViewTransformation(request, securityContext,
            ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView,
              config.getDefaultIdProperty()), config.getDefaultIdProperty()), propertyView);
          authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));
          tx.success();
        }

        // isolate doPut
        boolean retry = true;
        while (retry) {

          try (final Tx tx = app.tx()) {
            result = resource.doPut(convertPropertySetToMap(jsonInput.getJsonInputs().get(0)));
            tx.success();
            retry = false;

          } catch (DeadlockDetectedException ddex) {
            retry = true;
          }
        }

        // isolate write output
        try (final Tx tx = app.tx()) {
          result.commitResponse(gson.get(), response);
          tx.success();
        }

      } else {

        // isolate write output
        try (final Tx tx = app.tx()) {
          result = new RestMethodResult(HttpServletResponse.SC_FORBIDDEN);
          result.commitResponse(gson.get(), response);
          tx.success();
        }

      }
View Full Code Here

              cmd.execute(propertySet);
            }

          } else {
            return new RestMethodResult(HttpServletResponse.SC_NOT_FOUND);
          }

          // return 200 OK
          return new RestMethodResult(HttpServletResponse.SC_OK);

        } catch (InstantiationException iex) {
          throw new SystemException(iex.getMessage());
        } catch (IllegalAccessException iaex) {
          throw new SystemException(iaex.getMessage());
View Full Code Here

  public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {

    // TODO: fetch nodes with superuser security context, collect forbidden nodes and return
    //       in error response

    RestMethodResult result = new RestMethodResult(200);

    for (Object o : propertySet.values()) {

      if (o instanceof String) {

        String id = (String)o;

        AbstractNode node = (AbstractNode) StructrApp.getInstance().get(id);
        if (node != null) {
          result.addContent(node);
        }
      }
    }

    return result;
View Full Code Here

TOP

Related Classes of org.structr.rest.RestMethodResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.