Restlet:无法为此表示找到转换器:[application / repo.foo + xml]

时间:2014-10-22 12:29:55

标签: java rest restlet

我正在尝试从Web服务检索资源,但收到此警告:

WARNING: Unable to find a converter for this representation : [application/repo.foo+xml]

我的代码返回null实体。这是代码

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());

ClientResource resource = new ClientResource(path);
ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
ChallengeResponse auth = new ChallengeResponse(scheme, "user", "password");

resource.setChallengeResponse(auth);

Repo entity = resource.get(Repo.class);
System.out.println(entity);

更新

遗憾的是,我的尝试无效:

  1. resource.getRequestAttributes().put("org.restlet.http.headers", new MediaType("application", "application/repo.foo+xml"));

  2. resource.setAttribute("Content-Type", "application/repo.foo+xml");

1 个答案:

答案 0 :(得分:0)

你的问题有些混乱。

您正在撰写客户。您可以告诉客户端设置接受标头。简而言之,这是服务器关于您希望响应的内容类型的提示.JSON,HTML,XML等等。服务器可以尊重这一点,向您发送最佳猜测或完全忽略它。

您可以尝试将接受标头设置为“application / javascript”并查看其响应方式。如果它继续发送“application / repo.foo + xml”,那么你可能可以使用jackson xml数据包解析它。您可能必须向客户端注册媒体类型和转换器,以便它知道使用哪个转换器来序列化对象。