本文整理汇总了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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}