Example usage for org.springframework.web.bind.annotation RequestMethod HEAD

List of usage examples for org.springframework.web.bind.annotation RequestMethod HEAD

Introduction

In this page you can find the example usage for org.springframework.web.bind.annotation RequestMethod HEAD.

Prototype

RequestMethod HEAD

To view the source code for org.springframework.web.bind.annotation RequestMethod HEAD.

Click Source Link

Usage

From source file:github.priyatam.springrest.resource.PolicyResource.java

@RequestMapping(method = RequestMethod.HEAD, value = "/policy/{policyNum}")
@ResponseBody/*from   ww  w  . j a  va 2 s . c o  m*/
public ResponseEntity<Policy> head(HttpServletRequest request, @PathVariable String policyNum) {
    logger.debug("Requested head for: " + policyNum);
    // / String url = ServletUriComponentsBuilder.fromRequest(request).build().toString();
    try {
        String tag = eTagHelper.get(vhost + URLS.POLICY.expand(policyNum));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Etag", tag);
        return new ResponseEntity<Policy>(null, headers, HttpStatus.NO_CONTENT);
    } catch (InvalidTagException e) {
        return new ResponseEntity<Policy>(HttpStatus.NOT_FOUND);
    }
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.StudyPolicyStatementController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<StudyPolicyStatement> getStudyPolicyStatements(
        @RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_USER_NAME, REQUEST_PARAM_STUDY_ID,
            REQUEST_PARAM_DATASET_ID, REQUEST_PARAM_ANALYSIS_TOOL_ID);

    if (!params.isEmpty()) {
        String userName = params.get(REQUEST_PARAM_USER_NAME);
        String studyId = params.get(REQUEST_PARAM_STUDY_ID);
        String dataSetId = params.get(REQUEST_PARAM_DATASET_ID);
        String toolId = params.get(REQUEST_PARAM_ANALYSIS_TOOL_ID);

        ArrayList<String> missingParams = new ArrayList<String>();
        if (studyId == null) {
            missingParams.add(REQUEST_PARAM_STUDY_ID);
        }//from w w w.j  a va 2s  . c om
        if (dataSetId == null) {
            missingParams.add(REQUEST_PARAM_DATASET_ID);
        }
        if (toolId == null) {
            missingParams.add(REQUEST_PARAM_ANALYSIS_TOOL_ID);
        }
        if (userName != null) {
            if (studyId != null) {
                return studyPolicyStatementRepository.findByUserNameAndStudyId(userName,
                        validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
            } else {
                return studyPolicyStatementRepository.findByUserName(userName);
            }
        }
        if ((studyId != null) && ((dataSetId == null) && (toolId == null))) {
            return studyPolicyStatementRepository
                    .findByStudyId(validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        }
        if (!missingParams.isEmpty()) {
            throw new BadRequestException("Required parameter(s) missing: " + missingParams);
        }
        return studyPolicyStatementRepository.findStudyPolicyStatementByStudyIdAndDataSetIdAndToolId(
                validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId),
                validateIntegerParameter(REQUEST_PARAM_DATASET_ID, dataSetId),
                validateIntegerParameter(REQUEST_PARAM_ANALYSIS_TOOL_ID, toolId));
    }

    List<StudyPolicyStatement> studyPolicyStatements = new ArrayList<StudyPolicyStatement>();
    Iterator iter = studyPolicyStatementRepository.findAll().iterator();
    CollectionUtils.addAll(studyPolicyStatements, iter);

    return studyPolicyStatements;
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.ScannerUserController.java

@RequestMapping(value = ENTITY_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody ScannerUser getScannerUser(@PathVariable(ID_URL_PATH_VAR) Integer id) {
    ScannerUser foundUser = scannerUserRepository.findOne(id);
    if (foundUser == null) {
        throw new ResourceNotFoundException(id);
    }//  w w w.ja  va 2  s.com
    return foundUser;
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.StandardRoleController.java

@RequestMapping(value = ENTITY_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody StandardRole getStandardRole(@PathVariable(ID_URL_PATH_VAR) Integer id) {
    StandardRole foundStandardRole = standardRoleRepository.findOne(id);

    if (foundStandardRole == null) {
        throw new ResourceNotFoundException(id);
    }/*from   ww  w . java2  s  .  c o m*/
    return foundStandardRole;
}

From source file:de.blizzy.documentr.web.attachment.AttachmentController.java

@RequestMapping(value = "/{projectName:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}/" + "{branchName:"
        + DocumentrConstants.BRANCH_NAME_PATTERN + "}/" + "{pagePath:"
        + DocumentrConstants.PAGE_PATH_URL_PATTERN + "}/"
        + "{name:.*}", method = { RequestMethod.GET, RequestMethod.HEAD })
@PreAuthorize("hasPagePermission(#projectName, #branchName, #pagePath, VIEW)")
public ResponseEntity<byte[]> getAttachment(@PathVariable String projectName, @PathVariable String branchName,
        @PathVariable String pagePath, @PathVariable String name,
        @RequestParam(required = false) boolean download, HttpServletRequest request) throws IOException {

    try {//from   w  ww .j a  va 2s . c  om
        pagePath = Util.toRealPagePath(pagePath);
        PageMetadata metadata = pageStore.getAttachmentMetadata(projectName, branchName, pagePath, name);
        HttpHeaders headers = new HttpHeaders();

        long lastEdited = metadata.getLastEdited().getTime();
        long authenticationCreated = AuthenticationUtil.getAuthenticationCreationTime(request.getSession());
        long lastModified = Math.max(lastEdited, authenticationCreated);
        if (!download) {
            long projectEditTime = PageUtil.getProjectEditTime(projectName);
            if (projectEditTime >= 0) {
                lastModified = Math.max(lastModified, projectEditTime);
            }

            long modifiedSince = request.getDateHeader("If-Modified-Since"); //$NON-NLS-1$
            if ((modifiedSince >= 0) && (lastModified <= modifiedSince)) {
                return new ResponseEntity<byte[]>(headers, HttpStatus.NOT_MODIFIED);
            }
        }

        headers.setLastModified(lastModified);
        headers.setExpires(0);
        headers.setCacheControl("must-revalidate, private"); //$NON-NLS-1$
        if (download) {
            headers.set("Content-Disposition", //$NON-NLS-1$
                    "attachment; filename=\"" + name.replace('"', '_') + "\""); //$NON-NLS-1$ //$NON-NLS-2$
        }

        Page attachment = pageStore.getAttachment(projectName, branchName, pagePath, name);
        headers.setContentType(MediaType.parseMediaType(attachment.getContentType()));
        return new ResponseEntity<byte[]>(attachment.getData().getData(), headers, HttpStatus.OK);
    } catch (PageNotFoundException e) {
        return new ResponseEntity<byte[]>(HttpStatus.NOT_FOUND);
    }
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetVariableMetadataController.java

@RequestMapping(value = ENTITY_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody DataSetVariableMetadata getDataSetVariableMetadata(
        @PathVariable(ID_URL_PATH_VAR) Integer id) {
    DataSetVariableMetadata foundDataSetVariableMetadata = dataSetVariableMetadataRepository.findOne(id);

    if (foundDataSetVariableMetadata == null) {
        throw new ResourceNotFoundException(id);
    }/*from   w ww. ja  va  2  s .c  o  m*/
    return foundDataSetVariableMetadata;
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.SiteController.java

@RequestMapping(value = ENTITY_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody Site getSite(@PathVariable(ID_URL_PATH_VAR) Integer id) {
    Site foundSite = siteRepository.findOne(id);

    if (foundSite == null) {
        throw new ResourceNotFoundException(id);
    }//from www  . j a v a2  s . c  o  m
    return foundSite;
}

From source file:com.rr.generic.ui.controller.mainController.java

/**
 * The '/' request will be the default request of the translator. The request will serve up the home page of the translator.
 *
 * @param request// ww  w.j ava 2 s  .  c  o  m
 * @param response
 * @return   the home page view
 * @throws Exception
 */
@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView welcome(HttpServletRequest request, HttpServletResponse response,
        RedirectAttributes redirectAttr, HttpSession session) throws Exception {

    ModelAndView mav = new ModelAndView(new RedirectView("/login"));
    return mav;

}

From source file:alfio.controller.EventController.java

@RequestMapping(value = "/", method = RequestMethod.HEAD)
public ResponseEntity<String> replyToProxy() {
    return ResponseEntity.ok("Up and running!");
}

From source file:org.mashupmedia.controller.remote.RemoteLibraryController.java

@RequestMapping(value = "/album-art/{uniqueName}/{imageTypeValue}/{songId}", method = { RequestMethod.GET,
        RequestMethod.HEAD })
public ModelAndView handleAlbumArt(HttpServletRequest request, @PathVariable String uniqueName,
        @PathVariable String imageTypeValue, @PathVariable Long songId, Model model) throws IOException {
    Library remoteLibrary = getRemoteLibrary(uniqueName, request, true);
    if (remoteLibrary == null) {
        logger.info("Unable to load album art, unknown host: " + request.getRemoteHost());
        return null;
    }/*w  w  w  .j av a  2s .c  o  m*/

    logInAsSystemuser(request);

    ImageType imageType = ImageHelper.getImageType(imageTypeValue);
    StringBuilder servletPathBuilder = new StringBuilder(request.getServletPath());
    servletPathBuilder.append("/music/album-art");
    servletPathBuilder.append("/" + imageType.toString().toLowerCase());
    MediaItem mediaItem = mediaManager.getMediaItem(songId);
    if (mediaItem == null || !(mediaItem instanceof Song)) {
        return null;
    }
    Song song = (Song) mediaItem;
    Album album = song.getAlbum();
    long albumId = album.getId();

    servletPathBuilder.append("/" + albumId);
    return new ModelAndView("forward:" + servletPathBuilder.toString());
}