泽西接收文件列表

Jersey Receive List of Files

我想收到文件列表(只是 Nexus 服务器上的名称)。 这是我当前的代码:

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new HTTPBasicAuthFilter(nexusUser, nexusPassword));
WebResource service = client.resource("http://localhost:8081/nexus/content/repositories/linkToRepo
ClientResponse response = service.accept("application/json").get(ClientResponse.class);

String output = response.getEntity(String.class);

但我刚从服务器收到 html。我可以解析 HTML 但是否有可能直接接收文件名和路径?

这里是收到的 HTML 代码的一小段:

 <body>
<h1>Index of /repositories/linkToRepo</h1>
<table cellspacing="10">
  <tr>
    <th align="left">Name</th>
    <th>Last Modified</th>
    <th>Size</th>
    <th>Description</th>
  </tr>
  <tr>
    <td><a href="../">Parent Directory</a></td>
  </tr>
              <tr>
        <td><a href="http://localhost:8081/nexus/content/repositories/linkToRepo/1.0/">1.0/</a></td>
        <td>Wed May 27 14:38:37 CEST 2015</td>
        <td align="right">
                          &nbsp;
                      </td>
        <td></td>
      </tr>
              <tr>
        <td><a href="http://localhost:8081/nexus/content/repositories/linktoRepo/maven-metadata.xml">maven-metadata.xml</a></td>
        <td>Wed May 27 14:38:37 CEST 2015</td>
        <td align="right">
                          311
                      </td>
        <td></td>
      </tr>

亲切的问候, 桑德曼爵士

您可以将 http accept header Accept 设置为 application/json; charset=UTF-8 以便接收更易于解析的内容。 (查看文档以了解如何操作 https://jersey.java.net/documentation/1.19/client-api.html#d4e642

但是,您应该使用 Nexus Rest API(请参阅文档 https://oss.sonatype.org/nexus-restlet1x-plugin/default/docs/index.html)以获得您感兴趣的内容。

感谢指点! 我通过 jsoup 解析解决了这个问题,因为我没有使用 nexus rest api.

的经验

代码在这里:

        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        client.addFilter(new HTTPBasicAuthFilter(nexusUser, nexusPassword));
        WebResource service = client.resource(repoPath);
        ClientResponse response = service.accept("application/json",
                "UTF-8").get(ClientResponse.class);

        String htmlString = response.getEntity(String.class);
        Document doc = Jsoup.parseBodyFragment(htmlString);
        Elements elements = doc.select("a[href]");
        return elements;