【问题标题】:Uri not Absolute exception getting while calling Restful Webservice调用Restful Webservice时Uri不是绝对异常
【发布时间】:2013-01-28 17:21:21
【问题描述】:

下面的代码 sn-p 用于使用 RESTful API 调用我的 Web 服务。

ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    String uri= "https://127.0.0.1:8443/cas-server-webapp-3.5.0/login";
    WebResource resource = client.resource(URLEncoder.encode(uri));
      MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
       queryParams.add("username", "suresh");
       queryParams.add("password", "suresh");
       resource.queryParams(queryParams); 
       ClientResponse response = resource.type(
            "application/x-www-form-urlencoded").get(ClientResponse.class);
    String en = response.getEntity(String.class);
    System.out.println(en); 

并在运行上述代码时遇到此异常

com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute

    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)

我在谷歌上搜索了很多文章,但没有找到我做错的地方。

旁注:cas-server-webapp-3.5.0war 在我的机器上部署在 Apache tomacat7 中

【问题讨论】:

  • 在您的 URI 中,您确定是 https,而不是 http?请检查一次。
  • 是的,只有 HTTPS。我的 Tomcat 服务器上启用了 SSL。

标签: java web-services http servlets cas


【解决方案1】:

绝对 URI 指定方案;一个不是绝对的 URI 被称为是相对的。

http://docs.oracle.com/javase/8/docs/api/java/net/URI.html

那么,也许您的 URLEncoder 没有按预期工作(https 位)?

    URLEncoder.encode(uri) 

【讨论】:

    【解决方案2】:

    问题可能是您在已经是 URI 的东西上调用 URLEncoder.encode()。

    【讨论】:

      【解决方案3】:

      对于遇到此错误且与 OP 问题不是 100% 相关的其他人,请检查您是否传递了该值,并且在 spring-boot:@Value 注释的情况下它不为空。

      【讨论】:

        【解决方案4】:

        问题可能只存在于您的 IDE 编码设置中。尝试在任何地方设置 UTF-8:

        【讨论】:

          【解决方案5】:

          在 API 密钥授权场景中...

          在从第一次 REST 调用中获得 AUTH_TOKEN 和 ENDPOINT_URL 后,您可能正在执行第二次 REST 调用。

          检查“ + ”的串联,您可能只发送 API_METHOD_URI。

          这发生在我使用 Streamsets 集成平台尝试连接到 Oracle 的 Responsys API 时。

          【讨论】:

            猜你喜欢
            • 2015-12-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-11-07
            • 2015-04-30
            相关资源
            最近更新 更多