Java Code Examples for javax.activation.DataHandler#writeTo()
The following examples show how to use
javax.activation.DataHandler#writeTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogReaderSOAPClient.java From webcurator with Apache License 2.0 | 5 votes |
public File retrieveAQAFile(String aJob, String aFilename) { try { WCTSoapCall call = new WCTSoapCall(host, port, service, "retrieveAQAFile"); call.regTypes(DataHandler.class); DataHandler dh = (DataHandler) call.invoke(aJob, aFilename); File f = File.createTempFile("wct", "tmp"); dh.writeTo(new FileOutputStream(f)); return f; } catch(Exception ex) { throw new WCTRuntimeException("Failed to retrieve aqa file " + aFilename + " for " + aJob + ": " + ex.getMessage(), ex); } }
Example 2
Source File: DataHandlerType.java From cxf with Apache License 2.0 | 5 votes |
@Override protected byte[] getBytes(Object object) { DataHandler handler = (DataHandler) object; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { handler.writeTo(baos); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); }
Example 3
Source File: EmailSendTaskTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 4
Source File: JplagClient.java From jplag with GNU General Public License v3.0 | 5 votes |
private File extractPart(MimeMultipart inputZipFile, String path) { File result = new File(path + "/jplagResult.zip"); try { if (inputZipFile == null) return null; MimeBodyPart bdp = (MimeBodyPart) inputZipFile.getBodyPart(0); System.out.println("Content Type " + bdp.getContentType()); DataHandler dh = bdp.getDataHandler(); FileOutputStream os = new FileOutputStream(result); dh.writeTo(os); os.close(); } catch (Exception e) { if (e instanceof JPlagException) { JPlagException jex = (JPlagException) e; System.out.println(jex.getExceptionType()); System.out.println(jex.getDescription()); System.out.println(jex.getRepair()); } e.printStackTrace(); System.exit(-1); } String report = "\n" + "\n" + ((result == null) ? "compareSource was not successfull sorry" : "WAOOOOOOOUUUUU ******** CompareSource was succesfull**********") + "\n" + "\n"; System.out.println(report); return result; }
Example 5
Source File: EmailServiceTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 6
Source File: EmailSendTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 7
Source File: EmailServiceTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 8
Source File: EmailServiceTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 9
Source File: EmailServiceTaskTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 10
Source File: EmailSendTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); }
Example 11
Source File: CmmnMailTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
protected String getMessage(MimeMessage mimeMessage) { try { DataHandler dataHandler = mimeMessage.getDataHandler(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); dataHandler.writeTo(baos); baos.flush(); return baos.toString(); } catch (Exception e) { throw new RuntimeException("Couldn't get message", e); } }
Example 12
Source File: MTOMSwAClient.java From product-ei with Apache License 2.0 | 4 votes |
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException { Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction("urn:uploadFileUsingSwA"); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); ServiceClient sender = createServiceClient(); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); System.out.println("Sending file : " + fileName + " as SwA"); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope env = factory.getDefaultEnvelope(); OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns); OMElement request = factory.createOMElement("request", ns); OMElement imageId = factory.createOMElement("imageId", ns); imageId.setText(attachmentID); request.addChild(imageId); payload.addChild(request); env.getBody().addChild(payload); mc.setEnvelope(env); mepClient.addMessageContext(mc); mepClient.execute(true); MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPBody body = response.getEnvelope().getBody(); String imageContentId = body. getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")). getFirstChildWithName(new QName("http://services.samples", "response")). getFirstChildWithName(new QName("http://services.samples", "imageId")). getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); dataHandler.writeTo(fos); fos.flush(); fos.close(); System.out.println("Saved response to file : " + tempFile.getAbsolutePath()); return response; }
Example 13
Source File: MailNotifierTest.java From spring-boot-admin with Apache License 2.0 | 4 votes |
private String extractBody(DataHandler dataHandler) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(4096); dataHandler.writeTo(os); return os.toString(StandardCharsets.UTF_8.name()).replaceAll("\\r?\\n", "\n"); }
Example 14
Source File: BDReportServlet.java From carbon-commons with Apache License 2.0 | 4 votes |
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String dataSource = request.getParameter("dataSource"); String reportName = request.getParameter("reportName"); String reportType = request.getParameter("reportType"); String params = request.getParameter("hidden_param"); String downloadFileName = null; if (reportType.equals("pdf")) { response.setContentType("application/pdf"); downloadFileName = reportName + ".pdf"; } else if (reportType.equals("excel")) { response.setContentType("application/vnd.ms-excel"); downloadFileName = reportName + ".xls"; } else if (reportType.equals("html")) { response.setContentType("text/html"); } else { throw new ReportingException("requested report type can not be support"); } if (downloadFileName != null) { response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\""); } ReportBean reportBean = new ReportBean(); reportBean.setTemplateName(reportName); reportBean.setReportType(reportType); reportBean.setDataSourceName(dataSource); String serverURL = CarbonUIUtil.getServerURL(request.getSession().getServletContext(), request.getSession()); ConfigurationContext configurationContext = (ConfigurationContext) request.getSession().getServletContext(). getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); DBReportingServiceClient dbReportingServiceClient = null; try { dbReportingServiceClient = new DBReportingServiceClient(cookie, serverURL, configurationContext); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } List<ReportParamMap> reportParamMapsList = new ArrayList<ReportParamMap>(); String[] parmCollection = params.split("\\|"); for (String inputParam : parmCollection) { if (inputParam != null && !"".equals(inputParam)) { ReportParamMap reportParamMap = new ReportParamMap(); String[] input = inputParam.split("\\="); reportParamMap.setParamKey(input[0]); reportParamMap.setParamValue(input[1]); reportParamMapsList.add(reportParamMap); } } try { DataHandler dataHandler = null; if (dbReportingServiceClient != null) { dataHandler = dbReportingServiceClient.getReport(reportBean,reportParamMapsList.toArray(new ReportParamMap[reportParamMapsList.size()])); } ServletOutputStream outputStream = response.getOutputStream(); if (dataHandler != null) { dataHandler.writeTo(outputStream); } } catch (Exception e) { log.error("Failed to handle report request ",e); throw e; } }
Example 15
Source File: MTOMSwAClient.java From micro-integrator with Apache License 2.0 | 4 votes |
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException { Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction("urn:uploadFileUsingSwA"); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); ServiceClient sender = createServiceClient(); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); System.out.println("Sending file : " + fileName + " as SwA"); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope env = factory.getDefaultEnvelope(); OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns); OMElement request = factory.createOMElement("request", ns); OMElement imageId = factory.createOMElement("imageId", ns); imageId.setText(attachmentID); request.addChild(imageId); payload.addChild(request); env.getBody().addChild(payload); mc.setEnvelope(env); mepClient.addMessageContext(mc); mepClient.execute(true); MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPBody body = response.getEnvelope().getBody(); String imageContentId = body. getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")). getFirstChildWithName(new QName("http://services.samples", "response")). getFirstChildWithName(new QName("http://services.samples", "imageId")). getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); dataHandler.writeTo(fos); fos.flush(); fos.close(); System.out.println("Saved response to file : " + tempFile.getAbsolutePath()); return response; }
Example 16
Source File: SoapDocumentClient.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
public void downloadResourceContent(String sid, long docId, String fileVersion, String suffix, File out) throws Exception { DataHandler data = client.getResource(sid, docId, fileVersion, suffix); data.writeTo(new FileOutputStream(out)); }
Example 17
Source File: SoapDocumentClient.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
public void downloadVersionContent(String sid, long docId, String version, File out) throws Exception { DataHandler data = client.getVersionContent(sid, docId, version); data.writeTo(new FileOutputStream(out)); }
Example 18
Source File: MailNotifierTest.java From Moss with Apache License 2.0 | 4 votes |
private String extractBody(DataHandler dataHandler) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(4096); dataHandler.writeTo(os); return os.toString(StandardCharsets.UTF_8.name()) .replaceAll("\\r?\\n", "\n"); }
Example 19
Source File: MTOMSwAClient.java From micro-integrator with Apache License 2.0 | 4 votes |
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException { Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction("urn:uploadFileUsingSwA"); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); ServiceClient sender = createServiceClient(); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); System.out.println("Sending file : " + fileName + " as SwA"); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler); SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope env = factory.getDefaultEnvelope(); OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns); OMElement request = factory.createOMElement("request", ns); OMElement imageId = factory.createOMElement("imageId", ns); imageId.setText(attachmentID); request.addChild(imageId); payload.addChild(request); env.getBody().addChild(payload); mc.setEnvelope(env); mepClient.addMessageContext(mc); mepClient.execute(true); MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); SOAPBody body = response.getEnvelope().getBody(); String imageContentId = body. getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")). getFirstChildWithName(new QName("http://services.samples", "response")). getFirstChildWithName(new QName("http://services.samples", "imageId")). getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); dataHandler.writeTo(fos); fos.flush(); fos.close(); System.out.println("Saved response to file : " + tempFile.getAbsolutePath()); return response; }
Example 20
Source File: AbstractEmailTest.java From commons-email with Apache License 2.0 | 3 votes |
/** * Gets the byte making up the body of the message. * * @param mimeMessage * The mime message from which to extract the body. * @return A byte array representing the message body * @throws IOException * Thrown while serializing the body from * {@link DataHandler#writeTo(java.io.OutputStream)}. * @throws MessagingException * Thrown while getting the body content from * {@link MimeMessage#getDataHandler()} * @since 1.1 */ private byte[] getMessageBodyBytes(final MimeMessage mimeMessage) throws IOException, MessagingException { final DataHandler dataHandler = mimeMessage.getDataHandler(); final ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream(); final BufferedOutputStream buffOs = new BufferedOutputStream( byteArrayOutStream); dataHandler.writeTo(buffOs); buffOs.flush(); return byteArrayOutStream.toByteArray(); }