InputStream ins = ReferencingAuthenticator.class .getResourceAsStream("ReferencingAuthenticator.class"); byte[] b = IOUtils.readBytesFromStream(ins); if (JavaUtils.isJava9Compatible()) { Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles");
o = IOUtils.readBytesFromStream(dh.getInputStream()); } catch (IOException e) { throw new Fault(e);
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } throw new IOException("Unknown format of currentStream"); } // read the file try (InputStream fin = createInputStream(tempFile)) { return IOUtils.readBytesFromStream(fin); } }
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } throw new IOException("Unknown format of currentStream"); } // read the file try (InputStream fin = createInputStream(tempFile)) { return IOUtils.readBytesFromStream(fin); } }
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); return IOUtils.readBytesFromStream(fin); } }
private Object runTest(IJavascriptEngineExecutor executor, IRepository repository, String testModule) throws IOException, ScriptingException { try { InputStream in = AbstractApiSuiteTest.class.getResourceAsStream(IRepositoryStructure.SEPARATOR + testModule); if (in == null) { throw new IOException(IRepositoryStructure.SEPARATOR + testModule + " does not exist"); } repository.createResource(IRepositoryStructure.PATH_REGISTRY_PUBLIC + IRepositoryStructure.SEPARATOR + testModule, IOUtils.readBytesFromStream(in)); } catch (RepositoryWriteException e) { throw new IOException(IRepositoryStructure.SEPARATOR + testModule, e); } Object result = executor.executeServiceModule(testModule, null); return result; } }
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); return IOUtils.readBytesFromStream(fin); } }
private byte[] extractMessageBody(ReaderInterceptorContext context) { try (InputStream is = context.getInputStream()) { return IOUtils.readBytesFromStream(is); } catch (IOException e) { throw new DigestFailureException("failed to validate the digest", e); } }
private byte[] extractMessageBody(ReaderInterceptorContext context) { try (InputStream is = context.getInputStream()) { return IOUtils.readBytesFromStream(is); } catch (IOException e) { throw new DigestFailureException("failed to validate the digest", e); } }
private void verifyMultipartResponse(MultipartBody bodyResponse) throws Exception { Book jaxbBook = bodyResponse.getAttachmentObject("book1", Book.class); Book jsonBook = bodyResponse.getAttachmentObject("book2", Book.class); byte[] receivedImageBytes = bodyResponse.getAttachmentObject("image", byte[].class); InputStream is = getClass().getResourceAsStream("/java.jpg"); byte[] imageBytes = IOUtils.readBytesFromStream(is); if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId() && "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId() && Arrays.equals(imageBytes, receivedImageBytes)) { System.out.println(); System.out.println("Book attachments have been successfully received"); } else { throw new RuntimeException("Received Book attachment is corrupted"); } }
protected JweDecryptionOutput decrypt(InputStream is) throws IOException { JweDecryption theDecryptor = getInitializedDecryption(); JweDecryptionOutput out = theDecryptor.decrypt(new String(IOUtils.readBytesFromStream(is), "UTF-8")); validateHeaders(out.getHeaders()); return out; }
@WebMethod public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception { DataHandler dataHandler = request.getContent(); InputStream inputStream = dataHandler.getInputStream(); return IOUtils.readBytesFromStream(inputStream).length; } }
@Test public void testPostBookStore() throws IOException { final Response response = createWebClient("/bookstore", MediaType.TEXT_PLAIN) .type(MediaType.TEXT_PLAIN) .post(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/files/books.txt"))); try { assertEquals(200, response.getStatus()); assertThat(response.readEntity(String.class), equalTo("Book Store uploaded: 10355 bytes")); } finally { response.close(); } }
protected JweDecryptionOutput decrypt(InputStream is) throws IOException { JweCompactConsumer jwe = new JweCompactConsumer(new String(IOUtils.readBytesFromStream(is), StandardCharsets.UTF_8)); JweDecryptionProvider theDecryptor = getInitializedDecryptionProvider(jwe.getJweHeaders()); JweDecryptionOutput out = new JweDecryptionOutput(jwe.getJweHeaders(), jwe.getDecryptedContent(theDecryptor)); JoseUtils.traceHeaders(out.getHeaders()); validateHeaders(out.getHeaders()); return out; }
protected JweDecryptionOutput decrypt(InputStream is) throws IOException { JweJsonConsumer c = new JweJsonConsumer(new String(IOUtils.readBytesFromStream(is), StandardCharsets.UTF_8)); JweDecryptionProvider theProvider = getInitializedDecryptionProvider(c.getProtectedHeader()); JweJsonEncryptionEntry entry = c.getJweDecryptionEntry(theProvider, recipientProperties); if (entry == null) { throw new JweException(JweException.Error.INVALID_JSON_JWE); } JweDecryptionOutput out = c.decryptWith(theProvider, entry); JAXRSUtils.getCurrentMessage().put(JweJsonConsumer.class, c); JAXRSUtils.getCurrentMessage().put(JweJsonEncryptionEntry.class, entry); return out; }
@Test public void testAddGetImageWebClient() throws Exception { InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"); String address = "http://localhost:" + PORT + "/bookstore/books/image"; WebClient client = WebClient.create(address); client.type("multipart/mixed").accept("multipart/mixed"); WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true"); InputStream is2 = client.post(is1, InputStream.class); byte[] image1 = IOUtils.readBytesFromStream( getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg")); byte[] image2 = IOUtils.readBytesFromStream(is2); assertTrue(Arrays.equals(image1, image2)); }
@Test public void testOutMTOM() throws Exception { QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService"); QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort"); URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl"); JMSOutMTOMService service = new JMSOutMTOMService(wsdl, serviceName); JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class); URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class"); DataHandler handler1 = new DataHandler(fileURL); int size = handler1.getInputStream().available(); DataHandler ret = mtom.testOutMtom(); byte[] bytes = IOUtils.readBytesFromStream(ret.getInputStream()); Assert.assertEquals("The response file is not same with the original file.", size, bytes.length); ((Closeable)mtom).close(); }
public void handleMessage(Message message) throws Fault { InputStream is = message.getContent(InputStream.class); if (is == null) { return; } byte[] payload; try { // input stream will be closed by readBytesFromStream() payload = IOUtils.readBytesFromStream(is); assertNotNull("payload was null", payload); assertTrue("payload was EMPTY", payload.length > 0); message.setContent(InputStream.class, new ByteArrayInputStream(payload)); } catch (Exception e) { String error = "Failed to read the stream properly due to " + e.getMessage(); assertFalse(error, e != null); } }
@Test public void testUploadImageFromForm2() throws Exception { File file = new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg") .toURI().getPath()); String address = "http://localhost:" + PORT + "/bookstore/books/formimage2"; WebClient client = WebClient.create(address); client.type("multipart/form-data").accept("multipart/form-data"); WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true"); MultipartBody body2 = client.post(file, MultipartBody.class); InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream(); byte[] image1 = IOUtils.readBytesFromStream( getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg")); byte[] image2 = IOUtils.readBytesFromStream(is2); assertTrue(Arrays.equals(image1, image2)); ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition(); assertEquals("form-data;name=file;filename=java.jpg", cd2.toString()); assertEquals("java.jpg", cd2.getParameter("filename")); }
@Test public void testMTOM() throws Exception { QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService"); QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort"); URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl"); JMSMTOMService service = new JMSMTOMService(wsdl, serviceName); JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class); Binding binding = ((BindingProvider)mtom).getBinding(); ((SOAPBinding)binding).setMTOMEnabled(true); Holder<String> name = new Holder<>("Sam"); URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class"); Holder<DataHandler> handler1 = new Holder<>(); handler1.value = new DataHandler(fileURL); int size = handler1.value.getInputStream().available(); mtom.testDataHandler(name, handler1); byte[] bytes = IOUtils.readBytesFromStream(handler1.value.getInputStream()); Assert.assertEquals("The response file is not same with the sent file.", size, bytes.length); ((Closeable)mtom).close(); }