Example usage for org.springframework.http ResponseEntity ResponseEntity

List of usage examples for org.springframework.http ResponseEntity ResponseEntity

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity ResponseEntity.

Prototype

public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status) 

Source Link

Document

Create a new HttpEntity with the given headers and status code, and no body.

Usage

From source file:co.agileventure.jwtauth.web.controller.UserProcessorImpl.java

public ResponseEntity processUser(final HttpServletRequest request, final User.Provider provider,
        final String id, final String displayName, final String email, final String picture, final String name,
        final String givenName, final String familyName) throws JOSEException, ParseException {

    User user = null;//from  w ww  .ja  v  a2  s  .c  om
    switch (provider) {
    case FACEBOOK:
        user = userService.findByFacebook(id);
        break;
    case GOOGLE:
        user = userService.findByGoogle(id);
        break;
    default:
        return new ResponseEntity<String>("Unknown OAUTH2.0 Provider", HttpStatus.NOT_FOUND);
    }

    //If not found by provider try to find it by email
    if (user == null && StringUtils.isNotEmpty(email)) {
        user = userService.findByEmail(email);
    }

    // Step 3a. If user is already signed in then link accounts.
    User userToSave;
    final String authHeader = request.getHeader(AuthUtils.AUTH_HEADER_KEY);
    if (StringUtils.isNotBlank(authHeader)) {
        if (user == null) {
            return new ResponseEntity<String>(String.format(CONFLICT_MSG, provider.capitalize()),
                    HttpStatus.CONFLICT);
        }
        final String subject = AuthUtils.getSubject(authHeader);
        final User foundUser = userService.findOne(subject);
        if (foundUser == null) {
            return new ResponseEntity<String>(NOT_FOUND_MSG, HttpStatus.NOT_FOUND);
        }

        userToSave = foundUser;
        boolean updated = setUserProvider(provider, userToSave, id);
        if (userToSave.getDisplayName() == null) {
            userToSave.setDisplayName(displayName);
            updated = true;
        }
        if (userToSave.getPicture() == null) {
            userToSave.setPicture(picture);
            updated = true;
        }

        if (updated) {
            userToSave = userService.save(userToSave);
        }
    } else {
        // Step 3b. Create a new user account or return an existing one.
        if (user != null) {
            userToSave = user;
            if (setUserProvider(provider, userToSave, id)) {
                if (userToSave.getPicture() == null) {
                    userToSave.setPicture(picture);
                }
                userToSave = userService.save(userToSave);
            }
        } else {
            userToSave = new User();
            userToSave.setId(UUID.randomUUID().toString());
            userToSave.setDisplayName(displayName);
            userToSave.setEmail(email);
            userToSave.setName(name);
            userToSave.setGivenName(givenName);
            userToSave.setPicture(picture);
            userToSave.setFamilyName(familyName);

            setUserProvider(provider, userToSave, id);
            userToSave = userService.save(userToSave);
        }
    }

    Token token = AuthUtils.createToken(request.getRemoteHost(), userToSave.getId());
    return new ResponseEntity<Token>(token, HttpStatus.OK);
}

From source file:edu.pitt.dbmi.ccd.anno.index.IndexController.java

/**
 * Application index endpoint/*from w ww  .j a v a2  s.  c  o m*/
 *
 * @return links to endpoints
 */
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<IndexResource> index() {
    return new ResponseEntity<>(assembler.buildIndex(), HttpStatus.OK);
}

From source file:com.opensearchserver.hadse.RootController.java

@RequestMapping(method = RequestMethod.GET, value = "/")
@ResponseBody/* w  w  w .  j  a v  a2 s.co  m*/
public HttpEntity<RootResponse> home() {

    return new ResponseEntity<RootResponse>(new RootResponse(), HttpStatus.OK);
}

From source file:net.jkratz.igdb.controller.GenreController.java

/**
  * Returns all genres in database//from w  ww.j a  v a  2s .com
  * 
  * @return List of Genre objects
  * @see Genre
  */
@RequestMapping(value = { "", "/" }, method = RequestMethod.GET)
public ResponseEntity<List<Genre>> getGenres() {
    List<Genre> genres = genreRepository.findAll();

    return new ResponseEntity<>(genres, HttpStatus.OK);
}

From source file:reconf.server.services.property.ReadPropertyService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.GET)
@Transactional(readOnly = true)/*w  w  w.j ava2s  .c  om*/
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        HttpServletRequest request, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);
    Property reqProperty = new Property(key);

    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    Property dbProperty = properties.findOne(key);
    if (dbProperty == null) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Property.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    PropertyResult result = new PropertyResult(dbProperty, CrudServiceUtils.getBaseUrl(request));
    result.addSelfUri(CrudServiceUtils.getBaseUrl(request));
    return new ResponseEntity<PropertyResult>(result, HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.MetodoPagoFacturaController.java

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<MetodoPagoFactura> list = facadeService.getMetodoPagoFacturaDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {// w w w. ja va2 s  . c o  m
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:gt.dakaik.rest.impl.CountryImpl.java

@Override
public ResponseEntity<Country> findAll(int idUsuario, String token) throws EntidadNoEncontradaException {
    return new ResponseEntity(repoCountry.getAll(), HttpStatus.OK);
}

From source file:com.baidu.stqa.signet.web.action.RemarkAction.java

/**
 * /*from  w  ww  . j  av a2  s  .  com*/
 * 
 * @param projectId
 * @param storyId
 * @param nodeId
 * @return
 */
@RequestMapping(value = "/project/{projectId}/story/{storyId}/node/{nodeId}/remark", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<List<Remark>> getRemarks(@PathVariable long projectId, @PathVariable long storyId,
        @PathVariable long nodeId) {

    doLog(projectId);
    List<Remark> remarks = remarkService.getRemarksByNodeId(nodeId);
    return new ResponseEntity<List<Remark>>(remarks, HttpStatus.OK);
}

From source file:com.example.api.UrlShortener.java

@RequestMapping(value = "/", method = RequestMethod.POST)
ResponseEntity<String> save(@RequestParam String url) {
    if (validator.isValid(url)) {
        String hash = getHash(url);
        String shorten = new StringBuilder(urlShortenerUrl).append('/').append(hash).toString();
        return new ResponseEntity<>(shorten, HttpStatus.OK);
    } else {/*from  w ww  .  j  a  v  a2s.  c om*/
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:com.arya.latihan.controller.ItemController.java

@RequestMapping(method = RequestMethod.POST)
@Transactional(readOnly = false)//from  w ww.  j  av a 2  s . c om
public ResponseEntity<Void> saveItem(@RequestBody @Valid Item item) {
    Integer lastCode = itemRepository.findLastCode();
    String code = "M-" + String.format("%08d", (lastCode + 1));
    item.setCode(code);
    item = itemRepository.save(item);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(item.getId())
            .toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}