Example usage for javax.servlet.http HttpServletResponse SC_UNSUPPORTED_MEDIA_TYPE

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

Introduction

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

Prototype

int SC_UNSUPPORTED_MEDIA_TYPE

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

Click Source Link

Document

Status code (415) indicating that the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.

Usage

From source file:org.openo.drivermgr.service.impl.DriverMgrServiceImpl.java

/**
 * Register the driver info to the db./* w  w w. j  a v a 2 s.c o  m*/
 * <br/>
 * 
 * @param request : HttpServletRequest Object
 * @param response : HttpServletResponse Object
 * @since  
 */
public void register(HttpServletRequest request, HttpServletResponse response) {

    LOGGER.info("Going to Register Driver");

    DriverProperties driverProp = CommonUtil.getInstance().getDriverInfo(request);

    CheckDriverParameter.getInstance().checkParameter(driverProp.getDriverInfo());

    String instanceId = driverProp.getDriverInfo().getInstanceID();

    if (driverManager.getDriverByInstanceId(instanceId) != null) {
        throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, ErrorCode.DUPLICATE_ID);
    }

    if (driverManager.registerDriver(driverProp)) {
        response.setStatus(HttpServletResponse.SC_CREATED);
    } else {
        throw new DriverManagerException(HttpServletResponse.SC_FORBIDDEN, ErrorCode.FAILURE_INFORMATION);
    }
}

From source file:org.openo.drivermgr.service.impl.DriverMgrServiceImpl.java

/**
 * unregister the driver info from the DB.
 * <br/>//ww  w.ja v a  2  s.  c o  m
 * 
 * @param request : HttpServletRequest Object
 * @param response : HttpServletResponse Object
 * @since  
 */
public void unregister(HttpServletRequest request, HttpServletResponse response, String instanceId) {

    LOGGER.info("Going to UnRegister Driver");

    if (driverManager.getDriverByInstanceId(instanceId) == null) {
        throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                ErrorCode.INVALID_PARAMETERS);
    }

    if (driverManager.unregisterDriver(instanceId)) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        throw new DriverManagerException(HttpServletResponse.SC_FORBIDDEN, ErrorCode.FAILURE_INFORMATION);
    }
}

From source file:org.openo.drivermgr.service.impl.DriverMgrServiceImpl.java

/**
 * get the driver info from the driver managerment.
 * <br/>/*from   w  w w  .  j  a va 2 s.  c o m*/
 * 
 * @param request
 * @param response
 * @param serviceUrl
 * @param systemId
 * @return
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonGenerationException
 * @since  
 */
public String getDriverDetails(HttpServletRequest request, HttpServletResponse response, String serviceUrl,
        String systemId) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        if (null == serviceUrl && null == systemId) {
            return mapper.writeValueAsString(getDriverDetails(request, response));
        } else {
            if (StringUtils.isBlank(systemId)) {
                throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                        ErrorCode.INVALID_PARAMETERS);
            }

            String driverUrl = getDriverDetail(request, response, serviceUrl, getSystemID(systemId));
            return mapper.writeValueAsString(new DriverUrl(driverUrl));

        }
    } catch (IOException e) {
        LOGGER.error("IO Exception Occuered", e);
        throw new DriverManagerException(HttpServletResponse.SC_REQUEST_TIMEOUT, ErrorCode.COMMUNICATION_ERROR);
    }
}

From source file:org.openo.drivermgr.service.impl.DriverMgrServiceImpl.java

/**
 * get the driver info from the driver managerment.
 * <br/>/*from  w  ww . j  a  va2s. co  m*/
 * 
 * @param request
 * @param response
 * @param serviceUrl
 * @param systemId
 * @return
 * @since  
 */
private String getDriverDetail(HttpServletRequest request, HttpServletResponse response, String serviceUrl,
        String systemId) {

    LOGGER.info("Going to get driver info by systemid = " + systemId);
    ExtSysInfo extSysInfo = ClientCommunication.getInstance().getExtSysInfo(systemId);

    String type = extSysInfo.getType();
    String version = extSysInfo.getVersion();

    LOGGER.info("Information from ESR + Name =" + extSysInfo.getName() + ", Type=" + type + " , Version = "
            + version);

    String path = driverManager.getDriverInfo(serviceUrl, type, version);
    if (StringUtils.isNotEmpty(path)) {
        return path;
    } else {
        LOGGER.error("No match driver info is found.");
        throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                ErrorCode.INVALID_PARAMETERS);
    }
}

From source file:org.openo.drivermgr.service.impl.DriverMgrServiceImpl.java

private String getSystemID(String systemID) {

    String sysID = "";
    if (StringUtils.isNotBlank(systemID) && systemID.contains("=")) {
        String[] values = systemID.split("=");
        if (values[0].equals(Constant.SYSTEM_ID_PARAM)) {
            sysID = values[1];// ww  w.j  a  v a2s . c o m
        }
    } else {
        throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                ErrorCode.INVALID_PARAMETERS);
    }
    if (!StringUtils.isNotBlank(sysID)) {
        throw new DriverManagerException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                ErrorCode.INVALID_PARAMETERS);
    }
    return sysID;
}

From source file:org.osaf.cosmo.cmp.CmpServlet.java

private boolean checkPutPreconditions(HttpServletRequest req, HttpServletResponse resp) {
    if (req.getContentLength() <= 0) {
        resp.setStatus(HttpServletResponse.SC_LENGTH_REQUIRED);
        return false;
    }//from ww w. j  a  v  a 2s .  co  m
    if (req.getContentType() == null || !req.getContentType().startsWith("text/xml")) {
        resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return false;
    }
    if (req.getHeader("Content-Transfer-Encoding") != null || req.getHeader("Content-Encoding") != null
            || req.getHeader("Content-Base") != null || req.getHeader("Content-Location") != null
            || req.getHeader("Content-MD5") != null || req.getHeader("Content-Range") != null) {
        resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        return false;
    }
    return true;
}

From source file:org.osaf.cosmo.cmp.CmpServlet.java

private boolean checkMultiUserDeletePreconditions(HttpServletRequest req, HttpServletResponse resp) {

    if (req.getContentType() == null || !req.getContentType().startsWith("application/x-www-form-urlencoded")) {
        resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return false;
    }//from  w  w w .  j a v a 2 s  .  co m

    return true;
}

From source file:org.osaf.cosmo.mc.MorseCodeServlet.java

private boolean checkWritePreconditions(HttpServletRequest req, HttpServletResponse resp) {
    if (req.getContentLength() <= 0) {
        resp.setStatus(HttpServletResponse.SC_LENGTH_REQUIRED);
        return false;
    }/*from   ww  w  .  ja v  a 2s.c o m*/

    if (req.getContentType() == null || !req.getContentType().startsWith(MEDIA_TYPE_EIMML)) {
        resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return false;
    }

    if (req.getHeader("Content-Transfer-Encoding") != null || req.getHeader("Content-Encoding") != null
            || req.getHeader("Content-Base") != null || req.getHeader("Content-Location") != null
            || req.getHeader("Content-MD5") != null || req.getHeader("Content-Range") != null) {
        resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        return false;
    }

    return true;
}

From source file:org.overlord.dtgov.ui.server.servlets.DeploymentUploadServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from ww w .j a  v a 2  s .  co m*/
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    // Extract the relevant content from the POST'd form
    if (ServletFileUpload.isMultipartContent(req)) {
        Map<String, String> responseMap;
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Parse the request
        String deploymentType = null;
        String version = null;
        String fileName = null;
        InputStream artifactContent = null;
        try {
            List<FileItem> items = upload.parseRequest(req);
            for (FileItem item : items) {
                if (item.isFormField()) {
                    if (item.getFieldName().equals("deploymentType")) { //$NON-NLS-1$
                        deploymentType = item.getString();
                    } else if (item.getFieldName().equals("version")) { //$NON-NLS-1$
                        version = item.getString();
                    }
                } else {
                    fileName = item.getName();
                    if (fileName != null)
                        fileName = FilenameUtils.getName(fileName);
                    artifactContent = item.getInputStream();
                }
            }

            // Default version is 1.0
            if (version == null || version.trim().length() == 0) {
                version = "1.0"; //$NON-NLS-1$
            }

            // Now that the content has been extracted, process it (upload the artifact to the s-ramp repo).
            responseMap = uploadArtifact(deploymentType, fileName, version, artifactContent);
        } catch (SrampAtomException e) {
            responseMap = new HashMap<String, String>();
            responseMap.put("exception", "true"); //$NON-NLS-1$ //$NON-NLS-2$
            responseMap.put("exception-message", e.getMessage()); //$NON-NLS-1$
            responseMap.put("exception-stack", ExceptionUtils.getRootStackTrace(e)); //$NON-NLS-1$
        } catch (Throwable e) {
            responseMap = new HashMap<String, String>();
            responseMap.put("exception", "true"); //$NON-NLS-1$ //$NON-NLS-2$
            responseMap.put("exception-message", e.getMessage()); //$NON-NLS-1$
            responseMap.put("exception-stack", ExceptionUtils.getRootStackTrace(e)); //$NON-NLS-1$
        } finally {
            IOUtils.closeQuietly(artifactContent);
        }
        writeToResponse(responseMap, response);
    } else {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                Messages.i18n.format("DeploymentUploadServlet.ContentTypeInvalid")); //$NON-NLS-1$
    }
}

From source file:org.overlord.sramp.ui.server.ArtifactUploadServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from  w ww. j ava2s.  c  o m
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    // Extract the relevant content from the POST'd form
    if (ServletFileUpload.isMultipartContent(req)) {
        Map<String, String> responseMap;
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Parse the request
        String artifactType = null;
        String fileName = null;
        InputStream artifactContent = null;
        try {
            List<FileItem> items = upload.parseRequest(req);
            for (FileItem item : items) {
                if (item.isFormField()) {
                    if (item.getFieldName().equals("artifactType")) {
                        artifactType = item.getString();
                    }
                } else {
                    fileName = item.getName();
                    if (fileName != null)
                        fileName = FilenameUtils.getName(fileName);
                    artifactContent = item.getInputStream();
                }
            }

            // Now that the content has been extracted, process it (upload the artifact to the s-ramp repo).
            responseMap = uploadArtifact(artifactType, fileName, artifactContent);
        } catch (SrampAtomException e) {
            responseMap = new HashMap<String, String>();
            responseMap.put("exception", "true");
            responseMap.put("exception-message", e.getMessage());
            responseMap.put("exception-stack", ExceptionUtils.getRootStackTrace(e));
        } catch (Throwable e) {
            responseMap = new HashMap<String, String>();
            responseMap.put("exception", "true");
            responseMap.put("exception-message", e.getMessage());
            responseMap.put("exception-stack", ExceptionUtils.getRootStackTrace(e));
        } finally {
            IOUtils.closeQuietly(artifactContent);
        }
        writeToResponse(responseMap, response);
    } else {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
                "Request contents type is not supported by the servlet.");
        return;
    }
}