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


Java BadRequestException类代码示例

本文整理汇总了Java中javax.ws.rs.BadRequestException的典型用法代码示例。如果您正苦于以下问题:Java BadRequestException类的具体用法?Java BadRequestException怎么用?Java BadRequestException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: deleteQueue

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
public Response deleteQueue(String queueName, Boolean ifUnused, Boolean ifEmpty) {
    if (Objects.isNull(ifUnused)) {
        ifUnused = true;
    }

    if (Objects.isNull(ifEmpty)) {
        ifEmpty = true;
    }

    try {
        if (broker.deleteQueue(queueName, ifUnused, ifEmpty)) {
            return Response.ok().build();
        } else {
            throw new NotFoundException("Queue " + queueName + " doesn't exist.");
        }
    } catch (BrokerException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:20,代码来源:QueuesApiDelegate.java

示例2: make

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@POST
@Path("/meeting")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public Reservation make(Reservation reservation) {
	if (reservation.getId() != null)
		throw new BadRequestException(MessageFormat.format(ERROR_RESERVATION_IS_EXISTS_FMT, reservation.getId()));
	Set<Reservation> alreadyMadeReservations = reservationDao.getReservations(
			reservation.getVenue(), 
			reservation.getDate(), 
			reservation.getStartTime(),
			reservation.getDuration());
	if (alreadyMadeReservations != null && !alreadyMadeReservations.isEmpty())
		throw new BadRequestException(MessageFormat.format(ERROR_RESERVATION_CONFLICT_FMT, reservation.getVenue()));
	
	return reservationDao.createNew(reservation);
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:18,代码来源:MeetingBookingService.java

示例3: readFrom

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Override
public Object readFrom(
        final Class<Object> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType,
        final MultivaluedMap<String, String> httpHeaders,
        final InputStream entityStream)
                throws IOException {

    try {
        return objectMapper.readValue(entityStream, type);
    } catch (final JsonProcessingException ex) {
        throw new BadRequestException(ex.getMessage(), ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:17,代码来源:MinijaxJsonReader.java

示例4: updateCombItem

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
/**
 * Updates an existing content element in a comb of a user
 * @param userId of the user to update the comb element
 * @param contentId of the element in the comb of the user
 * @param item Data to change
 * @param con Connection to use - is injected automatically
 * @return the updated {@link CombItemModel}
 */
@PUT
public Response updateCombItem(@PathParam("userId") final long userId, @PathParam("contentId") final long contentId,
		final CombItemModel item, @Context final Connection con) {
	if(userId != item.getUserId()) {
		throw new BadRequestException("Different userIds.");
	}

	if(contentId != item.getContentId()) {
		throw new BadRequestException("Different contentIds.");
	}

	getAccessChecker().checkLoggedInUser(userId);

	new CombItemDao(con).updateCombItem(item);
	return ok(item);
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:25,代码来源:CombItemService.java

示例5: testFormFailsIfRequiredBooleanIsNotBoolean

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Test(expected = BadRequestException.class)
public void testFormFailsIfRequiredBooleanIsNotBoolean() {
	Builder<Map<String, Object>> builder = new Builder<>(emptyList());

	Form<Map<String, Object>> form = builder.title(
		__ -> "title"
	).description(
		__ -> "description"
	).constructor(
		HashMap::new
	).addRequiredBoolean(
		"long1", (map, string) -> map.put("l1", string)
	).build();

	form.get(_body);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:17,代码来源:FormTest.java

示例6: updateGraph

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
private List<Triple> updateGraph(final Resource res, final IRI graphName) {
    final List<Triple> triples;
    // Update existing graph
    try (final TrellisGraph graph = TrellisGraph.createGraph()) {
        try (final Stream<? extends Triple> stream = res.stream(graphName)) {
            stream.forEachOrdered(graph::add);
        }
        ioService.update(graph.asGraph(), sparqlUpdate, TRELLIS_PREFIX + req.getPath() +
                (ACL.equals(req.getExt()) ? "?ext=acl" : ""));
        triples = graph.stream().collect(toList());
    } catch (final RuntimeTrellisException ex) {
        LOGGER.warn(ex.getMessage());
        throw new BadRequestException("Invalid RDF: " + ex.getMessage());
    }

    return triples;
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:18,代码来源:PatchHandler.java

示例7: makePost

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
/**
 * Wrap the supplied element in a SOAP wrapper and post to the specified end-point
 *
 * @return Response from the remote server
 * @throws SOAPRequestError            if the remote server returns a non-200 status code
 * @throws ResponseProcessingException in case processing of a received HTTP response fails (e.g. in a filter
 *                                     or during conversion of the response entity data to an instance
 *                                     of a particular Java type).
 * @throws ProcessingException         in case the request processing or subsequent I/O operation fails.
 */
protected SoapResponse makePost(URI uri, Element requestElement) throws SOAPRequestError {
    LOG.info(format("Making SOAP request to: {0}", uri));

    Document requestDocument = soapMessageManager.wrapWithSoapEnvelope(requestElement);
    WebTarget target = client.target(uri);
    final Invocation.Builder request = target.request();
    final Response response = request.post(Entity.entity(requestDocument, MediaType.TEXT_XML_TYPE));

    try {
        if (response.getStatus() != 200) {
            LOG.warn(format("Unexpected status code ({0}) when contacting ({1}))", response.getStatus(), uri));
            // let the calling code handle this issue appropriately
            throw new SOAPRequestError(response);
        } else {
            try {
                return giveMeMySoap(response);
            } catch(BadRequestException e) {
                LOG.warn(format("Couldn't parse SOAP response when contacting ({0}))", uri), e);
                throw new SOAPRequestError(response, e);
            }
        }
    } finally {
        // Ensure that response's input stream has been closed.  This may not happen automatically in some cases
        // (e.g. the response body is never read from).
        try {
            response.close();
        } catch (ProcessingException f) {
            LOG.warn("Problem closing Jersey connection.", f);
        }
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:42,代码来源:SoapRequestClient.java

示例8: makePost_checkSOAPRequestErrorIsThrownWhenNotValidXML

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Test
public void makePost_checkSOAPRequestErrorIsThrownWhenNotValidXML() throws Exception {
    when(webResourceBuilder.post(any(Entity.class))).thenReturn(response);
    when(response.readEntity(Document.class)).thenThrow(new BadRequestException());
    when(response.getStatus()).thenReturn(200);
    Element matchingServiceRequest = XmlUtils.convertToElement("<someElement/>");
    URI matchingServiceUri = new URI("http://heyyeyaaeyaaaeyaeyaa.com/abc1");

    try {
        soapRequestClient.makeSoapRequest(matchingServiceRequest, matchingServiceUri);
        fail("Exception should have been thrown");
    }
    catch(SOAPRequestError e) {
    }
    finally {
        verify(response).readEntity(Document.class);
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:19,代码来源:SoapRequestClientTest.java

示例9: getStreamsByGame

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
/**
 * Filter streams/channels by game and by language.
 * Passes the JSON response to a Java object for easier use.
 *
 * @param game     the game to get the channels for
 * @param language filter all channels by language
 * @return a list of the channels currently streaming for a given game + language
 * @throws IOException
 */
public Set<String> getStreamsByGame(final String game, final String language) throws IOException {
    /*
    TODO: maybe handle the case for "all" languages
    TODO: make this run in its own thread. See java.util.concurrency
    TODO: organize the API better. This function is weak.
     */
    StringBuilder urlBuilder = new StringBuilder();
    urlBuilder.append(STREAM_ENDPOINT)
            .append(QUESTION_MARK)
            .append(GAME_PARAM)
            .append(EQUALS)
            .append(game);

    if (language != null) {
        urlBuilder.append(AMPERSAND)
                .append(LANG_PARAM)
                .append(EQUALS)
                .append(language);
    }

    String urlString = urlBuilder.toString();
    URL url = new URL(urlString);
    HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
    con.setRequestProperty(CLIENT_ID_HEADER, clientId);

    if (con.getResponseCode() != Constants.RESPONSE_OK) {
        throw new BadRequestException(BAD_CLIENT_ID + clientId);
    }

    channels = mapper.readValue(con.getInputStream(), ChannelContainer.class);
    return channels.getChannels();
}
 
开发者ID:agapic,项目名称:Twitch-Streamer,代码行数:42,代码来源:TwitchApi.java

示例10: startMultipart

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Override
public MultipartBean startMultipart(String uuid, String filepath, Boolean uploads)
{
	if( uploads == null )
	{
		throw new BadRequestException("Must use PUT for uploading files");
	}
	StagingFile stagingFile = getStagingFile(uuid);
	String uploadId = UUID.randomUUID().toString();
	String folderPath = "multipart/" + uploadId;
	ensureMultipartDir(stagingFile);
	try
	{
		fileSystemService.mkdir(stagingFile, folderPath);
		return new MultipartBean(uploadId);
	}
	catch( Exception e )
	{
		throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:StagingResourceImpl.java

示例11: login

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
/**
 * Logs in the user with email address and password.
 * Returns the user on success.
 *
 * @param email The user's email address.
 * @param password The user's plain text password.
 * @return the user details.
 */
public NewCookie login(final String email, final String password) {
    final SecurityUser candidate = dao.findUserByEmail(userClass, email);
    if (candidate == null) {
        throw new BadRequestException("notfound");
    }

    if (candidate.getPasswordHash() == null) {
        throw new BadRequestException("invalid");
    }

    if (!BCrypt.checkpw(password, candidate.getPasswordHash())) {
        throw new BadRequestException("incorrect");
    }

    return loginAs(candidate);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:Security.java

示例12: changePassword

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
/**
 * Changes the current user's password.
 *
 * @param oldPassword The old password.
 * @param newPassword The new password.
 * @param confirmNewPassword The confirmed new password.
 */
public void changePassword(final String oldPassword, final String newPassword, final String confirmNewPassword) {
    requireLogin();

    if (user.getPasswordHash() == null) {
        throw new BadRequestException("unset");
    }

    if (!BCrypt.checkpw(oldPassword, user.getPasswordHash())) {
        throw new BadRequestException("incorrect");
    }

    if (!newPassword.equals(confirmNewPassword)) {
        throw new BadRequestException("mismatch");
    }

    if (newPassword.length() < MINIMUM_PASSWORD_LENGTH) {
        throw new BadRequestException("short");
    }

    user.setPassword(newPassword);
    dao.update(user);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:30,代码来源:Security.java

示例13: testFormFailsIfRequiredDoubleIsNotDouble

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Test(expected = BadRequestException.class)
public void testFormFailsIfRequiredDoubleIsNotDouble() {
	Builder<Map<String, Object>> builder = new Builder<>(emptyList());

	Form<Map<String, Object>> form = builder.title(
		__ -> "title"
	).description(
		__ -> "description"
	).constructor(
		HashMap::new
	).addRequiredDouble(
		"long1", (map, string) -> map.put("l1", string)
	).build();

	form.get(_body);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:17,代码来源:FormTest.java

示例14: testInvalidSessionToken

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Test(expected = BadRequestException.class)
public void testInvalidSessionToken() {
    final User user = new User();

    final UserSession session = new UserSession();
    session.setUser(user);

    final String cookie = session.getId().toString();

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.read(eq(UserSession.class), eq(session.getId()))).thenReturn(session);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);

    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);

    final Security<User> security = new Security<>(dao, config, null, cookie);
    security.validateSession("not-the-right-token");
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:SecurityTest.java

示例15: testFormFailsIfRequiredIsNotPresent

import javax.ws.rs.BadRequestException; //导入依赖的package包/类
@Test(expected = BadRequestException.class)
public void testFormFailsIfRequiredIsNotPresent() {
	Builder<Map<String, Object>> builder = new Builder<>(emptyList());

	Form<Map<String, Object>> form = builder.title(
		__ -> "title"
	).description(
		__ -> "description"
	).constructor(
		HashMap::new
	).addRequiredString(
		"string1", (map, string) -> map.put("s1", string)
	).addRequiredString(
		"string3", (map, string) -> map.put("s2", string)
	).build();

	form.get(_body);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:19,代码来源:FormTest.java


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