我正在使用 Jersey 1.17 开发 REST-Webservice。我有两台服务器在两个 Tomcats-AppServer 上运行。第一个 Tomcat 第二个发送一些数据。这会获取这些数据并在他的系统上提取一些文件。现在我的问题是是否可以将多个文件发送回第一个 Tomcat 服务器。使用一个文件,我将其带到工作中:
雄猫 1
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/...");
ObjectMapper objektMapper = new ObjectMapper();
String input = null;
try {
input = objektMapper.writeValueAsString(jsonMappingWebservice);//some JSON-Values
} catch (JsonProcessingException e) {
e.printStackTrace();
}
ClientResponse response = webResource
.type("application/json")
.post(ClientResponse.class, input);
// this is what I want to
List<File> file = (List<File>) response.getEntity(File.class);have
String sCurrentLine;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file.get(1).getAbsolutePath()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
雄猫 2
@POST
@Path("/generate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response erstelleBericht(JsonMappingWebservice jsonMappingWebservice) {
List<String> dateiPfade = Steuerung.erstelleExportDateien(jsonMappingWebservice);
List<File> files = new ArrayList<>();
for (String pfad : dateiPfade) {
files.add(new File(pfad));
}
return Response.ok(files, MediaType.APPLICATION_OCTET_STREAM).build();
}
错误
A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/octet-stream was not found