本文整理汇总了Java中org.eclipse.jetty.http.HttpMethod.POST属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.POST属性的具体用法?Java HttpMethod.POST怎么用?Java HttpMethod.POST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jetty.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.POST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWebBookContent
@Endpoint(method = HttpMethod.GET, path = "/book/:id/html")
@Endpoint(method = HttpMethod.POST, path = "/book/:id/html")
public void getWebBookContent(IServletData data, String id) {
WebBook book = books.get(id);
if (book == null) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Book not found");
return;
}
try {
data.setContentType("text/html; charset=utf-8");
data.getOutputStream().write(book.getHtml().getBytes(Charset.forName("UTF-8")));
data.setDone();
} catch (IOException e) {
e.printStackTrace();
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not display web book");
}
}
示例2: executeMethod
@Endpoint(method = HttpMethod.POST, path = "/:world/method", perm = "method")
public void executeMethod(ServletData data, CachedWorld world) {
JsonNode reqJson = data.getRequestBody();
if (!reqJson.has("method")) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request must define the 'method' property");
return;
}
String mName = reqJson.get("method").asText();
Optional<Tuple<Class[], Object[]>> params = Util.parseParams(reqJson.get("params"));
if (!params.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters");
return;
}
Optional<Object> res = cacheService.executeMethod(world, mName, params.get().getFirst(), params.get().getSecond());
if (!res.isPresent()) {
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get world");
return;
}
data.addData("ok", true, false);
data.addData("world", world, true);
data.addData("result", res.get(), true);
}
示例3: createChunkAt
@Endpoint(method = HttpMethod.POST, path = "/:world/chunk/:x/:z", perm = "chunk.create")
public void createChunkAt(ServletData data, CachedWorld world, int x, int z) {
Optional<CachedChunk> optChunk = WebAPI.runOnMain(() -> {
Optional<World> optLive = world.getLive();
if (!optLive.isPresent())
return null;
World live = optLive.get();
Optional<Chunk> chunk = live.loadChunk(x, 0, z, true);
return chunk.map(CachedChunk::new).orElse(null);
});
if (optChunk.isPresent()) {
data.setStatus(HttpServletResponse.SC_CREATED);
data.setHeader("Location", optChunk.get().getLink());
}
data.addData("ok", optChunk.isPresent(), false);
data.addData("chunk", optChunk.orElse(null), true);
}
示例4: sendMessage
@Endpoint(method = HttpMethod.POST, path = "/", perm = "create")
public void sendMessage(ServletData data) {
Optional<Message> optMsg = data.getRequestBody(Message.class);
if (!optMsg.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid message");
return;
}
Message msg = optMsg.get();
if (msg.getTarget() == null && (msg.getTargets() == null || msg.getTargets().size() == 0)) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "You need to specify either a " +
"single target or a list of targets");
return;
}
boolean allSent = messageService.sendMessage(msg);
if (allSent) {
data.setStatus(HttpServletResponse.SC_CREATED);
data.setHeader("Location", msg.getLink());
}
data.addData("ok", allSent, false);
data.addData("message", msg, true);
}
示例5: authUser
@Endpoint(method = HttpMethod.POST, path = "/")
public void authUser(ServletData data) {
Optional<AuthRequest> optReq = data.getRequestBody(AuthRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid auth data: " + data.getLastParseError().getMessage());
return;
}
AuthRequest req = optReq.get();
Optional<UserPermission> optPerm = Users.getUser(req.getUsername(), req.getPassword());
if (!optPerm.isPresent()) {
data.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid username / password");
return;
}
UserPermission perm = optPerm.get();
String key = Util.generateUniqueId();
WebAPI.getAuthHandler().addTempPerm(key, perm);
data.addData("ok", true, false);
data.addData("key", key, false);
data.addData("user", perm, false);
}
示例6: executeMethod
@Endpoint(method = HttpMethod.POST, path = "/:entity/method", perm = "method")
public void executeMethod(ServletData data, CachedEntity entity) {
final JsonNode reqJson = data.getRequestBody();
if (!reqJson.has("method")) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request must define the 'method' property");
return;
}
String mName = reqJson.get("method").asText();
Optional<Tuple<Class[], Object[]>> params = Util.parseParams(reqJson.get("params"));
if (!params.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters");
return;
}
Optional<Object> res = cacheService.executeMethod(entity, mName, params.get().getFirst(), params.get().getSecond());
if (!res.isPresent()) {
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get entity");
return;
}
data.addData("ok", true, false);
data.addData("entity", entity, true);
data.addData("result", res.get(), true);
}
示例7: setProperties
@Endpoint(method = HttpMethod.POST, path = "/properties", perm = "properties.set")
public void setProperties(ServletData data) {
ServerService srv = WebAPI.getServerService();
JsonNode body = data.getRequestBody();
JsonNode props = body.get("properties");
if (props == null) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid new properties");
return;
}
for (Iterator<String> it = props.fieldNames(); it.hasNext(); ) {
String key = it.next();
srv.setProperty(key, props.get(key).asText());
}
data.addData("ok", true, false);
data.addData("properties", srv.getProperties(), true);
}
示例8: createCrate
@Endpoint(method = HttpMethod.POST, path = "crate", perm = "crate.create")
public void createCrate(IServletData data) {
HuskyCrates plugin = getHuskyPlugin(data);
if (plugin == null) return;
Optional<CachedVirtualCrate> optReq = data.getRequestBody(CachedVirtualCrate.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid crate data: " + data.getLastParseError().getMessage());
return;
}
CachedVirtualCrate req = optReq.get();
Optional<CachedVirtualCrate> optCrate = WebAPIAPI.runOnMain(() -> {
try {
saveCrate(plugin.crateConfig, req);
plugin.crateUtilities.generateVirtualCrates(plugin.crateConfig);
VirtualCrate crate = plugin.crateUtilities.getVirtualCrate(req.getId());
if (crate == null)
return null;
return new CachedVirtualCrate(crate);
} catch (IOException e) {
return null;
}
});
data.addData("ok", optCrate.isPresent(), false);
data.addData("crate", optCrate.orElse(null), true);
}
示例9: createWebBook
@Endpoint(method = HttpMethod.POST, path = "/book", perm = "book.create")
public void createWebBook(IServletData data) {
JsonNode body = data.getRequestBody();
if (!body.has("id")) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "A book needs at least an id");
return;
}
String id = body.get("id").asText();
if (id.isEmpty()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "A book needs a non-empty id");
return;
}
if (books.containsKey(id)) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "A book with this id already exists");
return;
}
String title = "";
if (body.has("title")) {
title = body.get("title").asText();
}
List<String> lines = new ArrayList<>();
if (body.has("lines")) {
body.get("lines").forEach(n -> lines.add(n.asText()));
}
WebBook book = new WebBook(id, title, lines);
books.put(id, book);
saveBooks();
data.addData("ok", true, false);
data.addData("book", book, true);
}
示例10: executeMethod
@Endpoint(method = HttpMethod.POST, path = "/:player/method", perm = "method")
public void executeMethod(ServletData data) {
String uuid = data.getPathParam("player");
if (uuid.split("-").length != 5) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid player UUID");
return;
}
Optional<ICachedPlayer> player = cacheService.getPlayer(UUID.fromString(uuid));
if (!player.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Player with UUID '" + uuid + "' could not be found");
return;
}
final JsonNode reqJson = data.getRequestBody();
if (!reqJson.has("method")) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request must define the 'method' property");
return;
}
String mName = reqJson.get("method").asText();
Optional<Tuple<Class[], Object[]>> params = Util.parseParams(reqJson.get("params"));
if (!params.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters");
return;
}
Optional<Object> res = cacheService.executeMethod(player.get(), mName, params.get().getFirst(), params.get().getSecond());
if (!res.isPresent()) {
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get world");
return;
}
data.addData("ok", true, false);
data.addData("player", player.get(), true);
data.addData("result", res.get(), true);
}
示例11: executeMethod
@Endpoint(method = HttpMethod.POST, path = "/:world/:x/:y/:z/method", perm = "method")
public void executeMethod(ServletData data, CachedWorld world, int x, int y, int z) {
Optional<ICachedTileEntity> te = cacheService.getTileEntity(world, x, y, z);
if (!te.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Tile entity in world '" + world.getName() + "' at [" + x + "," + y + "," + z + "] could not be found");
return;
}
final JsonNode reqJson = data.getRequestBody();
if (!reqJson.has("method")) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request must define the 'method' property");
return;
}
String mName = reqJson.get("method").asText();
Optional<Tuple<Class[], Object[]>> params = Util.parseParams(reqJson.get("params"));
if (!params.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters");
return;
}
Optional<Object> res = cacheService.executeMethod(te.get(), mName, params.get().getFirst(), params.get().getSecond());
if (!res.isPresent()) {
data.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get tile entity");
return;
}
data.addData("ok", true, false);
data.addData("tileEntity", te.get(), true);
data.addData("result", res.get(), true);
}
示例12: createJail
@Endpoint(method = HttpMethod.POST, path = "jail", perm = "jail.create")
public void createJail(IServletData data) {
Optional<NucleusJailService> optSrv = NucleusAPI.getJailService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues jail service not available");
return;
}
NucleusJailService srv = optSrv.get();
Optional<CreateJailRequest> optReq = data.getRequestBody(CreateJailRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid jail data: " + data.getLastParseError().getMessage());
return;
}
CreateJailRequest req = optReq.get();
if (!req.getWorld().isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid world provided");
return;
}
ICachedWorld world = req.getWorld().get();
if (req.getPosition() == null) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid position provided");
return;
}
Optional<CachedNamedLocation> optRes = WebAPIAPI.runOnMain(() -> {
Optional<World> optWorld = world.getLive();
if (!optWorld.isPresent())
return null;
World w = optWorld.get();
srv.setJail(req.getName(), new Location<>(w, req.getPosition()), req.getRotation());
Optional<NamedLocation> optJail = srv.getJail(req.getName());
return optJail.map(CachedNamedLocation::new).orElse(null);
});
data.setStatus(HttpServletResponse.SC_CREATED);
data.addData("ok", optRes.isPresent(), false);
data.addData("jail", optRes.orElse(null), true);
}
示例13: createKit
@Endpoint(method = HttpMethod.POST, path = "kit", perm = "kit.create")
public void createKit(IServletData data) {
Optional<NucleusKitService> optSrv = NucleusAPI.getKitService();
if (!optSrv.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Nuclues kit service not available");
return;
}
NucleusKitService srv = optSrv.get();
Optional<CreateKitRequest> optReq = data.getRequestBody(CreateKitRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit data: " + data.getLastParseError().getMessage());
return;
}
CreateKitRequest req = optReq.get();
if (req.getName().isEmpty()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit name");
return;
}
Optional<CachedKit> resKit = WebAPIAPI.runOnMain(() -> {
Kit kit = srv.createKit(req.getName());
kit.setCost(req.getCost());
kit.setCooldown(req.getCooldown());
if (req.hasStacks()) {
try {
kit.setStacks(req.getStacks().stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
} catch (Exception e) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not process item stack: " + e.getMessage());
return null;
}
}
if (req.hasCommands()) {
kit.setCommands(req.getCommands());
}
srv.saveKit(kit);
return new CachedKit(kit);
});
data.addData("ok", resKit.isPresent(), false);
data.addData("kit", resKit.orElse(null), true);
}
示例14: createWorld
@Endpoint(method = HttpMethod.POST, path = "/", perm = "create")
public void createWorld(ServletData data) {
WorldArchetype.Builder builder = WorldArchetype.builder();
Optional<CreateWorldRequest> optReq = data.getRequestBody(CreateWorldRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid world data: " + data.getLastParseError().getMessage());
return;
}
CreateWorldRequest req = optReq.get();
if (req.getName().isEmpty()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No name provided");
return;
}
req.getDimensionType().ifPresent(builder::dimension);
req.getGeneratorType().ifPresent(builder::generator);
req.getGameMode().ifPresent(builder::gameMode);
req.getDifficulty().ifPresent(builder::difficulty);
if (req.getSeed() != null) {
builder.seed(req.getSeed());
}
if (req.doesLoadOnStartup() != null) {
builder.loadsOnStartup(req.doesLoadOnStartup());
}
if (req.doesKeepSpawnLoaded() != null) {
builder.keepsSpawnLoaded(req.doesKeepSpawnLoaded());
}
if (req.doesAllowCommands() != null) {
builder.commandsAllowed(req.doesAllowCommands());
}
if (req.doesGenerateBonusChest() != null) {
builder.generateBonusChest(req.doesGenerateBonusChest());
}
if (req.doesUseMapFeatures() != null) {
builder.usesMapFeatures(req.doesUseMapFeatures());
}
String archTypeName = UUID.randomUUID().toString();
WorldArchetype archType = builder.enabled(true).build(archTypeName, archTypeName);
Optional<ICachedWorld> resWorld = WebAPI.runOnMain(() -> {
try {
WorldProperties props = Sponge.getServer().createWorldProperties(req.getName(), archType);
return cacheService.updateWorld(props);
} catch (IOException e) {
data.addData("ok", false, false);
data.addData("error", e, false);
return null;
}
});
if (!resWorld.isPresent())
return;
data.setStatus(HttpServletResponse.SC_CREATED);
data.setHeader("Location", resWorld.get().getLink());
data.addData("ok", true, false);
data.addData("world", resWorld.get(), true);
}
示例15: createEntity
@Endpoint(method = HttpMethod.POST, path = "/", perm = "create")
public void createEntity(ServletData data) {
Optional<CreateEntityRequest> optReq = data.getRequestBody(CreateEntityRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid entity data: " + data.getLastParseError().getMessage());
return;
}
CreateEntityRequest req = optReq.get();
Optional<ICachedWorld> optWorld = req.getWorld();
if (!optWorld.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid world provided");
return;
}
Optional<EntityType> optEntType = req.getEntityType();
if (!optEntType.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid entity type provided");
return;
}
if (req.getPosition() == null) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid position provided");
return;
}
Optional<ICachedEntity> resEntity = WebAPI.runOnMain(() -> {
Optional<World> optLive = optWorld.get().getLive();
if (!optLive.isPresent())
return null;
World w = optLive.get();
Entity e = w.createEntity(optEntType.get(), req.getPosition());
if (w.spawnEntity(e)) {
return cacheService.updateEntity(e);
} else {
e.remove();
return null;
}
});
if (!resEntity.isPresent()) {
data.addData("ok", false, false);
return;
}
data.setStatus(HttpServletResponse.SC_CREATED);
data.setHeader("Location", resEntity.get().getLink());
data.addData("ok", true, false);
data.addData("entity", resEntity.get(), true);
}