@Test public void testDicomWebClient_Stow() throws Exception { fakeDicomWebServer.addResponseWithStatusCode(200); String data = "some data"; client.stowRs(new ByteArrayInputStream(data.getBytes())); FakeWebServer.Request req = fakeDicomWebServer.getRequests().firstElement(); ByteArrayOutputStream body = new ByteArrayOutputStream(); req.request.getStreamingContent().writeTo(body); String contentType = req.request.getContentType(); HttpMediaType mediaType = new HttpMediaType(contentType); String boundary = mediaType.getParameter("boundary"); MultipartHandler handler = new MultipartHandler(); MultiPartParser parser = new MultiPartParser(handler,boundary); parser.parse(ByteBuffer.wrap(body.toByteArray()), true); assertThat(StandardCharsets.UTF_8.decode(handler.lastItem).toString()).isEqualTo(data); }
public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException { GenericUrl url = new GenericUrl(StringUtil.joinPath(serviceUrlPrefix, this.stowPath)); MultipartContent content = new MultipartContent(); content.setMediaType(new HttpMediaType("multipart/related; type=\"application/dicom\"")); content.setBoundary(UUID.randomUUID().toString()); InputStreamContent dicomStream = new InputStreamContent("application/dicom", in); content.addPart(new MultipartContent.Part(dicomStream)); try { HttpRequest httpRequest = requestFactory.buildPostRequest(url, content); httpRequest.execute(); } catch (HttpResponseException e) { throw new DicomWebException( String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()), e, e.getStatusCode(), Status.ProcessingFailure); } catch (IOException e) { throw new IDicomWebClient.DicomWebException(e); } }
DicomWebClient implements IDicomWebClient { public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException { GenericUrl url = new GenericUrl(StringUtil.joinPath(serviceUrlPrefix, this.stowPath)); MultipartContent content = new MultipartContent(); content.setMediaType(new HttpMediaType("multipart/related; type=\"application/dicom\"")); content.setBoundary(UUID.randomUUID().toString()); InputStreamContent dicomStream = new InputStreamContent("application/dicom", in); content.addPart(new MultipartContent.Part(dicomStream)); try { HttpRequest httpRequest = requestFactory.buildPostRequest(url, content); httpRequest.execute(); } catch (HttpResponseException e) { throw new DicomWebException( String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()), e, e.getStatusCode(), Status.ProcessingFailure); } catch (IOException e) { throw new IDicomWebClient.DicomWebException(e); } } }
DicomWebClient implements IDicomWebClient { public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException { GenericUrl url = new GenericUrl(StringUtil.joinPath(serviceUrlPrefix, this.stowPath)); MultipartContent content = new MultipartContent(); content.setMediaType(new HttpMediaType("multipart/related; type=\"application/dicom\"")); content.setBoundary(UUID.randomUUID().toString()); InputStreamContent dicomStream = new InputStreamContent("application/dicom", in); content.addPart(new MultipartContent.Part(dicomStream)); try { HttpRequest httpRequest = requestFactory.buildPostRequest(url, content); httpRequest.execute(); } catch (HttpResponseException e) { throw new DicomWebException( String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()), e, e.getStatusCode(), Status.ProcessingFailure); } catch (IOException e) { throw new IDicomWebClient.DicomWebException(e); } } @Inject  DicomWebClient(
      HttpRequestFactory requestFactory,
      @Annotations.DicomwebAddr String serviceUrlPrefix,
      String stowPath); }
DicomWebClient implements IDicomWebClient { public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException { GenericUrl url = new GenericUrl(StringUtil.joinPath(serviceUrlPrefix, this.stowPath)); MultipartContent content = new MultipartContent(); content.setMediaType(new HttpMediaType("multipart/related; type=\"application/dicom\"")); content.setBoundary(UUID.randomUUID().toString()); InputStreamContent dicomStream = new InputStreamContent("application/dicom", in); content.addPart(new MultipartContent.Part(dicomStream)); try { HttpRequest httpRequest = requestFactory.buildPostRequest(url, content); httpRequest.execute(); } catch (HttpResponseException e) { throw new DicomWebException( String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()), e, e.getStatusCode(), Status.ProcessingFailure); } catch (IOException e) { throw new IDicomWebClient.DicomWebException(e); } } @Inject  DicomWebClient(
      HttpRequestFactory requestFactory,
      @Annotations.DicomwebAddr String serviceUrlPrefix,
      String stowPath); InputStream wadoRs(String path); JSONArray qidoRs(String path); void stowRs(InputStream in); }
DicomWebClient implements IDicomWebClient { public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException { GenericUrl url = new GenericUrl(StringUtil.joinPath(serviceUrlPrefix, this.stowPath)); MultipartContent content = new MultipartContent(); content.setMediaType(new HttpMediaType("multipart/related; type=\"application/dicom\"")); content.setBoundary(UUID.randomUUID().toString()); InputStreamContent dicomStream = new InputStreamContent("application/dicom", in); content.addPart(new MultipartContent.Part(dicomStream)); try { HttpRequest httpRequest = requestFactory.buildPostRequest(url, content); httpRequest.execute(); } catch (HttpResponseException e) { throw new DicomWebException( String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()), e, e.getStatusCode(), Status.ProcessingFailure); } catch (IOException e) { throw new IDicomWebClient.DicomWebException(e); } } @Inject  DicomWebClient(
      HttpRequestFactory requestFactory,
      @Annotations.DicomwebAddr String serviceUrlPrefix,
      String stowPath); InputStream wadoRs(String path); JSONArray qidoRs(String path); void stowRs(InputStream in);  }