当前位置: 首页>>代码示例>>Java>>正文


Java Status.BAD_REQUEST属性代码示例

本文整理汇总了Java中javax.ws.rs.core.Response.Status.BAD_REQUEST属性的典型用法代码示例。如果您正苦于以下问题:Java Status.BAD_REQUEST属性的具体用法?Java Status.BAD_REQUEST怎么用?Java Status.BAD_REQUEST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.ws.rs.core.Response.Status的用法示例。


在下文中一共展示了Status.BAD_REQUEST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toResponse

@Override
public Response toResponse(Throwable t) {
    if (t instanceof WebApplicationException) {
        return ((WebApplicationException) t).getResponse();
    }

    Status status = Status.INTERNAL_SERVER_ERROR;
    String message = Messages.ERROR_EXECUTING_REST_API_CALL;

    if (t instanceof ContentException) {
        status = Status.BAD_REQUEST;
    } else if (t instanceof NotFoundException) {
        status = Status.NOT_FOUND;
    } else if (t instanceof ConflictException) {
        status = Status.CONFLICT;
    }

    if (t instanceof SLException || t instanceof VirusScannerException) {
        message = t.getMessage();
    }

    LOGGER.error(Messages.ERROR_EXECUTING_REST_API_CALL, t);
    return Response.status(status).entity(message).type(MediaType.TEXT_PLAIN_TYPE).build();
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:24,代码来源:CFExceptionMapper.java

示例2: createException

private RequestValidationException createException(ValidationReport report) {

    ImmutableList.Builder<Object> invalidParamsBuilder = new ImmutableList.Builder<>();

    report.getMessages().forEach(message -> {
      ImmutableMap.Builder<String, String> paramBuilder = new ImmutableMap.Builder<>();
      paramBuilder.put("name", message.getKey());
      paramBuilder.put("reason", message.getMessage());
      invalidParamsBuilder.add(paramBuilder.build());
    });

    ImmutableMap<String, Object> details =
        ImmutableMap.of("invalid-params", invalidParamsBuilder.build());

    return new RequestValidationException("Request parameters didn't validate.", Status.BAD_REQUEST,
        details);
  }
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:17,代码来源:ApiRequestValidator.java

示例3: execute

@POST
public Response execute(String x) {
	GraphQLRequest request = Json.loads(x, GraphQLRequest.class);
	String query = request.query;
	Object context = null;
	Map<String, Object> arguments = request.variables;
	if (query == null) { query = ""; }
	if (arguments == null) {arguments = Collections.emptyMap(); }
	ExecutionResult result = graphql
		.execute(query, context, arguments);
	List<Object> errors = handleErrors(result);
	Map<String, Object> output = new LinkedHashMap<>();
	Status status = Status.OK;
	if (!errors.isEmpty()) {
		// react-relay rejected when
		// key "errors" presented even it's empty
		output.put("errors", errors);
		status = Status.BAD_REQUEST;
	}
	output.put("data", result.getData());
	return Response
		.status(status)
		.type(MediaType.APPLICATION_JSON)
		.entity(Json.dumps(output))
		.build();
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:26,代码来源:GraphQLService.java

示例4: testRestToArgsInstanceExcetpion

@Test
public void testRestToArgsInstanceExcetpion(@Mocked HttpServletRequest request,
    @Mocked RestOperationMeta restOperation, @Mocked RestParam restParam,
    @Mocked ParamValueProcessor processer) throws Exception {
  List<RestParam> params = new ArrayList<>();
  params.add(restParam);
  InvocationException exception = new InvocationException(Status.BAD_REQUEST, "Parameter is not valid.");

  new Expectations() {
    {
      restOperation.getParamList();
      result = params;
      restParam.getParamProcessor();
      result = processer;
      processer.getValue(request);
      result = exception;
    }
  };

  boolean success = false;
  try {
    RestCodec.restToArgs(request, restOperation);
    success = true;
  } catch (InvocationException e) {
    Assert.assertEquals(e.getStatusCode(), Status.BAD_REQUEST.getStatusCode());
  }
  Assert.assertEquals(success, false);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:28,代码来源:TestRestCodec.java

示例5: nextStep

@POST
@javax.ws.rs.Path("/commands/{commandName}/next")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JsonObject nextStep(JsonObject content,
                           @PathParam("commandName") @DefaultValue(DEFAULT_COMMAND_NAME) String commandName,
                           @Context HttpHeaders headers)
        throws Exception {
    validateCommand(commandName);
    int stepIndex = content.getInt("stepIndex", 1);
    JsonObjectBuilder builder = createObjectBuilder();
    try (CommandController controller = getCommand(commandName, ForgeInitializer.getRoot(), headers)) {
        if (!(controller instanceof WizardCommandController)) {
            throw new WebApplicationException("Controller is not a wizard", Status.BAD_REQUEST);
        }
        controller.getContext().getAttributeMap().put("action", "next");
        WizardCommandController wizardController = (WizardCommandController) controller;
        helper.populateController(content, controller);
        for (int i = 0; i < stepIndex; i++) {
            wizardController.next().initialize();
            helper.populateController(content, wizardController);
        }
        helper.describeMetadata(builder, controller);
        helper.describeInputs(builder, controller);
        helper.describeCurrentState(builder, controller);
    }
    return builder.build();
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:28,代码来源:LaunchResource.java

示例6: writeTo

@Override
public void writeTo(PropertyBox t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
		MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
		throws IOException, WebApplicationException {
	try (final Writer writer = new OutputStreamWriter(entityStream, CHARSET)) {
		try {
			getObjectWriter().writeValue(writer, t);
		} catch (JsonProcessingException e) {
			throw new WebApplicationException(e.getMessage(), e, Status.BAD_REQUEST);
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:12,代码来源:JacksonJsonPropertyBoxProvider.java

示例7: readPropertyBox

/**
 * Read given <code>application/x-www-form-urlencoded</code> type value into a {@link PropertyBox}.
 * @param encoded Value to read
 * @return PropertyBox with current {@link com.holonplatform.core.Context} property set initialized with the values
 *         read from given form data
 * @throws IOException If a PropertySet is missing
 * @throws WebApplicationException If a property read error occurred
 */
private PropertyBox readPropertyBox(String encoded) throws IOException, WebApplicationException {
	if (encoded != null && !encoded.trim().equals("")) {
		PropertySet<?> propertySet = com.holonplatform.core.Context.get()
				.resource(PropertySet.CONTEXT_KEY, PropertySet.class)
				.orElseThrow(() -> new IOException("Missing PropertySet instance to build a PropertyBox. "
						+ "A PropertySet instance must be available as context resource to perform PropertyBox deserialization."));

		try {
			final PropertyBox.Builder builder = PropertyBox.builder(propertySet).invalidAllowed(true);

			// decode
			String[] pairs = encoded.split("\\&");
			if (pairs != null) {
				for (String pair : pairs) {
					String[] fields = pair.split("=");
					if (fields != null && fields.length > 1) {
						final String name = decode(fields[0]);
						if (name != null) {
							final String value = decode(fields[1]);
							getPropertyByName(propertySet, name).ifPresent(p -> {
								builder.set(p, deserialize(p, value));
							});
						}
					}
				}
			}

			return builder.build();

		} catch (PropertyAccessException e) {
			throw new WebApplicationException(e.getMessage(), e, Status.BAD_REQUEST);
		}
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:43,代码来源:PropertyBoxFormDataProvider.java

示例8: createStagingFromItem

/**
 * @param itemUuid The uuid of the item to copy files from
 * @param version The version of the item to copy files from
 * @return
 */
@Override
public Response createStagingFromItem(String itemUuid, int itemVersion)
{
	final StagingFile stagingFile = stagingService.createStagingArea();

	if( Check.isEmpty(itemUuid) || itemVersion == 0 )
	{
		throw new WebApplicationException(
			new IllegalArgumentException("uuid and version must be supplied to the copy endpoint"),
			Status.BAD_REQUEST);
	}

	final Item item = itemService.get(new ItemId(itemUuid, itemVersion));
	if( aclService.filterNonGrantedPrivileges(item, PRIVS_COPY_ITEM_FILES).isEmpty() )
	{
		throw new PrivilegeRequiredException(PRIVS_COPY_ITEM_FILES);
	}

	final ItemFile itemFile = itemFileService.getItemFile(item);
	if( !fileSystemService.fileExists(itemFile) )
	{
		throw new WebApplicationException(Status.NOT_FOUND);
	}
	fileSystemService.copy(itemFile, stagingFile);

	// final RootFolderBean stagingBean = convertStagingFile(stagingFile,
	// false);
	// was: .entity(stagingBean)
	return Response.status(Status.CREATED).location(itemLinkService.getFileDirURI(stagingFile, null)).build();
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:FileResourceImpl.java

示例9: putFile

@Override
public Response putFile(String uuid, String filepath, InputStream data, String unzipTo, String copySource,
	int partNumber, String uploadId, long size, String contentType) throws IOException
{
	final StagingFile stagingFile = getStagingFile(uuid);
	if( fileSystemService.fileExists(stagingFile, filepath) )
	{
		throw new WebApplicationException(Status.BAD_REQUEST);
	}
	if( !Strings.isNullOrEmpty(copySource) )
	{
		fileSystemService.copy(stagingFile, copySource, stagingFile, filepath);
		String md5 = fileSystemService.getMD5Checksum(stagingFile, filepath);
		return Response.ok().header(HttpHeaders.ETAG, "\"" + md5 + "\"").location(stagingUri(uuid, filepath))
			.build();
	}

	try( InputStream bd = data )
	{
		checkValidContentType(contentType);
		FileInfo info = fileSystemService.write(stagingFile, filepath, bd, false, true);

		if( !Check.isEmpty(unzipTo) )
		{
			fileSystemService.mkdir(stagingFile, unzipTo);
			info = fileSystemService.unzipFile(stagingFile, filepath, unzipTo);
		}

		return Response.ok().header(HttpHeaders.ETAG, "\"" + info.getMd5CheckSum() + "\"")
			.location(stagingUri(uuid, filepath)).build();
	}
	catch( IOException e )
	{
		throw Throwables.propagate(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:36,代码来源:StagingResourceImpl.java

示例10: ConstraintViolationMapper

public ConstraintViolationMapper() {
  super(Status.BAD_REQUEST);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:3,代码来源:ConstraintViolationMapper.java

示例11: ValidationExceptionMapper

public ValidationExceptionMapper() {
  super(Status.BAD_REQUEST);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:3,代码来源:ValidationExceptionMapper.java

示例12: IllegalArgumentMapper

public IllegalArgumentMapper() {
  super(Status.BAD_REQUEST);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:3,代码来源:IllegalArgumentMapper.java

示例13: CheckedExceptionMapper

public CheckedExceptionMapper() {
  super(Status.BAD_REQUEST);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:3,代码来源:CheckedExceptionMapper.java

示例14: BadValueMapper

public BadValueMapper() {
  super(Status.BAD_REQUEST);
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:3,代码来源:BadValueMapper.java

示例15: getStatus

@Override
public Status getStatus() {
    return Status.BAD_REQUEST;
}
 
开发者ID:appstatus,项目名称:appstatus-spring-boot-starter,代码行数:4,代码来源:ApiBadRequest.java


注:本文中的javax.ws.rs.core.Response.Status.BAD_REQUEST属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。