Example usage for javax.servlet.http HttpServletResponse SC_CREATED

List of usage examples for javax.servlet.http HttpServletResponse SC_CREATED

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_CREATED.

Prototype

int SC_CREATED

To view the source code for javax.servlet.http HttpServletResponse SC_CREATED.

Click Source Link

Document

Status code (201) indicating the request succeeded and created a new resource on the server.

Usage

From source file:de.elomagic.mag.ServletMock.java

@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    received = false;/*w  ww . j  ava  2 s. c o  m*/

    lastContentLength = request.getContentLength();
    requestedUri = request.getRequestURI();

    if (lastContentLength > 0) {
        lastContent = IOUtils.readFully(request.getInputStream(), lastContentLength);
    }

    LOGGER.info("contentLength=" + FileUtils.byteCountToDisplaySize(lastContentLength));
    LOGGER.info("content" + lastContent);

    response.setStatus(HttpServletResponse.SC_CREATED);

    received = true;
}

From source file:com.thinkberg.moxo.dav.PutHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {/*from   w  w w  . j  av a2 s .  c om*/
        LockManager.getInstance().checkCondition(object, getIf(request));
    } catch (LockException e) {
        if (e.getLocks() != null) {
            response.sendError(SC_LOCKED);
        } else {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
        return;
    }

    // it is forbidden to write data on a folder
    if (object.exists() && FileType.FOLDER.equals(object.getType())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    FileObject parent = object.getParent();
    if (!parent.exists()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (!FileType.FOLDER.equals(parent.getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    InputStream is = request.getInputStream();
    OutputStream os = object.getContent().getOutputStream();
    log("PUT sends " + request.getHeader("Content-length") + " bytes");
    log("PUT copied " + Util.copyStream(is, os) + " bytes");
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

From source file:com.homesnap.webserver.ControllerRestAPITest.java

@Test
public void test01CreateControllerByGroup() {
    // Test impossible to create an existing controller
    deleteRequestJSONObject("/house", HttpServletResponse.SC_NO_CONTENT);
    postRequestJSONObject(urn_groups + "/group?id=1", createGroup1(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/11", createJsonController11(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/12", createJsonController12(), HttpServletResponse.SC_CREATED);

    JSONObject jo = postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_CREATED);
    testController16(jo);/*w ww.j a v a2s  .  co m*/
    postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_NOT_ACCEPTABLE);

    jo = postRequestJSONObject(urn_groups + "/1/17", createJsonController17(), HttpServletResponse.SC_CREATED);
    testController17(jo);
}

From source file:org.syncope.core.rest.controller.DerivedSchemaController.java

@PreAuthorize("hasRole('SCHEMA_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/{kind}/create")
public DerivedSchemaTO create(final HttpServletResponse response,
        @RequestBody final DerivedSchemaTO derivedSchemaTO, @PathVariable("kind") final String kind)
        throws SyncopeClientCompositeErrorException {

    AbstractDerSchema derivedSchema = derivedSchemaDataBinder.create(derivedSchemaTO,
            getAttributableUtil(kind).newDerivedSchema());

    derivedSchema = derivedSchemaDAO.save(derivedSchema);

    response.setStatus(HttpServletResponse.SC_CREATED);
    return derivedSchemaDataBinder.getDerivedSchemaTO(derivedSchema);
}

From source file:org.syncope.core.rest.controller.VirtualSchemaController.java

@PreAuthorize("hasRole('SCHEMA_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/{kind}/create")
public VirtualSchemaTO create(final HttpServletResponse response,
        @RequestBody final VirtualSchemaTO virtualSchemaTO, @PathVariable("kind") final String kind)
        throws SyncopeClientCompositeErrorException {

    AbstractVirSchema virtualSchema = virtualSchemaDataBinder.create(virtualSchemaTO,
            getAttributableUtil(kind).newVirtualSchema(), getAttributableUtil(kind).schemaClass());

    virtualSchema = virtualSchemaDAO.save(virtualSchema);

    response.setStatus(HttpServletResponse.SC_CREATED);
    return virtualSchemaDataBinder.getVirtualSchemaTO(virtualSchema);
}

From source file:org.efaps.webdav4vfs.handler.MkColHandler.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    BufferedReader bufferedReader = request.getReader();
    String line = bufferedReader.readLine();
    if (line != null) {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;//from  w  w w  .  j av a2s . c  o m
    }

    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {
        if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
    } catch (LockException e) {
        response.sendError(SC_LOCKED);
        return;
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }

    if (object.exists()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    try {
        object.createFolder();
        response.setStatus(HttpServletResponse.SC_CREATED);
    } catch (FileSystemException e) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:com.homesnap.webserver.GroupRestAPITest.java

@Test
public void test3CreateGroup() {
    // Test to get a specific group
    JSONObject group = postRequestJSONObject(urn_groups + "/6", createGroup6(), HttpServletResponse.SC_CREATED);
    // Test group 6
    testGroup6(group);//w  w  w  .j  a  v a 2  s .  c o  m

    group = postRequestJSONObject(urn_groups + "/group?id=10", createGroup10(), HttpServletResponse.SC_CREATED);
    // Test group 1
    testGroup10(group);

    group = postRequestJSONObject(urn_groups + "/group?id=1", createGroup1(), HttpServletResponse.SC_CREATED);
    // Test group 1
    testGroup1(group);
}

From source file:org.smigo.species.varieties.VarietyController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/variety", method = RequestMethod.POST)
public Object addVariety(@Valid @RequestBody Variety variety, BindingResult result,
        HttpServletResponse response, @AuthenticationPrincipal AuthenticatedUser user) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }//  w  ww  .j a  v a 2s .  co  m
    variety.setUserId(user.getId());
    final int id = varietyDao.addVariety(variety);
    response.setStatus(HttpServletResponse.SC_CREATED);
    return id;
}

From source file:net.skhome.roborace.web.controller.UserController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseBody/*from  ww w .  j av  a2s  .  c  o m*/
public Map<String, String> createUserAccount(@RequestBody @Valid final UserAccount account,
        final HttpServletResponse response) {

    try {
        service.createUserAccount(account);
        response.setStatus(HttpServletResponse.SC_CREATED);
        return Collections.singletonMap("id", account.getId());
    } catch (DataAccessException ex) {
        throw new ResourceAlreadyExistsException(account.getUsername());
    }

}

From source file:com.k42b3.quantum.handler.MessageHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (request.getMethod().equals("GET")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/json;charset=utf-8");
        baseRequest.setHandled(true);/*from   w  w  w.j  a  va  2s . c o  m*/

        try {
            String modifiedSince = request.getHeader("If-Modified-Since");
            Date date = null;

            if (modifiedSince != null && !modifiedSince.isEmpty()) {
                date = DateUtils.parseDate(modifiedSince);
            }

            response.getWriter()
                    .print(container.getGson().toJson(container.getMessageRepository().getAll(date)));
        } catch (SQLException e) {
            this.handleException(response, e);
        }
    } else if (request.getMethod().equals("POST")) {
        Message message = container.getGson().fromJson(readRequestBody(request), Message.class);

        container.getEventPublisher().publish(null, message);

        response.setContentType("application/json;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_CREATED);
        response.getWriter().print(container.getGson().toJson(message));
    }
}