Example usage for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST

List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.

Prototype

int SC_BAD_REQUEST

To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.

Click Source Link

Document

<tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616)

Usage

From source file:org.linagora.linshare.webservice.legacy.impl.PluginCompatibilityRestServiceImpl.java

@POST
@Path("/share/multiplesharedocuments")
@Override/*from www . j av a 2s  .co m*/
public void multiplesharedocuments(@FormParam("targetMail") String targetMail,
        @FormParam("file") List<String> uuid, @FormParam("securedShare") @DefaultValue("0") int securedShare,
        @FormParam("message") @DefaultValue("") String message,
        @FormParam("inReplyTo") @DefaultValue("") String inReplyTo,
        @FormParam("references") @DefaultValue("") String references) throws BusinessException {
    CollectionUtils.filter(uuid, StringPredicates.isNotBlank());
    if (uuid.isEmpty())
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing parameter file");
    webServiceShareFacade.multiplesharedocuments(targetMail, uuid, securedShare, message, inReplyTo,
            references);
}

From source file:org.linagora.linshare.webservice.legacy.impl.PluginCompatibilityRestServiceImpl.java

/**
 * upload a file in user's space. send file inside a form
 *//*www .  j  a va  2s . c  o  m*/
@POST
@Path("/document/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Override
public DocumentDto uploadfile(@Multipart(value = "file") InputStream theFile,
        @Multipart(value = "description", required = false) String description,
        @Multipart(value = "filename", required = false) String givenFileName, MultipartBody body)
        throws BusinessException {
    checkMaintenanceMode();
    String comment = (description == null) ? "" : description;
    if (theFile == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    String fileName = getFileName(givenFileName, body);
    File tempFile = getTempFile(theFile, "rest-plugin", fileName);
    try {
        return webServiceDocumentFacade.create(tempFile, fileName, comment, null);
    } finally {
        deleteTempFile(tempFile);
    }
}

From source file:org.linagora.linshare.webservice.uploadrequest.impl.FlowUploaderRestServiceImpl.java

/**
 * UPLOAD FOR IE//from   www. j av a 2 s  .  c  o m
 */

@Path("/iexplorer")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@Override
public Response uploadForIe9(@Multipart(value = FILE) InputStream file, MultipartBody body,
        @Multipart(REQUEST_URL_UUID) String uploadRequestUrlUuid, @Multipart(PASSWORD) String password)
        throws BusinessException {
    if (file == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    // Ensure fileName and description aren't null
    String fileName = body.getAttachment(FILE).getContentDisposition().getParameter(IEFILENAME);

    try {
        byte[] bytes = fileName.getBytes("ISO-8859-1");
        fileName = new String(bytes, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        logger.error("Can not encode file name " + e1.getMessage());
    }

    ErrorDto errorDto;
    try {
        File tempFile2 = getTempFile(file, "rest-flowuploader", fileName);
        try {
            uploadRequestUrlFacade.addUploadRequestEntry(uploadRequestUrlUuid, password, tempFile2, fileName);
        } finally {
            deleteTempFile(tempFile2);
        }
        errorDto = new ErrorDto(0, "upload success");
    } catch (BusinessException exception) {
        logger.error(exception.getMessage());
        errorDto = new ErrorDto(exception.getErrorCode().getCode(), exception.getMessage());
    }
    ResponseBuilder response = Response.status(Status.OK);
    response.entity(errorDto);
    return response.build();
}

From source file:org.linagora.linshare.webservice.user.impl.DocumentRestServiceImpl.java

/**
 * upload a file in user's space. send file inside a form
 *//*  w  w w . j av a  2  s . c o  m*/
@POST
@Path("/")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Override
public DocumentDto uploadfile(@Multipart(value = "file") InputStream theFile,
        @Multipart(value = "description", required = false) String description,
        @Multipart(value = "filename", required = false) String givenFileName, MultipartBody body)
        throws BusinessException {
    User actor = webServiceDocumentFacade.checkAuthentication();
    String fileName;
    String comment = (description == null) ? "" : description;

    if ((actor instanceof Guest && !actor.getCanUpload())) {
        throw giveRestException(HttpStatus.SC_FORBIDDEN, "You are not authorized to use this service");
    }
    if (theFile == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    if (givenFileName == null || givenFileName.isEmpty()) {
        // parameter givenFileName is optional
        // so need to search this information in the header of the
        // attachement (with id file)
        fileName = body.getAttachment("file").getContentDisposition().getParameter("filename");
    } else {
        fileName = givenFileName;
    }

    return webServiceDocumentFacade.uploadfile(theFile, fileName, comment);
}

From source file:org.linagora.linshare.webservice.user.impl.FineUploaderServiceImpl.java

@Path("/receiver")
@ApiOperation(value = "Upload a file in the user space.", response = FineUploaderDto.class)
@POST//from ww  w  . ja  v  a  2 s .co m
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@Override
public FineUploaderDto upload(
        @ApiParam(value = "File stream", required = true) @Multipart(value = FILE) InputStream file,
        @ApiParam(value = "File name") @Multipart(value = FILE_NAME, required = false) String fileName,
        MultipartBody body) throws BusinessException {
    User actor = null;

    // Authentication, permission and error checking
    actor = documentFacade.checkAuthentication();
    if (actor instanceof Guest && !actor.getCanUpload()) {
        throw giveRestException(HttpStatus.SC_FORBIDDEN, "You are not authorized to use this service");
    }
    if (file == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    // Ensure fileName and description aren't null
    if (fileName == null || fileName.isEmpty()) {
        fileName = body.getAttachment(FILE).getContentDisposition().getParameter(FILE_NAME);
    }

    try {
        byte[] bytes = fileName.getBytes("ISO-8859-1");
        fileName = new String(bytes, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        logger.error("Can not encode file name " + e1.getMessage());
    }
    try {
        DocumentDto doc = documentFacade.uploadfile(file, fileName, "");
        return new FineUploaderDto(true, doc.getUuid());
    } catch (BusinessException e) {
        return new FineUploaderDto(false);
    }
}

From source file:org.linagora.linshare.webservice.user.impl.FineUploaderServiceImpl.java

@Path("/receiver/{uuid}")
@ApiOperation(value = "Remove a previously uploaded file by uuid", response = FineUploaderDto.class)
@DELETE//from   ww w  .j ava2 s .  c  o m
@Produces(MediaType.TEXT_PLAIN)
@Override
public FineUploaderDto delete(@ApiParam(value = "File uuid", required = true) @PathParam("uuid") String uuid)
        throws BusinessException {
    User actor = null;

    // Authentication, permission and error checking
    actor = documentFacade.checkAuthentication();
    if (actor instanceof Guest && !actor.getCanUpload()) {
        throw giveRestException(HttpStatus.SC_FORBIDDEN, "You are not authorized to use this service");
    }
    if (uuid == null || uuid.isEmpty()) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    try {
        documentFacade.deleteFile(uuid);
        return new FineUploaderDto(true);
    } catch (BusinessException e) {
        return new FineUploaderDto(false);
    }
}

From source file:org.linagora.linshare.webservice.user.impl.FineUploaderServiceImpl.java

@Path("/threadentry/{threadUuid}")
@ApiOperation(value = "Upload a file in a thread by uuid.", response = FineUploaderDto.class)
@POST/*w  ww . j  a v  a2  s  .  com*/
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@Override
public FineUploaderDto uploadThreadEntry(
        @ApiParam(value = "Thread uuid", required = true) @PathParam("threadUuid") String threadUuid,
        @ApiParam(value = FILE, required = true) @Multipart(value = FILE) InputStream file,
        @ApiParam(value = FILE_NAME) @Multipart(value = FILE_NAME, required = false) String fileName,
        MultipartBody body) throws BusinessException {
    User actor = null;

    // Authentication, permission and error checking
    actor = documentFacade.checkAuthentication();
    if (actor instanceof Guest && !actor.getCanUpload()) {
        throw giveRestException(HttpStatus.SC_FORBIDDEN, "You are not authorized to use this service");
    }
    if (file == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    if (threadUuid == null) {
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing thread Uuid(check parameter threadUuid)");
    }
    // Ensure fileName and description aren't null
    if (fileName == null || fileName.isEmpty()) {
        fileName = body.getAttachment(FILE).getContentDisposition().getParameter(FILE_NAME);
    }

    try {
        byte[] bytes = fileName.getBytes("ISO-8859-1");
        fileName = new String(bytes, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        logger.error("Can not encode file name " + e1.getMessage());
    }
    try {
        ThreadEntryDto doc = threadEntryFacade.uploadfile(threadUuid, file, fileName, "");
        return new FineUploaderDto(true, doc.getUuid());
    } catch (BusinessException e) {
        return new FineUploaderDto(false);
    }
}

From source file:org.linagora.linshare.webservice.userv1.impl.DocumentRestServiceImpl.java

@Path("/")
@POST//w  w w .j a  v a 2s . c  om
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a document which will contain the uploaded file.", response = DocumentDto.class)
@ApiResponses({
        @ApiResponse(code = 403, message = "Current logged in account does not have the delegation role."),
        @ApiResponse(code = 404, message = "Document not found."),
        @ApiResponse(code = 400, message = "Bad request : missing required fields."),
        @ApiResponse(code = 500, message = "Internal server error."), })
@Override
public DocumentDto create(
        @ApiParam(value = "File stream.", required = true) @Multipart(value = "file", required = true) InputStream file,
        @ApiParam(value = "An optional description of a document.") @Multipart(value = "description", required = false) String description,
        @ApiParam(value = "The given file name of the uploaded file.", required = false) @Multipart(value = "filename", required = false) String givenFileName,
        @ApiParam(value = "Signature file stream.", required = false) @Multipart(value = "signaturefile", required = false) InputStream theSignatureFile,
        @ApiParam(value = "The given file name of the signature uploaded file.", required = false) @Multipart(value = "signatureFileName", required = false) String signatureFileName,
        @ApiParam(value = "X509 Certificate entity.", required = false) @Multipart(value = "x509cert", required = false) InputStream x509certificate,
        @ApiParam(value = "The given metadata of the uploaded file.", required = false) @Multipart(value = "metadata", required = false) String metaData,
        @ApiParam(value = "True to enable asynchronous upload processing.", required = false) @QueryParam("async") Boolean async,
        @HeaderParam("Content-Length") Long contentLength,
        @ApiParam(value = "file size (size validation purpose).", required = false) @Multipart(value = "filesize", required = false) Long fileSize,
        MultipartBody body) throws BusinessException {

    checkMaintenanceMode();
    Long transfertDuration = getTransfertDuration();
    if (file == null) {
        logger.error("Missing file (check parameter file)");
        throw giveRestException(HttpStatus.SC_BAD_REQUEST,
                "Missing file (check multipart parameter named 'file')");
    }
    String fileName = getFileName(givenFileName, body);
    // Default mode. No user input.
    if (async == null) {
        async = false;
    }
    File tempFile = getTempFile(file, "rest-userv2-document-entries", fileName);
    long currSize = tempFile.length();
    if (sizeValidation) {
        checkSizeValidation(contentLength, fileSize, currSize);
    }
    if (async) {
        logger.debug("Async mode is used");
        // Asynchronous mode
        AccountDto actorDto = documentFacade.getAuthenticatedAccountDto();
        AsyncTaskDto asyncTask = null;
        try {
            DocumentTaskContext documentTaskContext = new DocumentTaskContext(actorDto, actorDto.getUuid(),
                    tempFile, fileName, metaData, description);
            asyncTask = asyncTaskFacade.create(currSize, transfertDuration, fileName, null,
                    AsyncTaskType.DOCUMENT_UPLOAD);
            DocumentUploadAsyncTask task = new DocumentUploadAsyncTask(documentAsyncFacade, documentTaskContext,
                    asyncTask);
            taskExecutor.execute(task);
            return new DocumentDto(asyncTask, documentTaskContext);
        } catch (Exception e) {
            logAsyncFailure(asyncTask, e);
            deleteTempFile(tempFile);
            throw e;
        }
    } else {
        // TODO : manage transfertDuration
        // Synchronous mode
        try {
            logger.debug("Async mode is not used");
            if (theSignatureFile != null) {
                return documentFacade.createWithSignature(tempFile, fileName, description, theSignatureFile,
                        signatureFileName, x509certificate);
            }
            return documentFacade.create(tempFile, fileName, description, metaData);
        } finally {
            deleteTempFile(tempFile);
        }
    }
}

From source file:org.linagora.linshare.webservice.userv1.impl.ThreadEntryRestServiceImpl.java

@Path("/")
@POST/*from w  w w .  j av a 2s .  c o m*/
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Create a thread entry which will contain the uploaded file.", response = WorkGroupEntryDto.class)
@ApiResponses({
        @ApiResponse(code = 403, message = "Current logged in account does not have the delegation role."),
        @ApiResponse(code = 404, message = "Thread entry not found."),
        @ApiResponse(code = 400, message = "Bad request : missing required fields."),
        @ApiResponse(code = 500, message = "Internal server error."), })
@Override
public WorkGroupEntryDto create(
        @ApiParam(value = "The thread uuid.", required = true) @PathParam("threadUuid") String threadUuid,
        @ApiParam(value = "File stream.", required = true) @Multipart(value = "file", required = true) InputStream file,
        @ApiParam(value = "An optional description of a thread entry.") @Multipart(value = "description", required = false) String description,
        @ApiParam(value = "The given file name of the uploaded file.", required = true) @Multipart(value = "filename", required = false) String givenFileName,
        @ApiParam(value = "True to enable asynchronous upload processing.", required = false) @QueryParam("async") Boolean async,
        @HeaderParam("Content-Length") Long contentLength,
        @ApiParam(value = "file size (size validation purpose).", required = false) @Multipart(value = "filesize", required = false) Long fileSize,
        MultipartBody body) throws BusinessException {
    checkMaintenanceMode();
    Long transfertDuration = getTransfertDuration();
    if (file == null) {
        logger.error("Missing file (check parameter file)");
        throw giveRestException(HttpStatus.SC_BAD_REQUEST, "Missing file (check parameter file)");
    }
    String fileName = getFileName(givenFileName, body);
    // Default mode. No user input.
    if (async == null) {
        async = false;
    }
    File tempFile = getTempFile(file, "rest-userv2-thread-entries", fileName);
    long currSize = tempFile.length();
    if (sizeValidation) {
        checkSizeValidation(contentLength, fileSize, currSize);
    }
    if (async) {
        logger.debug("Async mode is used");
        // Asynchronous mode
        AccountDto actorDto = workGroupEntryFacade.getAuthenticatedAccountDto();
        AsyncTaskDto asyncTask = null;
        try {
            asyncTask = asyncTaskFacade.create(currSize, transfertDuration, fileName, null,
                    AsyncTaskType.THREAD_ENTRY_UPLOAD);
            ThreadEntryTaskContext threadEntryTaskContext = new ThreadEntryTaskContext(actorDto,
                    actorDto.getUuid(), threadUuid, tempFile, fileName, null);
            ThreadEntryUploadAsyncTask task = new ThreadEntryUploadAsyncTask(threadEntryAsyncFacade,
                    threadEntryTaskContext, asyncTask);
            taskExecutor.execute(task);
            return new WorkGroupEntryDto(asyncTask, threadEntryTaskContext);
        } catch (Exception e) {
            logAsyncFailure(asyncTask, e);
            throw e;
        } finally {
            deleteTempFile(tempFile);
        }
    } else {
        // TODO : manage transfertDuration
        // Synchronous mode
        try {
            logger.debug("Async mode is not used");
            WorkGroupEntryDto dto = workGroupEntryFacade.create(null, threadUuid, null, tempFile, fileName);
            // Compatibility code : Reset this field (avoid to display new attribute in old API) 
            dto.setWorkGroup(null);
            dto.setWorkGroupFolder(null);
            return dto;
        } finally {
            deleteTempFile(tempFile);
        }
    }
}

From source file:org.linagora.linshare.webservice.userv2.impl.DocumentRestServiceImpl.java

@Path("/")
@POST//from w w w .  j  a va 2 s . c  om
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create a document which will contain the uploaded file.", response = DocumentDto.class)
@ApiResponses({
        @ApiResponse(code = 403, message = "Current logged in account does not have the delegation role."),
        @ApiResponse(code = 404, message = "Document not found."),
        @ApiResponse(code = 400, message = "Bad request : missing required fields."),
        @ApiResponse(code = 500, message = "Internal server error."), })
@Override
public DocumentDto create(
        @ApiParam(value = "File stream.", required = true) @Multipart(value = "file", required = true) InputStream file,
        @ApiParam(value = "An optional description of a document.") @Multipart(value = "description", required = false) String description,
        @ApiParam(value = "The given file name of the uploaded file.", required = false) @Multipart(value = "filename", required = false) String givenFileName,
        @ApiParam(value = "Signature file stream.", required = false) @Multipart(value = "signaturefile", required = false) InputStream theSignatureFile,
        @ApiParam(value = "The given file name of the signature uploaded file.", required = false) @Multipart(value = "signatureFileName", required = false) String signatureFileName,
        @ApiParam(value = "X509 Certificate entity.", required = false) @Multipart(value = "x509cert", required = false) InputStream x509certificate,
        @ApiParam(value = "The given metadata of the uploaded file.", required = false) @Multipart(value = "metadata", required = false) String metaData,
        @ApiParam(value = "True to enable asynchronous upload processing.", required = false) @DefaultValue("false") @QueryParam("async") boolean async,
        @ApiParam(value = "file size (size validation purpose).", required = true) @Multipart(value = "filesize", required = true) Long fileSize,
        MultipartBody body) throws BusinessException {
    checkMaintenanceMode();
    Long transfertDuration = getTransfertDuration();
    if (file == null) {
        logger.error("Missing file (check parameter file)");
        throw giveRestException(HttpStatus.SC_BAD_REQUEST,
                "Missing file (check multipart parameter named 'file')");
    }
    String fileName = getFileName(givenFileName, body);
    File tempFile = getTempFile(file, "rest-userv2-document-entries", fileName);
    long currSize = tempFile.length();
    if (sizeValidation) {
        checkSizeValidation(fileSize, currSize);
    }
    if (async) {
        logger.debug("Async mode is used");
        // Asynchronous mode
        AccountDto actorDto = documentFacade.getAuthenticatedAccountDto();
        AsyncTaskDto asyncTask = null;
        try {
            DocumentTaskContext documentTaskContext = new DocumentTaskContext(actorDto, actorDto.getUuid(),
                    tempFile, fileName, metaData, description);
            asyncTask = asyncTaskFacade.create(currSize, transfertDuration, fileName, null,
                    AsyncTaskType.DOCUMENT_UPLOAD);
            DocumentUploadAsyncTask task = new DocumentUploadAsyncTask(documentAsyncFacade, documentTaskContext,
                    asyncTask);
            taskExecutor.execute(task);
            return new DocumentDto(asyncTask, documentTaskContext);
        } catch (Exception e) {
            logAsyncFailure(asyncTask, e);
            deleteTempFile(tempFile);
            throw e;
        }
    } else {
        // TODO : manage transfertDuration
        // Synchronous mode
        try {
            logger.debug("Async mode is not used");
            if (theSignatureFile != null) {
                return documentFacade.createWithSignature(tempFile, fileName, description, theSignatureFile,
                        signatureFileName, x509certificate);
            }
            return documentFacade.create(tempFile, fileName, description, metaData);
        } finally {
            deleteTempFile(tempFile);
        }
    }
}