@POST @Path("port") @Consumes(MediaType.MULTIPART_FORM_DATA) public void importData(@Context HttpServletRequest request) throws IcatException, IOException { if (!ServletFileUpload.isMultipartContent(request)) { throw new IcatException(IcatExceptionType.BAD_PARAMETER, "Multipart content expected"); } ServletFileUpload upload = new ServletFileUpload(); String jsonString = null; String name = null; // Parse the request try { FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); String fieldName = item.getFieldName(); InputStream stream = item.openStream(); if (item.isFormField()) { String value = Streams.asString(stream); if (fieldName.equals("json")) { jsonString = value; } else { throw new IcatException( IcatExceptionType.BAD_PARAMETER, "Form field " + fieldName + "is not recognised"); } } else { if (name == null) { name = item.getName(); } porter.importData(jsonString, stream, manager, userTransaction); } } } catch (FileUploadException e) { throw new IcatException(IcatExceptionType.INTERNAL, e.getClass() + " " + e.getMessage()); } }
@GET @Path("port") @Produces(MediaType.TEXT_PLAIN) public Response exportData(@QueryParam("json") String jsonString) throws IcatException { return porter.exportData(jsonString, manager, userTransaction); }