SirSandmann SirSandmann - 4 months ago 9
Java Question

Jersey Receive List of Files

I want to receive a List of Files (just the names on a Nexus Server).
Here is my current Code:

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);


But i just receive the html from the Server. I could parse the HTML but is there any possibility to receive directly the name of the files and the path?

Here a short snippet of the HTML Code received:

<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>


Kind regards,
SirSandmann

Answer

You may set the http accept header Accept to application/json; charset=UTF-8 in order to receive something easier to parse. (check out the doc to see how to do it https://jersey.java.net/documentation/1.19/client-api.html#d4e642)

However, you should rather use Nexus Rest API (see the doc https://oss.sonatype.org/nexus-restlet1x-plugin/default/docs/index.html) in order to get what you're interested for.