我正在研究客户端服务器应用程序。我使用的是Restlet 2.0.3。由于负载繁重的任务,我的客户正在超时。我在论坛上搜索,发现切换到Restlet 2.2会有所帮助。所以我做到了。我将Restlet升级到2.2.1。但是现在我的代码已经停止了这种方法。
public synchronized UUID generateUniqueSessionId(String userAtDomain)
{
UUID newSessionId = UUID.randomUUID();
SessionAttributes sessionAttributes = new SessionAttributes();
sessionAttributes.setAlive(true);
sessionAttributes.setFQUserName(userAtDomain);
loggedInUsers.put(newSessionId, sessionAttributes);
return newSessionId;
}
所以我终于回来了UUID。 此代码位于服务器上,并在登录期间调用。以下是我从日志中获得的错误。
2015年3月16日11:23:18警告 - 无法为此对象找到转换器:f3d2edda-443c-454d-856a-fb4e7ed9c535
日志中引用的此对象属于java.util.UUID
调用服务器的客户端代码如下所示。
public UUID authenticateUser(String username, String passwd) {
try {
String url = RESTLetWebSvcsFactory.getFactoryInstance().getServer_URL() + "login/" + username + "/" + passwd;
Context context = new Context();
Client client = new Client(context, Protocol.HTTP);
ClientHelper helper = new ClientHelper(client);
helper.getHelpedParameters().set("socketConnectTimeoutMs", "60000");
ClientResource cr = new ClientResource(url);
LoginLogoutResource resource = cr.wrap(LoginLogoutResource.class);
return resource.loginUser();
} catch (ResourceException re) {
if (re.getStatus().isConnectorError()) {
try {
RESTLetWebSvcsFactory.enableFallBackServer();
String url = RESTLetWebSvcsFactory.getFactoryInstance().getServer_URL() + "login/" + username + "/" + passwd;
ClientResource cr = new ClientResource(url);
LoginLogoutResource resource = cr.wrap(LoginLogoutResource.class);
return resource.loginUser();
} catch (ResourceException re1) {
int statusCode = new RESTLetErrorHandler().handleServerError(re);
if (statusCode != -1) {
throw new UserCRUDException(statusCode);
}
}
} else {
throw new UserCRUDException(new RESTLetErrorHandler().handleServerError(re));
}
}
return null;
}
注意:USERCRUDException是我自己的异常,而不是JAVA
之一请帮我解决这个问题,这可能会阻止从服务器返回UUID,因此我的应用程序没有继续前进。
提前致谢
答案 0 :(得分:0)
Restlet使用泛型bean转换将bean转换为表示(并表示为bean)。所以你的问题取决于你使用的转换器。
我使用扩展名org.restlet.ext.jackson
(包含此类bean转换器)和Restlet 2.2.1版进行了测试。我的测试bean如下所述:
public class TestBean {
private String name;
private String message;
private UUID uuid;
(...)
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
}
以及以下测试服务器资源:
public class MyServerResource extends ServerResource {
@Get
public TestBean ping() {
TestBean bean = new TestBean();
bean.setMessage("pong");
bean.setUuid(UUID.randomUUID());
return bean;
}
}
我收到了以下GET方法的内容:
{
"name":"my name",
"message":"my message",
"uuid":"be9e5381-d5c9-4e45-b5c8-4af1f8bdca16"
}
您能提供您使用的转换器吗?以及您在应用程序中具有的Restlet依赖项列表?
希望它可以帮到你, 亨利