簡體   English   中英

客戶端服務器應用程序中的錯誤:找不到java.util.UUID的轉換器

[英]Error in Client Server Application : Unable to find converter for java.util.UUID

我正在處理客戶端服務器應用程序。 我正在使用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,因此我的應用程序無法正常運行。

提前致謝

Restlet在后台使用通用bean轉換將bean轉換為表示形式(以及將表示形式轉換為bean)。 因此,您的問題取決於您使用的轉換器。

我使用擴展名org.restlet.ext.jackson (包含此類bean轉換器)和2.2.1版本的Restlet進行了測試。 我的測試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依賴項列表?

希望對您有幫助,蒂埃里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM