本文整理汇总了Java中org.restlet.ext.jackson.JacksonRepresentation类的典型用法代码示例。如果您正苦于以下问题:Java JacksonRepresentation类的具体用法?Java JacksonRepresentation怎么用?Java JacksonRepresentation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JacksonRepresentation类属于org.restlet.ext.jackson包,在下文中一共展示了JacksonRepresentation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPKCS11config
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
protected Representation addPKCS11config(String platform, List<String> config, User user) {
switch (platform) {
case "linux":
config.add("pkcs11-providers /usr/lib/libbeidpkcs11.so");
config.add("pkcs11-id \"Belgium Government/Belgium eID/" + user.certId.substring(16) + "/BELPIC/0200000000000000\"");
break;
case "osx":
config.add("pkcs11-providers /usr/local/lib/beid-pkcs11.bundle/Contents/MacOS/libbeidpkcs11.dylib");
config.add("pkcs11-id \"Belgium Government/Belgium eID/" + user.certId.substring(16) + "/BELPIC/0200000000000000\"");
break;
case "windows":
config.add("pkcs11-providers C:\\\\WINDOWS\\\\system32\\\\beidpkcs11.dll");
config.add("pkcs11-id \"Belgium Government/Belgium eID/" + user.certId.substring(16) + "/BELPIC/02000000\"");
break;
default:
return new JacksonRepresentation(new ClientError("ILLEGAL_PLATFORM_TYPE"));
}
return null;
}
示例2: getAssignedLeases
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Get
public Representation getAssignedLeases() {
try {
if (getRequestAttributes().containsKey("id")) {
return new JacksonRepresentation<>(IPAddresses.dao.queryForId(getAttribute("id")));
}
HashMap<Client, List<IPAddress>> map = new HashMap<>();
List<Client> clients = Clients.dao.queryForAll();
for (Client c : clients) {
map.put(c, IPAddresses.dao.queryForEq("client_id", c.id));
}
return new JacksonRepresentation(map);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to get assigned leases", ex);
}
return DEFAULT_ERROR;
}
示例3: updateLease
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Post
public Representation updateLease(IPAddress addr) {
if (!getRequestAttributes().containsKey("id"))
return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
if (addr == null) return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
try {
IPAddress ip = IPAddresses.dao.queryForId(getAttribute("id"));
mergeUpdate(ip, addr);
IPAddresses.dao.update(ip);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to update subnet lease", ex);
}
return new JacksonRepresentation<>(addr);
}
示例4: get
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Get
public Representation get() {
if (getQueryValue("zones") != null) {
return new JacksonRepresentation<>(DNSRecords.getZoneMapping());
}
if (!getRequestAttributes().containsKey("zone")) {
return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
}
DNSRecords.getDaoForZone(getAttribute("zone")).orElseThrow(() -> new IllegalArgumentException("Invalid zone"));
Dao<DNSRecord, String> dao = DNSRecords.getDaoForZone(getAttribute("zone")).get();
try {
return new JacksonRepresentation<>(
dao.queryForAll()
.parallelStream()
.filter((record) -> Policy.get().canModify(getLoggedInUser(), record))
.collect(Collectors.toList())
);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to get user DNS records", ex);
}
return DEFAULT_ERROR;
}
示例5: modifyVPNClient
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Post
public Representation modifyVPNClient(Client client) {
if (!getRequestAttributes().containsKey("client"))
return clientError("MALFORMED_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
try {
Client c = Clients.dao.queryForId(getAttribute("client"));
if (!Policy.get().canModify(getSessionToken().get().getUser(), c)) {
return clientError("FORBIDDEN", Status.CLIENT_ERROR_BAD_REQUEST);
}
if (c != null) {
c = mergeUpdate(c, client).get();
}
Clients.dao.update(c);
return new JacksonRepresentation<>(client);
} catch (Exception ex) {
Logger.getLogger(getClass()).error("Failed to update client", ex);
}
return clientError("UNKNOWN_ERROR", Status.SERVER_ERROR_INTERNAL);
}
示例6: addVPNClient
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Put
public Representation addVPNClient(Client client) {
if ((client.commonName == null || client.commonName.isEmpty()) ||
(client.userId == null)) {
return clientError("MALFORMED_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
}
try {
Clients.dao.create(client);
return new JacksonRepresentation<>(client);
} catch (Exception ex) {
Logger.getLogger(getClass()).error("Failed to retrieve clients", ex);
}
return clientError("UNKNOWN_ERROR", Status.SERVER_ERROR_INTERNAL);
}
示例7: getSessionDetails
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Get
public Representation getSessionDetails() {
if (!Users.isRelatedService(getLoggedInUser()))
return clientError("ACCESS_DENIED", Status.CLIENT_ERROR_UNAUTHORIZED);
if (getAttribute("session") == null) return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
String session = getAttribute("session");
try {
HashMap<String, Object> sessionDetails = new HashMap<>();
SessionToken st = SessionTokens.dao.queryForEq("token", UUID.fromString(session)).get(0);
sessionDetails.put("details", st);
sessionDetails.put("isAdmin", Users.isAdmin(st.getUser()));
return new JacksonRepresentation<>(sessionDetails);
} catch (Exception ex) {
Logger.getLogger(getClass()).error("Failed to retrieve session", ex);
}
return DEFAULT_ERROR;
}
示例8: addAddressesToPool
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Put
public Representation addAddressesToPool(Map<String, Object> data) {
int version = (int) data.get("version");
String subnet = (String) data.get("subnet");
String purpose = data.get("purpose").toString();
if (purpose == null) purpose = IPAddress.Purpose.CLIENT_ASSIGN;
int v6prefix = 64;
if (data.containsKey("v6prefix")) v6prefix = (int) data.get("v6prefix");
try {
switch (version) {
case 4:
IPAddresses.addv4SubnetToPool(subnet, purpose);
return DEFAULT_SUCCESS;
case 6:
IPAddresses.addv6SubnetToPool(subnet, purpose, v6prefix);
return DEFAULT_SUCCESS;
default:
return new JacksonRepresentation(new ClientError("ILLEGAL_INPUT"));
}
} catch (NumberFormatException ex) {
return new JacksonRepresentation(new ClientError("ILLEGAL_INPUT", ex));
}
}
示例9: getSubnetLeases
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Get
public Representation getSubnetLeases() {
try {
if (getRequestAttributes().containsKey("id")) {
return new JacksonRepresentation<>(SubnetLeases.dao.queryForId(getAttribute("id")));
}
HashMap<Client, be.neutrinet.ispng.vpn.ip.SubnetLease> ip6 = new HashMap<>();
for (Client c : Clients.dao.queryForAll()) {
for (be.neutrinet.ispng.vpn.ip.SubnetLease sl : SubnetLeases.dao.queryForEq("client_id", c.id)) {
ip6.put(c, sl);
}
}
return new JacksonRepresentation<>(ip6);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to get assigned leases", ex);
}
return DEFAULT_ERROR;
}
示例10: updateLease
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Post
public Representation updateLease(be.neutrinet.ispng.vpn.ip.SubnetLease sl) {
if (!getRequestAttributes().containsKey("id"))
return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
if (sl == null) return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
try {
be.neutrinet.ispng.vpn.ip.SubnetLease subnetLease = SubnetLeases.dao.queryForId(getAttribute("id"));
mergeUpdate(subnetLease, sl);
SubnetLeases.dao.update(subnetLease);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to update subnet lease", ex);
}
return new JacksonRepresentation<>(sl);
}
示例11: deleteLease
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Delete
public Representation deleteLease() {
if (!getRequestAttributes().containsKey("id"))
return clientError("INVALID_REQUEST", Status.CLIENT_ERROR_BAD_REQUEST);
try {
be.neutrinet.ispng.vpn.ip.SubnetLease sl = SubnetLeases.dao.queryForId(getAttribute("id"));
SubnetLeases.dao.delete(sl);
if (!getRequestAttributes().containsKey("shallow")) {
IPSubnets.dao.delete(sl.subnet);
}
return new JacksonRepresentation<>(sl);
} catch (SQLException ex) {
Logger.getLogger(getClass()).error("Failed to delete subnet lease", ex);
}
return DEFAULT_ERROR;
}
示例12: login
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Post
public Representation login(Map<String, String> data) {
if (!data.containsKey("user") || !data.containsKey("password")) {
return error();
}
User user = Users.authenticate(data.get("user"), data.get("password"));
if (user != null) {
SessionToken token = SessionManager.createSessionToken(user, getRequest().getClientInfo().getAddress());
getResponse().getCookieSettings().add("Session", token.getToken().toString());
return new JacksonRepresentation(token);
} else {
getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED, "Authentication failed");
return DEFAULT_ERROR;
}
}
示例13: addUnlockKey
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Put
public Representation addUnlockKey(Map<String, String> data) {
if (!data.containsKey("email")) {
throw new IllegalArgumentException("No email address given");
}
try {
be.neutrinet.ispng.vpn.admin.UnlockKey key = new be.neutrinet.ispng.vpn.admin.UnlockKey();
key.email = data.get("email");
key.key = generateUnlockKey();
UnlockKeys.dao.createIfNotExists(key);
if (data.containsKey("sendEmail") && Boolean.parseBoolean(data.get("sendEmail")))
VPN.generator.sendUnlockKey(key, key.email);
return new JacksonRepresentation(key);
} catch (Exception ex) {
Logger.getLogger(getClass()).error("Failed to add unlock key", ex);
return DEFAULT_ERROR;
}
}
示例14: get
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
@Get
public Representation get() {
if (!sessionAvailable()) return DEFAULT_ERROR;
try {
if (!getRequestAttributes().containsKey("user") ||
getAttribute("user").equals("all")) {
List<User> users = Users.queryForAll();
return new JacksonRepresentation(Policy.filterAccessible(getSessionToken().get().getUser(), users));
}
String id = getAttribute("user");
User user = Users.queryForId(UUID.fromString(id));
if (Policy.get().canAccess(getSessionToken().get().getUser(), user)) {
return new JacksonRepresentation(user);
} else {
return clientError("FORBIDDEN", Status.CLIENT_ERROR_BAD_REQUEST);
}
} catch (Exception ex) {
Logger.getLogger(getClass()).error("Failed to retrieve users", ex);
}
return DEFAULT_ERROR;
}
示例15: run
import org.restlet.ext.jackson.JacksonRepresentation; //导入依赖的package包/类
/**
* Run the Application on an open port.
*
*/
public void run() {
try {
setStatusService(new StatusService() {
@Override
public Representation getRepresentation(Status status,
Request request,
Response response) {
return new JacksonRepresentation<>(status);
}
});
// Start listening for REST requests
component = new Component();
server = component.getServers().add(Protocol.HTTP, 0);
component.getDefaultHost().attach(this);
component.start();
} catch (Exception e) {
// Web server did not start.
throw new IllegalStateException(e);
}
}