本文整理汇总了Java中org.springframework.extensions.webscripts.Status.STATUS_BAD_REQUEST属性的典型用法代码示例。如果您正苦于以下问题:Java Status.STATUS_BAD_REQUEST属性的具体用法?Java Status.STATUS_BAD_REQUEST怎么用?Java Status.STATUS_BAD_REQUEST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.springframework.extensions.webscripts.Status
的用法示例。
在下文中一共展示了Status.STATUS_BAD_REQUEST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLongParam
private Long getLongParam(String paramStr, Long defaultVal)
{
if (paramStr == null)
{
// note: defaultVal can be null
return defaultVal;
}
try
{
return Long.parseLong(paramStr);
}
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, e.getMessage());
}
}
示例2: unprotectedExecuteImpl
@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
{
// get the filterID parameter.
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String filterID = templateVars.get("filterID");
if (filterID == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Filter id not provided");
}
facetService.deleteFacet(filterID);
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("success", true);
if (logger.isDebugEnabled())
{
logger.debug("Facet [" + filterID + "] has been deleted successfully");
}
return model;
}
示例3: importModel
protected CustomModel importModel(M2Model m2Model)
{
CustomModel model = null;
try
{
model = customModels.createCustomModel(m2Model);
}
catch (Exception ex)
{
int statusCode;
if (ex instanceof ConstraintViolatedException)
{
statusCode = Status.STATUS_CONFLICT;
}
else if (ex instanceof InvalidArgumentException)
{
statusCode = Status.STATUS_BAD_REQUEST;
}
else
{
statusCode = Status.STATUS_INTERNAL_SERVER_ERROR;
}
String msg = ex.getMessage();
// remove log numbers. regEx => match 8 or more integers
msg = (msg != null) ? msg.replaceAll("\\d{8,}", "").trim() : "cmm.rest_api.model.import_failure";
throw new WebScriptException(statusCode, msg);
}
return model;
}
示例4: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>(7);
String appName = getParamAppName(req);
if (appName == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "audit.err.app.notProvided");
}
AuditApplication app = auditService.getAuditApplications().get(appName);
if (app == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "audit.err.app.notFound", appName);
}
// Get from/to times
Long fromTime = getParamFromTime(req); // might be null
Long toTime = getParamToTime(req); // might be null
// Clear
int cleared = auditService.clearAudit(appName, fromTime, toTime);
model.put(JSON_KEY_CLEARED, cleared);
// Done
if (logger.isDebugEnabled())
{
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
示例5: getIntParam
private int getIntParam(String paramStr, int defaultVal)
{
if (paramStr == null)
{
return defaultVal;
}
try
{
return Integer.parseInt(paramStr);
}
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, e.getMessage());
}
}
示例6: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>(7);
String appName = getParamAppName(req);
String path = getParamPath(req);
boolean enabledGlobal = auditService.isAuditEnabled();
Map<String, AuditApplication> appsByName = auditService.getAuditApplications();
// Check that the application exists
if (appName != null)
{
if (path == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "audit.err.path.notProvided");
}
AuditApplication app = appsByName.get(appName);
if (app == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "audit.err.app.notFound", appName);
}
// Discard all the other applications
appsByName = Collections.singletonMap(appName, app);
}
model.put(JSON_KEY_ENABLED, enabledGlobal);
model.put(JSON_KEY_APPLICATIONS, appsByName.values());
// Done
if (logger.isDebugEnabled())
{
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
示例7: executeImpl
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put("success", Boolean.TRUE);
// What format are they after?
String format = req.getFormat();
if("csv".equals(format) || "xls".equals(format) ||
"xlsx".equals(format) || "excel".equals(format))
{
// Identify the thing to process
Object resource = identifyResource(format, req);
// Generate the spreadsheet
try
{
generateSpreadsheet(resource, format, req, status, model);
return model;
}
catch(IOException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Unable to generate template file", e);
}
}
// If we get here, then it isn't a spreadsheet version
if(allowHtmlFallback())
{
// There's some sort of help / upload form
return model;
}
else
{
throw new WebScriptException("Web Script format '" + format + "' is not supported");
}
}
示例8: identifyAction
@Override
protected Action identifyAction(WebScriptRequest req, Status status,
Cache cache) {
// Which action did they ask for?
String name = req.getParameter("name");
if(name == null) {
try {
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
if(! json.has("name")) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'name' parameter");
}
name = json.getString("name");
}
catch (IOException iox)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
}
catch (JSONException je)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
}
}
// Load the specified replication definition
ReplicationDefinition replicationDefinition =
replicationService.loadReplicationDefinition(name);
return replicationDefinition;
}
示例9: validateParameters
private void validateParameters(String siteShortName, String invitationId)
{
if ((invitationId == null) || (invitationId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid invitation id provided");
}
SiteInfo site = siteService.getSite(siteShortName);
if (site == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Invalid site id provided");
}
}
示例10: identifyAction
@Override
protected Action identifyAction(WebScriptRequest req, Status status,
Cache cache) {
// Which action did they ask for?
String nodeRef = req.getParameter("nodeRef");
if(nodeRef == null) {
try {
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
if(! json.has("nodeRef")) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'nodeRef' parameter");
}
nodeRef = json.getString("nodeRef");
}
catch (IOException iox)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
}
catch (JSONException je)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
}
}
// Does it exist in the repo?
NodeRef actionNodeRef = new NodeRef(nodeRef);
if(! nodeService.exists(actionNodeRef)) {
return null;
}
// Load the specified action
Action action = runtimeActionService.createAction(actionNodeRef);
return action;
}
示例11: executeImpl
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json,
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Grab the date range to search over
String numDaysS = req.getParameter("numdays");
int numDays = RECENT_POSTS_PERIOD_DAYS;
if (numDaysS != null)
{
numDays = Integer.parseInt(numDaysS);
}
Date now = new Date();
Date since = new Date(now.getTime() - numDays*ONE_DAY_MS);
// Get the topics with recent replies
PagingResults<Pair<TopicInfo,Integer>> topicsAndCounts = null;
PagingRequest paging = buildPagingRequest(req);
if (site != null)
{
topicsAndCounts = discussionService.listHotTopics(site.getShortName(), since, paging);
}
else
{
topicsAndCounts = discussionService.listHotTopics(nodeRef, since, paging);
}
// For this, we actually only need the topics, not their counts too
List<TopicInfo> topics = new ArrayList<TopicInfo>();
for (Pair<TopicInfo,Integer> tc : topicsAndCounts.getPage())
{
topics.add(tc.getFirst());
}
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}
// Build the common model parts
Map<String, Object> model = buildCommonModel(site, topic, post, req);
model.put("forum", nodeRef);
// Have the topics rendered
model.put("data", renderTopics(topics, topicsAndCounts.getTotalResultCount(), paging, site));
// All done
return model;
}
示例12: buildModel
private Map<String, Object> buildModel(WebScriptRequest req) throws JSONException, IOException
{
List<Long> aclIds = null;
Content content = req.getContent();
if (content == null)
{
throw new WebScriptException("Request content is empty");
}
JSONObject o = new JSONObject(content.getContent());
JSONArray aclIdsJSON = o.has("aclIds") ? o.getJSONArray("aclIds") : null;
if (aclIdsJSON == null)
{
throw new WebScriptException(
Status.STATUS_BAD_REQUEST,
"Parameter 'aclIds' not provided in request content.");
}
else if (aclIdsJSON.length() == 0)
{
throw new WebScriptException(
Status.STATUS_BAD_REQUEST,
"Parameter 'aclIds' must hold from 1 or more IDs.");
}
aclIds = new ArrayList<Long>(aclIdsJSON.length());
for (int i = 0; i < aclIdsJSON.length(); i++)
{
aclIds.add(aclIdsJSON.getLong(i));
}
// Request according to the paging query style required
List<AclReaders> aclsReaders = solrTrackingComponent.getAclsReaders(aclIds);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("aclsReaders", aclsReaders);
if (logger.isDebugEnabled())
{
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
示例13: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
if (!customModelService.isModelAdmin(AuthenticationUtil.getFullyAuthenticatedUser()))
{
throw new WebScriptException(Status.STATUS_FORBIDDEN, PermissionDeniedException.DEFAULT_MESSAGE_ID);
}
FormData formData = (FormData) req.parseContent();
if (formData == null || !formData.getIsMultiPart())
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_not_multi_part_req");
}
ImportResult resultData = null;
boolean processed = false;
for (FormData.FormField field : formData.getFields())
{
if (field.getIsFile())
{
final String fileName = field.getFilename();
File tempFile = createTempFile(field.getInputStream());
try (ZipFile zipFile = new ZipFile(tempFile, StandardCharsets.UTF_8))
{
resultData = processUpload(zipFile, field.getFilename());
}
catch (ZipException ze)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_not_zip_format", new Object[] { fileName });
}
catch (IOException io)
{
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_zip_file_failure", io);
}
finally
{
// now the import is done, delete the temp file
tempFile.delete();
}
processed = true;
break;
}
}
if (!processed)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_no_zip_file_uploaded");
}
// If we get here, then importing the custom model didn't throw any exceptions.
Map<String, Object> model = new HashMap<>(2);
model.put("importedModelName", resultData.getImportedModelName());
model.put("shareExtXMLFragment", resultData.getShareExtXMLFragment());
return model;
}
示例14: executeImpl
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef destinationNodeRef = null;
/* Parse the template vars */
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
destinationNodeRef = parseNodeRefFromTemplateArgs(templateVars);
/* Delete links */
DeleteLinksStatusReport report;
try
{
report = documentLinkService.deleteLinksToDocument(destinationNodeRef);
}
catch (IllegalArgumentException ex)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage());
}
catch (AccessDeniedException e)
{
throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation");
}
/* Build response */
Map<String, Object> model = new HashMap<String, Object>();
model.put("total_count", report.getTotalLinksFoundCount());
model.put("deleted_count", report.getDeletedLinksCount());
Map<String, String> errorDetails = new HashMap<String, String>();
Iterator<Entry<NodeRef, Throwable>> it = report.getErrorDetails().entrySet().iterator();
while (it.hasNext())
{
Map.Entry<NodeRef, Throwable> pair = it.next();
Throwable th = pair.getValue();
errorDetails.put(pair.getKey().toString(), th.getMessage());
}
model.put("error_details", errorDetails);
return model;
}
示例15: executeImpl
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json,
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Do we need to list or search?
boolean tagSearch = false;
String tag = req.getParameter("tag");
if (tag != null && tag.length() > 0)
{
tagSearch = true;
// Tags can be full unicode strings, so decode
tag = URLDecoder.decode(tag);
}
// Get the topics
boolean oldestTopicsFirst = false;
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if (tagSearch)
{
// Tag based is a search rather than a listing
if (site != null)
{
topics = discussionService.findTopics(site.getShortName(), null, tag, oldestTopicsFirst, paging);
}
else
{
topics = discussionService.findTopics(nodeRef, null, tag, oldestTopicsFirst, paging);
}
}
else
{
if (site != null)
{
topics = discussionService.listTopics(site.getShortName(), oldestTopicsFirst, paging);
}
else
{
topics = discussionService.listTopics(nodeRef, oldestTopicsFirst, buildPagingRequest(req));
}
}
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}
// Build the common model parts
Map<String, Object> model = buildCommonModel(site, topic, post, req);
model.put("forum", nodeRef);
// Have the topics rendered
model.put("data", renderTopics(topics, paging, site));
// All done
return model;
}