What Jersey (Has RESTful web service support) Version i need to download for JDK 1.6? Please provide the URL of the download and would be helpful. I also need file upload support. What are the jar dependencies for both client and server side?
The REST server code for file upload looks like as follows:
@Path("/file")
public class FileService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFile(@FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("file") FormDataContentDisposition aFileDetail) {
OutputStream os = null;
try {
File fileToUpload = new File("D:/uploadedFile");
os = new FileOutputStream(fileToUpload);
byte[] b = new byte[2048];
int length;
while ((length = uploadedInputStream.read(b)) != -1) {
os.write(b, 0, length);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
os.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Client code looks like as follows:
Client client = ClientBuilder.newBuilder()
.register(MultiPartFeature.class).build();
WebTarget webTarget = client.target(REST_SERVICE_URL);
MultiPart multiPart = new MultiPart();
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
new File("d:/classes12-1.jar"),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(fileDataBodyPart);
Response response = webTarget.request(
MediaType.MULTIPART_FORM_DATA).post(
Entity.entity(multiPart, multiPart.getMediaType()));