@Override public StoreContext spool( String localAETitle, String remoteAETitle, InputStream in, InstanceAvailableCallback callback) throws Exception { StoreContext context; ApplicationEntity localAE = aeCache.findApplicationEntity(localAETitle); StoreSession session = storeService.createStoreSession(storeService); session.setSource( new GenericParticipant(localAE.getConnections().get(0).getHostname(), "WadoRS Fetch")); session.setRemoteAET(remoteAETitle); ArchiveAEExtension arcAEExt = aeCache.get(localAETitle).getAEExtension(ArchiveAEExtension.class); session.setArchiveAEExtension(arcAEExt); storeService.init(session); context = storeService.createStoreContext(session); try { DicomInputStream din = new DicomInputStream(in); Attributes fmi = din.getFileMetaInformation(); storeService.writeSpoolFile(context, fmi, din); } catch (Exception e) { throw new Exception("Failed to spool WadoRS response from AE " + remoteAETitle); } return context; }
@POST @Path("/studies") @Consumes({"multipart/related", "multipart/form-data"}) public Response storeInstances(InputStream in) throws Exception { String str = req.toString(); LOG.info(str); init(); final StoreSession session = storeService.createStoreSession(storeService); session.setSource(new HttpSource(request)); ApplicationEntity sourceAE = aeCache.findAE(new HttpSource(request)); session.setRemoteAET( sourceAE != null ? sourceAE.getAETitle() : null); // add AE for the web source session.setArchiveAEExtension(arcAE); storeService.initStorageSystem(session); storeService.initSpoolDirectory(session); storeService.initMetaDataStorageSystem(session); try { new MultipartParser(boundary) .parse( in, new MultipartParser.Handler() { @Override public void bodyPart(int partNumber, MultipartInputStream in) throws IOException { Map<String, List<String>> headerParams = in.readHeaderParams(); String transferSyntax = null; LOG.info("storeInstances: Extract Part #{}{}", partNumber, headerParams); String contentType = getHeaderParamValue(headerParams, "content-type"); String contentLocation = getHeaderParamValue(headerParams, "content-location"); MediaType mediaType; try { mediaType = contentType == null ? MediaType.TEXT_PLAIN_TYPE : MediaType.valueOf(contentType); } catch (IllegalArgumentException e) { LOG.info( "storeInstances: Ignore Part with illegal Content-Type={}", contentType); in.skipAll(); return; } // check for metadata transfer syntax if (contentLocation == null) { transferSyntax = contentType.contains("transfer-syntax=") ? contentType.split("transfer-syntax=")[1] : null; } if (!creatorType.readBodyPart( StowRS.this, session, in, mediaType, contentLocation, transferSyntax)) { LOG.info("storeInstances: Ignore Part with Content-Type={}", mediaType); in.skipAll(); } } }); creatorType.storeMetadataAndBulkdata(this, session); } finally { storeService.onClose(session); } return buildResponse(); }