本文整理汇总了Java中org.eclipse.jetty.http.HttpMethod.PUT属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.PUT属性的具体用法?Java HttpMethod.PUT怎么用?Java HttpMethod.PUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jetty.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.PUT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifyBlockOperation
@Endpoint(method = HttpMethod.PUT, path = "/op/:uuid", perm = "op.change")
public void modifyBlockOperation(ServletData data, UUID uuid) {
JsonNode reqJson = data.getRequestBody();
// Check block op
Optional<IBlockOperation> op = blockService.getBlockOperation(uuid);
if (!op.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Block opeartion with UUID '" +
uuid + "' could not be found");
return;
}
if (reqJson.get("pause").asBoolean()) {
op.get().pause();
} else {
op.get().start();
}
data.addData("ok", true, false);
data.addData("operation", op, true);
}
示例2: changeCrate
@Endpoint(method = HttpMethod.PUT, path = "crate/:id", perm = "crate.change")
public void changeCrate(IServletData data, String id) {
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> optRes = WebAPIAPI.runOnMain(() -> {
try {
VirtualCrate oldCrate = plugin.crateUtilities.getVirtualCrate(id);
if (oldCrate == null) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Crate not found");
return null;
}
req.setId(oldCrate.id);
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) {
e.printStackTrace();
return null;
}
});
data.addData("ok", optRes.isPresent(), false);
data.addData("crate", optRes.orElse(null), true);
}
示例3: changeTicket
@Endpoint(method = HttpMethod.PUT, path = "/ticket/:id", perm = "change")
public void changeTicket(IServletData data, Integer id) {
Main plugin = getMMCTicketsPlugin(data);
if (plugin == null) return;
Optional<ChangeTicketRequest> optReq = data.getRequestBody(ChangeTicketRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid ticket data: " + data.getLastParseError().getMessage());
return;
}
ChangeTicketRequest req = optReq.get();
Optional<CachedTicketData> optTicket = WebAPIAPI.runOnMain(() -> {
TicketData ticketData = plugin.getTicket(id);
if (ticketData == null) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Ticket not found");
return null;
}
if (req.getComment() != null) {
ticketData.setComment(req.getComment());
}
if (req.getNotified() != null) {
ticketData.setNotified(req.getNotified());
}
if (req.getStatus() != null) {
ticketData.setStatus(req.getStatus());
}
return new CachedTicketData(ticketData);
});
data.addData("ok", optTicket.isPresent(), false);
data.addData("ticket", optTicket.orElse(null), true);
}
示例4: changeWebBook
@Endpoint(method = HttpMethod.PUT, path = "/book/:id", perm = "book.change")
public void changeWebBook(IServletData data, String id) {
WebBook book = books.get(id);
if (book == null) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Book not found");
return;
}
JsonNode body = data.getRequestBody();
String title = book.getTitle();
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()));
}
book = new WebBook(id, title, lines);
books.put(id, book);
saveBooks();
data.addData("ok", true, false);
data.addData("book", book, true);
}
示例5: changeJail
@Endpoint(method = HttpMethod.PUT, path = "jail/:name", perm = "jail.change")
public void changeJail(IServletData data) {
data.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "Not implemented");
}
示例6: changeKit
@Endpoint(method = HttpMethod.PUT, path = "kit/:name", perm = "kit.change")
public void changeKit(IServletData data, String name) {
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<BaseKitRequest> optReq = data.getRequestBody(BaseKitRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid kit data: " + data.getLastParseError().getMessage());
return;
}
BaseKitRequest req = optReq.get();
Optional<CachedKit> optRes = WebAPIAPI.runOnMain(() -> {
Optional<Kit> optKit = srv.getKit(name);
if (!optKit.isPresent()) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Kit not found");
return null;
}
Kit kit = optKit.get();
if (req.hasCost()) {
kit.setCost(req.getCost());
}
if (req.hasCooldown()) {
kit.setCooldown(req.getCooldown());
}
if (req.hasCommands()) {
kit.setCommands(req.getCommands());
}
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;
}
}
srv.saveKit(kit);
return new CachedKit(kit);
});
data.addData("ok", optRes.isPresent(), false);
data.addData("kit", optRes.orElse(null), true);
}
示例7: updateWorld
@Endpoint(method = HttpMethod.PUT, path = "/:world", perm = "change")
public void updateWorld(ServletData data, CachedWorld world) {
Optional<UpdateWorldRequest> optReq = data.getRequestBody(UpdateWorldRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid world data: " + data.getLastParseError().getMessage());
return;
}
final UpdateWorldRequest req = optReq.get();
Optional<ICachedWorld> resWorld = WebAPI.runOnMain(() -> {
Optional<World> optLive = world.getLive();
Optional<WorldProperties> optProps = world.getLiveProps();
if (!optProps.isPresent())
return null;
World live = optLive.orElse(null);
WorldProperties props = optProps.get();
if (req.isLoaded() != null && req.isLoaded() != world.isLoaded()) {
if (req.isLoaded()) {
Optional<World> newWorld = Sponge.getServer().loadWorld(props);
if (newWorld.isPresent()) {
live = newWorld.get();
props = newWorld.get().getProperties();
}
} else if (live != null) {
Sponge.getServer().unloadWorld(live);
Optional<WorldProperties> newProps = Sponge.getServer().getUnloadedWorlds()
.stream().filter(w -> w.getUniqueId().equals(world.getUUID())).findAny();
if (newProps.isPresent()) {
live = null;
props = optProps.get();
}
} else {
WebAPI.getLogger().warn("World should be unloaded but isn't present");
return null;
}
}
if (req.getGameRules() != null) {
for (Map.Entry<String, String> entry : req.getGameRules().entrySet()) {
props.setGameRule(entry.getKey(), entry.getValue());
}
}
req.getGeneratorType().ifPresent(props::setGeneratorType);
req.getGameMode().ifPresent(props::setGameMode);
req.getDifficulty().ifPresent(props::setDifficulty);
if (req.getSeed() != null) {
props.setSeed(req.getSeed());
}
if (req.doesLoadOnStartup() != null) {
props.setLoadOnStartup(req.doesLoadOnStartup());
}
if (req.doesKeepSpawnLoaded() != null) {
props.setKeepSpawnLoaded(req.doesKeepSpawnLoaded());
}
if (req.doesAllowCommands() != null) {
props.setCommandsAllowed(req.doesAllowCommands());
}
if (req.doesUseMapFeatures() != null) {
props.setMapFeaturesEnabled(req.doesUseMapFeatures());
}
if (live != null)
return cacheService.updateWorld(live);
else
return cacheService.updateWorld(props);
});
data.addData("ok", resWorld.isPresent(), false);
data.addData("world", resWorld.orElse(null), true);
}
示例8: updateEntity
@Endpoint(method = HttpMethod.PUT, path = "/:entity", perm = "change")
public void updateEntity(ServletData data, CachedEntity entity) {
Optional<UpdateEntityRequest> optReq = data.getRequestBody(UpdateEntityRequest.class);
if (!optReq.isPresent()) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid entity data: " + data.getLastParseError().getMessage());
return;
}
final UpdateEntityRequest req = optReq.get();
Optional<ICachedEntity> resEntity = WebAPI.runOnMain(() -> {
Optional<Entity> optLive = entity.getLive();
if (!optLive.isPresent())
return null;
Entity live = optLive.get();
if (req.getWorld().isPresent()) {
Optional<World> optWorld = req.getWorld().get().getLive();
if (!optWorld.isPresent())
return null;
if (req.getPosition() != null) {
live.transferToWorld(optWorld.get(), req.getPosition());
} else {
live.transferToWorld(optWorld.get());
}
} else if (req.getPosition() != null) {
live.setLocation(new Location<>(live.getWorld(), req.getPosition()));
}
if (req.getVelocity() != null) {
live.setVelocity(req.getVelocity());
}
if (req.getRotation() != null) {
live.setRotation(req.getRotation());
}
if (req.getScale() != null) {
live.setRotation(req.getScale());
}
if (req.getDamage() != null) {
DamageRequest dmgReq = req.getDamage();
DamageSource.Builder builder = DamageSource.builder();
if (dmgReq.getDamageType().isPresent())
builder.type(dmgReq.getDamageType().get());
live.damage(req.getDamage().getAmount(), builder.build());
}
if (req.hasInventory()) {
if (!(live instanceof Carrier)) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Entity does not have an inventory!");
return null;
}
try {
Inventory inv = ((Carrier) live).getInventory();
inv.clear();
for (ItemStack stack : req.getInventory()) {
inv.offer(stack);
}
} catch (Exception e) {
return null;
}
}
return cacheService.updateEntity(live);
});
data.addData("ok", resEntity.isPresent(), false);
data.addData("entity", resEntity.orElse(null), true);
}