本文整理匯總了Java中javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.SC_BAD_REQUEST屬性的具體用法?Java HttpServletResponse.SC_BAD_REQUEST怎麽用?Java HttpServletResponse.SC_BAD_REQUEST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.SC_BAD_REQUEST屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Only set the status on the first call (the dispatch will trigger
// another call to this Servlet)
if (resp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) {
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
AsyncContext ac = req.startAsync();
ac.dispatch();
}
}
示例2: getState
/**
* Gets the specified {@link WorkflowTaskState}, null if not requested
*
* @param req WebScriptRequest
* @return WorkflowTaskState
*/
private WorkflowTaskState getState(WebScriptRequest req)
{
String stateName = req.getParameter(PARAM_STATE);
if (stateName != null)
{
try
{
return WorkflowTaskState.valueOf(stateName.toUpperCase());
}
catch (IllegalArgumentException e)
{
String msg = "Unrecognised State parameter: " + stateName;
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}
return null;
}
示例3: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req);
String ratingSchemeName = parseRequestForScheme(req);
Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName);
if (deletedRating == null)
{
// There was no rating in the specified scheme to delete.
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: "
+ ratingSchemeName + " from " + nodeRef.toString());
}
model.put(NODE_REF, nodeRef.toString());
model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName));
model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName));
model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName));
return model;
}
示例4: getState
/**
* Gets the specified {@link WorkflowState}, null if not requested.
*
* @param req The WebScript request
* @return The workflow state or null if not requested
*/
private WorkflowState getState(WebScriptRequest req)
{
String stateName = req.getParameter(PARAM_STATE);
if (stateName != null)
{
try
{
return WorkflowState.valueOf(stateName.toUpperCase());
}
catch (IllegalArgumentException e)
{
String msg = "Unrecognised State parameter: " + stateName;
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}
return null;
}
示例5: executeImpl
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model) throws IOException
{
// render content
QName propertyQName = ContentModel.PROP_CONTENT;
String contentPart = templateVars.get("property");
if (contentPart.length() > 0 && contentPart.charAt(0) == ';')
{
if (contentPart.length() < 2)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed");
}
String propertyName = contentPart.substring(1);
if (propertyName.length() > 0)
{
propertyQName = QName.createQName(propertyName, namespaceService);
}
}
// determine attachment
boolean attach = Boolean.valueOf(req.getParameter("a"));
// Stream the content
streamContentLocal(req, res, nodeRef, attach, propertyQName, model);
}
示例6: getIntParameter
private int getIntParameter(WebScriptRequest req, String paramName, int defaultValue)
{
String paramString = req.getParameter(paramName);
if (paramString != null)
{
try
{
int param = Integer.valueOf(paramString);
if (param >= 0)
{
return param;
}
}
catch (NumberFormatException e)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
}
}
return defaultValue;
}
示例7: setStatus
/**
* Behaviour depends on the status code.
*
* Status < 400 - Calls setStatus. Returns false. CGI servlet will provide
* the response body. Status >= 400 - Calls sendError(status), returns true.
* Standard error page mechanism will provide the response body.
*/
private boolean setStatus(HttpServletResponse response, int status) throws IOException {
if (status >= HttpServletResponse.SC_BAD_REQUEST) {
response.sendError(status);
return true;
} else {
response.setStatus(status);
return false;
}
}
示例8: parseRequestHeaders
/**
* Parse the request headers
*
* @exception WebDAVServerException
*/
protected void parseRequestHeaders() throws WebDAVServerException
{
// Get the lock token, if any
String strLockTokenHeader = m_request.getHeader(WebDAV.HEADER_LOCK_TOKEN);
// DEBUG
if (logger.isDebugEnabled())
logger.debug("Parsing Lock-Token header: " + strLockTokenHeader);
// Validate the lock token
if (strLockTokenHeader != null)
{
if (!(strLockTokenHeader.startsWith("<") && strLockTokenHeader.endsWith(">")))
{
// ALF-13904: Header isn't correctly enclosed in < and > characters. Try correcting this
// to allow for Windows 7 + OpenOffice.org bug.
strLockTokenHeader = "<" + strLockTokenHeader + ">";
}
if (strLockTokenHeader.startsWith("<" + WebDAV.OPAQUE_LOCK_TOKEN) && strLockTokenHeader.endsWith(">"))
{
try
{
m_strLockToken = strLockTokenHeader.substring(
WebDAV.OPAQUE_LOCK_TOKEN.length() + 1,
strLockTokenHeader.length() - 1);
}
catch (IndexOutOfBoundsException e)
{
logger.warn("Failed to parse If header: " + strLockTokenHeader);
}
}
}
// If there is no token this is a bad request so send an error back
if (m_strLockToken == null)
{
throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
}
}
示例9: testCommitOnComplete
@Test
public void testCommitOnComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStatusServlet asyncStatusServlet =
new AsyncStatusServlet(HttpServletResponse.SC_BAD_REQUEST);
Wrapper wrapper =
Tomcat.addServlet(ctx, "asyncStatusServlet", asyncStatusServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/asyncStatusServlet", "asyncStatusServlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/asyncStatusServlet");
int rc = getUrl(url.toString(), new ByteChunk(), null);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
// Without this test may complete before access log has a chance to log
// the request
Thread.sleep(REQUEST_TIME);
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
REQUEST_TIME);
}
示例10: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
if (! isEnabled())
{
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
if (nodeRef == null)
{
String msg = "A valid NodeRef must be specified!";
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
try
{
QuickShareDTO dto = quickShareService.shareContent(nodeRef);
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("sharedDTO", dto);
return model;
}
catch (InvalidNodeRefException inre)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef);
}
}
示例11: validateFilterID
protected void validateFilterID(String filterID)
{
Matcher matcher = FILTER_ID_PATTERN.matcher(filterID);
if (matcher.find())
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST,
"Invalid Filter Id. The characters \" * \\ < > ? / : | are not allowed. The Filter Id cannot end with a dot.");
}
}
示例12: finishResponse
/**
* Perform whatever actions are required to flush and close the output
* stream or writer, in a single operation.
*
* @exception IOException if an input/output error occurs
*/
public void finishResponse() throws IOException {
if (getStatus() < HttpServletResponse.SC_BAD_REQUEST) {
if ((!isStreamInitialized()) && (getContentLength() == -1)
&& (getStatus() >= 200)
&& (getStatus() != SC_NOT_MODIFIED)
&& (getStatus() != SC_NO_CONTENT))
setContentLength(0);
} else {
setHeader("Connection", "close");
}
super.finishResponse();
}
示例13: setStatus
/**
* Behaviour depends on the status code.
*
* Status < 400 - Calls setStatus. Returns false. CGI servlet will provide
* the response body.
* Status >= 400 - Calls sendError(status), returns true. Standard error
* page mechanism will provide the response body.
*/
private boolean setStatus(HttpServletResponse response, int status) throws IOException {
if (status >= HttpServletResponse.SC_BAD_REQUEST) {
response.sendError(status);
return true;
} else {
response.setStatus(status);
return false;
}
}
示例14: executeImpl
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
{
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
if (nodeRef == null)
{
String msg = "A valid NodeRef must be specified!";
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
try
{
Map<String, Object> model = quickShareService.getMetaData(nodeRef);
if (logger.isDebugEnabled())
{
logger.debug("Retrieved limited metadata: "+nodeRef+" ["+model+"]");
}
return model;
}
catch (InvalidNodeRefException inre)
{
logger.error("Unable to find node: "+inre.getNodeRef());
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find nodeRef: "+inre.getNodeRef());
}
}
示例15: patchProperties
protected void patchProperties(FileInfo nodeInfo, String path) throws WebDAVServerException
{
failedProperty = null;
for (PropertyAction action : m_propertyActions)
{
if (action.getProperty().isProtected())
{
failedProperty = action.getProperty();
break;
}
}
Map<QName, String> deadProperties = null;
for (PropertyAction propertyAction : m_propertyActions)
{
int statusCode;
String statusCodeDescription;
WebDAVProperty property = propertyAction.getProperty();
if (failedProperty == null)
{
PropertyDefinition propDef = getDAVHelper().getDictionaryService().getProperty(property.createQName());
boolean deadProperty = propDef == null || (!propDef.getContainerClass().isAspect() && !getDAVHelper().getDictionaryService().isSubClass(getNodeService().getType(nodeInfo.getNodeRef()),
propDef.getContainerClass().getName()));
if (deadProperty && deadProperties == null)
{
deadProperties = loadDeadProperties(nodeInfo.getNodeRef());
}
if (PropertyAction.SET == propertyAction.getAction())
{
if (deadProperty)
{
deadProperties.put(property.createQName(), property.getValue());
}
else
{
getNodeService().setProperty(nodeInfo.getNodeRef(), property.createQName(), property.getValue());
}
}
else if (PropertyAction.REMOVE == propertyAction.getAction())
{
if (deadProperty)
{
deadProperties.remove(property.createQName());
}
else
{
getNodeService().removeProperty(nodeInfo.getNodeRef(), property.createQName());
}
}
else
{
throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
}
statusCode = HttpServletResponse.SC_OK;
statusCodeDescription = WebDAV.SC_OK_DESC;
}
else if (failedProperty == property)
{
statusCode = HttpServletResponse.SC_FORBIDDEN;
statusCodeDescription = WebDAV.SC_FORBIDDEN_DESC;
}
else
{
statusCode = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY;
statusCodeDescription = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY_DESC;
}
propertyAction.setResult(statusCode, statusCodeDescription);
}
if (deadProperties != null)
{
persistDeadProperties(nodeInfo.getNodeRef(), deadProperties);
}
}