Java Code Examples for org.springframework.extensions.webscripts.Status#setRedirect()

The following examples show how to use org.springframework.extensions.webscripts.Status#setRedirect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Login.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    // extract username and password
    String username = req.getParameter("u");
    if (username == null || username.length() == 0)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Username not specified");
    }
    String password = req.getParameter("pw");
    if (password == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Password not specified");
    }

    try
    {
        return login(username, password);
    }
    catch(WebScriptException e)
    {
        status.setCode(e.getStatus());
        status.setMessage(e.getMessage());
        status.setRedirect(true);
        return null;
    }
}
 
Example 2
Source File: BulkImportStopWebScript.java    From alfresco-bulk-import with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result = new HashMap<>();

    cache.setNeverCache(true);
    
    if (importer.getStatus().inProgress())
    {
        result.put("result", "stop requested");
        importer.stop();
        status.setCode(Status.STATUS_ACCEPTED, "Stop requested.");
        status.setRedirect(true);  // Make sure the custom 202 status template is used (why this is needed at all is beyond me...)
    }
    else
    {
        result.put("result", "no imports in progress");
        status.setCode(Status.STATUS_BAD_REQUEST, "No bulk imports are in progress.");
    }
    
    return(result);
}
 
Example 3
Source File: BulkImportResumeWebScript.java    From alfresco-bulk-import with Apache License 2.0 6 votes vote down vote up
/**
 * @see DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result = new HashMap<>();

    cache.setNeverCache(true);
    
    if (importer.getStatus().isPaused())
    {
        result.put("result", "resume requested");
        importer.resume();
        status.setCode(Status.STATUS_ACCEPTED, "Resume requested.");
        status.setRedirect(true);  // Make sure the custom 202 status template is used (why this is needed at all is beyond me...)
    }
    else
    {
        result.put("result", "no imports in progress");
        status.setCode(Status.STATUS_BAD_REQUEST, "No bulk imports are in progress.");
    }
    
    return(result);
}
 
Example 4
Source File: ReplicationDefinitionDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder, 
                                         WebScriptRequest req, Status status, Cache cache)
{
    // Which definition did they ask for?
    String replicationDefinitionName = 
       req.getServiceMatch().getTemplateVars().get("replication_definition_name");
    ReplicationDefinition replicationDefinition =
       replicationService.loadReplicationDefinition(replicationDefinitionName);
   
    // Does it exist?
    if(replicationDefinition == null) {
       throw new WebScriptException(
             Status.STATUS_NOT_FOUND, 
             "No Replication Definition found with that name"
       );
    }
    
    // Delete it
    replicationService.deleteReplicationDefinition(replicationDefinition);
    
    // Report that we have deleted it
    status.setCode(Status.STATUS_NO_CONTENT);
    status.setMessage("Replication Definition deleted");
    status.setRedirect(true);
    return null;
}
 
Example 5
Source File: LoginTicketDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    // retrieve ticket from request and current ticket
    String ticket = req.getExtensionPath();
    if (ticket == null || ticket.length() == 0)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Ticket not specified");
    }
    
    // construct model for ticket
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("ticket",  ticket);
    
    try
    {
        String ticketUser = ticketComponent.validateTicket(ticket);

        // do not go any further if tickets are different
        if (!AuthenticationUtil.getFullyAuthenticatedUser().equals(ticketUser))
        {
            status.setCode(HttpServletResponse.SC_NOT_FOUND);
            status.setMessage("Ticket not found");
        }
        else
        {
            // delete the ticket
            authenticationService.invalidateTicket(ticket);
            status.setMessage("Deleted Ticket " + ticket);
        }
    }
    catch(AuthenticationException e)
    {
        status.setCode(HttpServletResponse.SC_NOT_FOUND);
        status.setMessage("Ticket not found");
    }

    status.setRedirect(true);
    return model;
}
 
Example 6
Source File: LoginTicket.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    // retrieve ticket from request and current ticket
    String ticket = req.getExtensionPath();
    if (ticket == null || ticket.length() == 0)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Ticket not specified");
    }
    
    // construct model for ticket
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("ticket",  ticket);
    
    try
    {
        String ticketUser = ticketComponent.validateTicket(ticket);
        
        String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();

        // do not go any further if tickets are different 
        // or the user is not fully authenticated
        if (currentUser == null || !currentUser.equals(ticketUser))
        {
            status.setRedirect(true);
            status.setCode(HttpServletResponse.SC_NOT_FOUND);
            status.setMessage("Ticket not found");
        }
    }
    catch (AuthenticationException e)
    {
        status.setRedirect(true);
        status.setCode(HttpServletResponse.SC_NOT_FOUND);
        status.setMessage("Ticket not found");
    }
    
    return model;
}
 
Example 7
Source File: RunningActionDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> buildModel(
      RunningActionModelBuilder modelBuilder, WebScriptRequest req,
      Status status, Cache cache) {
   // Which action did they ask for?
   String actionTrackingId = 
      req.getServiceMatch().getTemplateVars().get("action_tracking_id");

   // Check it exists
   ExecutionSummary action = 
      getSummaryFromKey(actionTrackingId);
   if(action == null) {
      throw new WebScriptException(
            Status.STATUS_NOT_FOUND, 
            "No Running Action found with that tracking id"
      );
   }
   
   ExecutionDetails details =
      actionTrackingService.getExecutionDetails(action);
   if(details == null) {
      throw new WebScriptException(
            Status.STATUS_NOT_FOUND, 
            "No Running Action found with that tracking id"
      );
   }
   
   // Request the cancel
   actionTrackingService.requestActionCancellation(action);
   
   // Report it as having been cancelled
   status.setCode(Status.STATUS_NO_CONTENT);
   status.setMessage("Action cancellation requested");
   status.setRedirect(true);
   return null;
}
 
Example 8
Source File: BulkImportPauseWebScript.java    From alfresco-bulk-import with Apache License 2.0 5 votes vote down vote up
/**
 * @see DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result = new HashMap<>();

    cache.setNeverCache(true);
    
    if (importer.getStatus().inProgress())
    {
        if (!importer.getStatus().isPaused())
        {
            result.put("result", "pause requested");
            importer.pause();
            status.setCode(Status.STATUS_ACCEPTED, "Pause requested.");
            status.setRedirect(true);  // Make sure the custom 202 status template is used (why this is needed at all is beyond me...)
        }
        else
        {
            result.put("result", "import is already paused");
            status.setCode(Status.STATUS_BAD_REQUEST, "Bulk import is already paused.");
        }
    }
    else
    {
        result.put("result", "no imports in progress");
        status.setCode(Status.STATUS_BAD_REQUEST, "No bulk imports are in progress.");
    }
    
    return(result);
}
 
Example 9
Source File: BulkImportUIWebScript.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result = null;
    
    if (importer.getStatus().inProgress())
    {
        // If an import is already in progress, redirect to the status Web Script
        status.setCode(Status.STATUS_MOVED_TEMPORARILY);
        status.setRedirect(true);
        status.setLocation(request.getServiceContextPath() + WEB_SCRIPT_URI_BULK_IMPORT_STATUS);
    }
    else
    {
        // Construct the list of available bulk import sources
        Map<String, BulkImportSource> bulkImportSources = importer.getBulkImportSources();
        
        if (bulkImportSources != null && bulkImportSources.size() > 0)
        {
            List<Map<String, String>> sources = new ArrayList<Map<String, String>>(bulkImportSources.size());
            
            for (final String beanId : bulkImportSources.keySet())
            {
                BulkImportSource    source      = bulkImportSources.get(beanId);
                Map<String, String> sourceAsMap = new HashMap<String, String>();
                
                sourceAsMap.put("name",               source.getName());
                sourceAsMap.put("description",        source.getDescription());
                sourceAsMap.put("beanId",             beanId);
                sourceAsMap.put("configWebScriptURI", source.getConfigWebScriptURI());
                
                sources.add(sourceAsMap);
            }
            
            result = new HashMap<>();
            result.put("sources", sources);
        }
    }
    
    return(result);
}
 
Example 10
Source File: DeleteSpaceWebScript.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result        = null;
    String              targetPath    = null;
    NodeRef             targetNodeRef = null;
    
    cache.setNeverCache(true);
    
    try
    {
        targetPath = request.getParameter(PARAMETER_TARGET_PATH);

        if (targetPath == null || targetPath.trim().length() == 0)
        {
            throw new RuntimeException("Error: parameter '" + PARAMETER_TARGET_PATH + "' was not provided.");
        }
        
        targetPath    = targetPath.trim();
        targetNodeRef = convertPathToNodeRef(serviceRegistry, targetPath);
        
        fastDeleteSpace(targetPath, targetNodeRef);
        
    }
    catch (final WebScriptException wse)
    {
        throw wse;
    }
    catch (final FileNotFoundException fnfe)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "The path " + targetPath + " does not exist.", fnfe);
    }
    catch (final Throwable t)
    {
        throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, buildTextMessage(t), t);
    }
    
    // If successful, redirect back to the delete GET Web Script
    status.setCode(Status.STATUS_MOVED_TEMPORARILY);
    status.setRedirect(true);
    status.setLocation(request.getServiceContextPath() + WEB_SCRIPT_URI_DELETE_SPACE);
    
    return(result);
}