powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / JFreeChart + CommonEmail
1 сообщений из 1, страница 1 из 1
JFreeChart + CommonEmail
    #34681816
Who am I
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Делаю диаграмму с помощью JFreeChart, диаграмма отображается нормально, если раскомментить кусок кода внизу, то это можно будет посмотреть.
Далее эту диаграмму нужно отправить по емайлу.
Использую апачевский CommonEmail.
Все хорошо до тех пор пока размеры картинки небольшие. 200 х 200 смогло отправить. Но как только размер увеличиваю до определенного размера (мне в идеале надо будет 1024 х 768), вылетает ошибка:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mail.ru: 25 
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java: 873 )
	at org.apache.commons.mail.Email.send(Email.java: 898 )
	at com.denik.test.MainTest.main(MainTest.java: 288 )
	at sun.reflect.NativeMethodAccessorImpl.invoke0( Native  Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39 )
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25 )
	at java.lang.reflect.Method.invoke(Method.java: 324 )
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java: 90 )
Caused by: javax.mail.MessagingException: IOException  while  sending message;
  nested exception is:
	java.net.SocketException: Software caused connection abort: socket write error
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java: 625 )
	at javax.mail.Transport.send0(Transport.java: 169 )
	at javax.mail.Transport.send(Transport.java: 98 )
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java: 863 )
	...  7  more
Caused by: java.net.SocketException: Software caused connection abort: socket write error
	at java.net.SocketOutputStream.socketWrite0( Native  Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java: 92 )
	at java.net.SocketOutputStream.write(SocketOutputStream.java: 136 )
	at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java: 101 )
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java: 66 )
	at java.io.BufferedOutputStream.write(BufferedOutputStream.java: 110 )
	at com.sun.mail.util.CRLFOutputStream.write(CRLFOutputStream.java: 87 )
	at com.sun.mail.smtp.SMTPOutputStream.write(SMTPOutputStream.java: 74 )
	at com.sun.mail.util.CRLFOutputStream.write(CRLFOutputStream.java: 65 )
	at com.sun.mail.util.BASE64EncoderStream.encode(BASE64EncoderStream.java: 182 )
	at com.sun.mail.util.BASE64EncoderStream.write(BASE64EncoderStream.java: 135 )
	at com.sun.mail.util.BASE64EncoderStream.write(BASE64EncoderStream.java: 96 )
	at javax.activation.DataHandler.writeTo(DataHandler.java: 308 )
	at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java: 1350 )
	at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java: 845 )
	at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java: 361 )
	at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java: 85 )
	at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java: 883 )
	at javax.activation.DataHandler.writeTo(DataHandler.java: 316 )
	at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java: 1350 )
	at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java: 1683 )
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java: 585 )
	...  10  more
Exception in thread "main" 
Process finished with exit code  1 

Подозреваю что это связано с тем что я все это дело тестирую на своем буке дома, инет у меня очень тормозной, т.к. gprs и через некоторое время вылетает ошибка. Можно как-то это обойти и принудительно поставить долгое ожидание? Или дело не в этом? У заказчика интернет шустрый, таких проблем по идее быть не должно. Но.... Это очень важный аспект, email должен быть отправлен 100%, поэтому возможный баг надо искоренять заранее. Очень прошу помочь всех, у кого какие идеи есть, пусть они даже будут глупые :)

Исходник:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
 package  com.denik.test;

 import  org.jfree.chart.JFreeChart;
 import  org.jfree.chart.ChartUtilities;
 import  org.jfree.chart.axis.CategoryAxis;
 import  org.jfree.chart.axis.CategoryLabelPositions;
 import  org.jfree.chart.axis.NumberAxis;
 import  org.jfree.chart.axis.ValueAxis;
 import  org.jfree.chart.labels.StandardCategoryToolTipGenerator;
 import  org.jfree.chart.plot.CategoryPlot;
 import  org.jfree.chart.plot.DatasetRenderingOrder;
 import  org.jfree.chart.plot.PlotOrientation;
 import  org.jfree.chart.renderer.category.LineAndShapeRenderer;
 import  org.jfree.chart.renderer.category.StackedBarRenderer;
 import  org.jfree.data.category.CategoryDataset;
 import  org.jfree.data.category.DefaultCategoryDataset;
 import  org.apache.commons.mail.MultiPartEmail;
 import  org.apache.commons.mail.EmailException;
 import  org.apache.commons.mail.ByteArrayDataSource;

 import  java.awt.*;
 import  java.io.*;

 public   class  MainTest {

    // Time intervals
     private   static   final  String time_06_30_07_00 = "06:30 to 07:00";
     private   static   final  String time_07_00_07_30 = "07:00 to 07:30";
     private   static   final  String time_07_30_08_00 = "07:30 to 08:00";
     private   static   final  String time_08_00_08_30 = "08:00 to 08:30";
     private   static   final  String time_08_30_09_00 = "08:30 to 09:00";
     private   static   final  String time_09_00_09_30 = "09:00 to 09:30";
     private   static   final  String time_09_30_10_00 = "09:30 to 10:00";
     private   static   final  String time_10_00_10_30 = "10:00 to 10:30";
     private   static   final  String time_10_30_11_00 = "10:30 to 11:00";
     private   static   final  String time_11_00_11_30 = "11:00 to 11:30";
     private   static   final  String time_11_30_12_00 = "11:30 to 12:00";
     private   static   final  String time_12_00_12_30 = "12:00 to 12:30";
     private   static   final  String time_12_30_13_00 = "12:30 to 13:00";
     private   static   final  String time_13_00_13_30 = "13:00 to 13:30";
     private   static   final  String time_13_30_14_00 = "13:30 to 14:00";
     private   static   final  String time_14_00_14_30 = "14:00 to 14:30";
     private   static   final  String time_14_30_15_00 = "14:30 to 15:00";
     private   static   final  String time_15_00_15_30 = "15:00 to 15:30";
     private   static   final  String time_15_30_16_00 = "15:30 to 16:00";
     private   static   final  String time_16_00_16_30 = "16:00 to 16:30";
     private   static   final  String time_16_30_17_00 = "16:30 to 17:00";
     private   static   final  String time_17_00_17_30 = "17:00 to 17:30";
     private   static   final  String time_17_30_18_00 = "17:30 to 18:00";
     private   static   final  String time_18_00_18_30 = "18:00 to 18:30";
     private   static   final  String time_18_30_19_00 = "18:30 to 19:00";
     private   static   final  String time_19_00_19_30 = "19:00 to 19:30";

     private   static   final  String average = "20 day Average / Max";

     private   static   final  String greenBarDescription = "<= 5 seconds";
     private   static   final  String yellowBarDescription = "5 to 15 seconds";
     private   static   final  String orangeBarDescription = "15 to 30 seconds";
     private   static   final  String redBarDescription = "> 30 seconds";

     private   static   final  String RANGE_AXIS = "Time";
     private   static   final  String DOMAIN_AXIS = "Queries";

     private   static  CategoryDataset getAverageDataset() {
        DefaultCategoryDataset dataSet =  new  DefaultCategoryDataset();
        dataSet.addValue( 40 , average, time_06_30_07_00);
        dataSet.addValue( 49 , average, time_07_00_07_30);
        dataSet.addValue( 90 , average, time_07_30_08_00);
        dataSet.addValue( 107 , average, time_08_00_08_30);
        dataSet.addValue( 120 , average, time_08_30_09_00);
        dataSet.addValue( 160 , average, time_09_00_09_30);
        dataSet.addValue( 250 , average, time_09_30_10_00);
        dataSet.addValue( 290 , average, time_10_00_10_30);
        dataSet.addValue( 270 , average, time_10_30_11_00);
        dataSet.addValue( 250 , average, time_11_00_11_30);
        dataSet.addValue( 230 , average, time_11_30_12_00);
        dataSet.addValue( 200 , average, time_12_00_12_30);
        dataSet.addValue( 190 , average, time_12_30_13_00);
        dataSet.addValue( 234 , average, time_13_00_13_30);
        dataSet.addValue( 290 , average, time_13_30_14_00);
        dataSet.addValue( 310 , average, time_14_00_14_30);
        dataSet.addValue( 330 , average, time_14_30_15_00);
        dataSet.addValue( 320 , average, time_15_00_15_30);
        dataSet.addValue( 260 , average, time_15_30_16_00);
        dataSet.addValue( 207 , average, time_16_00_16_30);
        dataSet.addValue( 180 , average, time_16_30_17_00);
        dataSet.addValue( 150 , average, time_17_00_17_30);
        dataSet.addValue( 100 , average, time_17_30_18_00);
        dataSet.addValue( 87 , average, time_18_00_18_30);
        dataSet.addValue( 65 , average, time_18_30_19_00);
        dataSet.addValue( 40 , average, time_19_00_19_30);
         return  dataSet;
    }

     private   static  CategoryDataset getQueriesDataset() {

        DefaultCategoryDataset dataSet =  new  DefaultCategoryDataset();

        dataSet.addValue( 50 , greenBarDescription, time_06_30_07_00);
        dataSet.addValue( 17 , yellowBarDescription, time_06_30_07_00);
        dataSet.addValue( 4 , orangeBarDescription, time_06_30_07_00);
        dataSet.addValue( 1 , redBarDescription, time_06_30_07_00);

        dataSet.addValue( 55 , greenBarDescription, time_07_00_07_30);
        dataSet.addValue( 10 , yellowBarDescription, time_07_00_07_30);
        dataSet.addValue( 17 , orangeBarDescription, time_07_00_07_30);
        dataSet.addValue( 2 , redBarDescription, time_07_00_07_30);

        dataSet.addValue( 70 , greenBarDescription, time_07_30_08_00);
        dataSet.addValue( 13 , yellowBarDescription, time_07_30_08_00);
        dataSet.addValue( 20 , orangeBarDescription, time_07_30_08_00);
        dataSet.addValue( 3 , redBarDescription, time_07_30_08_00);

        dataSet.addValue( 80 , greenBarDescription, time_08_00_08_30);
        dataSet.addValue( 11 , yellowBarDescription, time_08_00_08_30);
        dataSet.addValue( 1 , orangeBarDescription, time_08_00_08_30);
        dataSet.addValue( 4 , redBarDescription, time_08_00_08_30);

        dataSet.addValue( 100 , greenBarDescription, time_08_30_09_00);
        dataSet.addValue( 9 , yellowBarDescription, time_08_30_09_00);
        dataSet.addValue( 34 , orangeBarDescription, time_08_30_09_00);
        dataSet.addValue( 5 , redBarDescription, time_08_30_09_00);

        dataSet.addValue( 200 , greenBarDescription, time_09_00_09_30);
        dataSet.addValue( 10 , yellowBarDescription, time_09_00_09_30);
        dataSet.addValue( 8 , orangeBarDescription, time_09_00_09_30);
        dataSet.addValue( 10 , redBarDescription, time_09_00_09_30);

        dataSet.addValue( 178 , greenBarDescription, time_09_30_10_00);
        dataSet.addValue( 15 , yellowBarDescription, time_09_30_10_00);
        dataSet.addValue( 15 , orangeBarDescription, time_09_30_10_00);
        dataSet.addValue( 7 , redBarDescription, time_09_30_10_00);

        dataSet.addValue( 243 , greenBarDescription, time_10_00_10_30);
        dataSet.addValue( 11 , yellowBarDescription, time_10_00_10_30);
        dataSet.addValue( 3 , orangeBarDescription, time_10_00_10_30);
        dataSet.addValue( 11 , redBarDescription, time_10_00_10_30);

        dataSet.addValue( 217 , greenBarDescription, time_10_30_11_00);
        dataSet.addValue( 7 , yellowBarDescription, time_10_30_11_00);
        dataSet.addValue( 5 , orangeBarDescription, time_10_30_11_00);
        dataSet.addValue( 11 , redBarDescription, time_10_30_11_00);

        dataSet.addValue( 130 , greenBarDescription, time_11_00_11_30);
        dataSet.addValue( 22 , yellowBarDescription, time_11_00_11_30);
        dataSet.addValue( 13 , orangeBarDescription, time_11_00_11_30);
        dataSet.addValue( 21 , redBarDescription, time_11_00_11_30);

        dataSet.addValue( 270 , greenBarDescription, time_11_30_12_00);
        dataSet.addValue( 12 , yellowBarDescription, time_11_30_12_00);
        dataSet.addValue( 13 , orangeBarDescription, time_11_30_12_00);
        dataSet.addValue( 19 , redBarDescription, time_11_30_12_00);

        dataSet.addValue( 234 , greenBarDescription, time_12_00_12_30);
        dataSet.addValue( 10 , yellowBarDescription, time_12_00_12_30);
        dataSet.addValue( 21 , orangeBarDescription, time_12_00_12_30);
        dataSet.addValue( 15 , redBarDescription, time_12_00_12_30);

        dataSet.addValue( 107 , greenBarDescription, time_12_30_13_00);
        dataSet.addValue( 3 , yellowBarDescription, time_12_30_13_00);
        dataSet.addValue( 23 , orangeBarDescription, time_12_30_13_00);
        dataSet.addValue( 45 , redBarDescription, time_12_30_13_00);

        dataSet.addValue( 234 , greenBarDescription, time_13_00_13_30);
        dataSet.addValue( 1 , yellowBarDescription, time_13_00_13_30);
        dataSet.addValue( 21 , orangeBarDescription, time_13_00_13_30);
        dataSet.addValue( 30 , redBarDescription, time_13_00_13_30);

        dataSet.addValue( 300 , greenBarDescription, time_13_30_14_00);
        dataSet.addValue( 12 , yellowBarDescription, time_13_30_14_00);
        dataSet.addValue( 11 , orangeBarDescription, time_13_30_14_00);
        dataSet.addValue( 34 , redBarDescription, time_13_30_14_00);

        dataSet.addValue( 211 , greenBarDescription, time_14_00_14_30);
        dataSet.addValue( 18 , yellowBarDescription, time_14_00_14_30);
        dataSet.addValue( 4 , orangeBarDescription, time_14_00_14_30);
        dataSet.addValue( 30 , redBarDescription, time_14_00_14_30);

        dataSet.addValue( 198 , greenBarDescription, time_14_30_15_00);
        dataSet.addValue( 1 , yellowBarDescription, time_14_30_15_00);
        dataSet.addValue( 15 , orangeBarDescription, time_14_30_15_00);
        dataSet.addValue( 24 , redBarDescription, time_14_30_15_00);

        dataSet.addValue( 234 , greenBarDescription, time_15_00_15_30);
        dataSet.addValue( 7 , yellowBarDescription, time_15_00_15_30);
        dataSet.addValue( 11 , orangeBarDescription, time_15_00_15_30);
        dataSet.addValue( 7 , redBarDescription, time_15_00_15_30);

        dataSet.addValue( 187 , greenBarDescription, time_15_30_16_00);
        dataSet.addValue( 23 , yellowBarDescription, time_15_30_16_00);
        dataSet.addValue( 28 , orangeBarDescription, time_15_30_16_00);
        dataSet.addValue( 9 , redBarDescription, time_15_30_16_00);

        dataSet.addValue( 207 , greenBarDescription, time_16_00_16_30);
        dataSet.addValue( 11 , yellowBarDescription, time_16_00_16_30);
        dataSet.addValue( 118 , orangeBarDescription, time_16_00_16_30);
        dataSet.addValue( 2 , redBarDescription, time_16_00_16_30);

        dataSet.addValue( 178 , greenBarDescription, time_16_30_17_00);
        dataSet.addValue( 8 , yellowBarDescription, time_16_30_17_00);
        dataSet.addValue( 16 , orangeBarDescription, time_16_30_17_00);
        dataSet.addValue( 4 , redBarDescription, time_16_30_17_00);

        dataSet.addValue( 217 , greenBarDescription, time_17_00_17_30);
        dataSet.addValue( 11 , yellowBarDescription, time_17_00_17_30);
        dataSet.addValue( 8 , orangeBarDescription, time_17_00_17_30);
        dataSet.addValue( 3 , redBarDescription, time_17_00_17_30);

        dataSet.addValue( 100 , greenBarDescription, time_17_30_18_00);
        dataSet.addValue( 14 , yellowBarDescription, time_17_30_18_00);
        dataSet.addValue( 13 , orangeBarDescription, time_17_30_18_00);
        dataSet.addValue( 1 , redBarDescription, time_17_30_18_00);

        dataSet.addValue( 80 , greenBarDescription, time_18_00_18_30);
        dataSet.addValue( 23 , yellowBarDescription, time_18_00_18_30);
        dataSet.addValue( 2 , orangeBarDescription, time_18_00_18_30);
        dataSet.addValue( 4 , redBarDescription, time_18_00_18_30);

        dataSet.addValue( 50 , greenBarDescription, time_18_30_19_00);
        dataSet.addValue( 10 , yellowBarDescription, time_18_30_19_00);
        dataSet.addValue( 17 , orangeBarDescription, time_18_30_19_00);
        dataSet.addValue( 3 , redBarDescription, time_18_30_19_00);

        dataSet.addValue( 43 , greenBarDescription, time_19_00_19_30);
        dataSet.addValue( 17 , yellowBarDescription, time_19_00_19_30);
        dataSet.addValue( 8 , orangeBarDescription, time_19_00_19_30);
        dataSet.addValue( 6 , redBarDescription, time_19_00_19_30);

         return  dataSet;
    }

     public   static   void  main(String[] args)  throws  IOException, EmailException {
        // Create first renderer
        CategoryAxis categoryAxis =  new  CategoryAxis(RANGE_AXIS);
        categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        ValueAxis valueAxis =  new  NumberAxis(DOMAIN_AXIS);
        StackedBarRenderer renderer =  new  StackedBarRenderer();
        renderer.setBaseToolTipGenerator(
                 new  StandardCategoryToolTipGenerator());

        // Customize colors
        renderer.setSeriesPaint( 0 ,  new  Color( 51 ,  153 ,  102 ));
        renderer.setSeriesPaint( 1 ,  new  Color( 255 ,  255 ,  0 ));
        renderer.setSeriesPaint( 2 ,  new  Color( 255 ,  153 ,  0 ));
        renderer.setSeriesPaint( 3 ,  new  Color( 255 ,  0 ,  0 ));

        // Create a plot
        CategoryPlot plot =  new  CategoryPlot(getQueriesDataset(), categoryAxis, valueAxis,
                renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        // Add a second dataset and renderer
        LineAndShapeRenderer averageRenderer =  new  LineAndShapeRenderer(true, true);
        averageRenderer.setSeriesStroke(
                 0 ,
                 new  BasicStroke(
                         2 .0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                         1 .0f,  new   float []{ 2 .0f,  6 .0f},  0 .0f
                )
        );
        averageRenderer.setSeriesPaint( 0 ,  new  Color( 255 ,  153 ,  0 ));
        plot.setDataset( 1 , getAverageDataset());
        plot.setRenderer( 1 , averageRenderer);

        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        JFreeChart chart =  new  JFreeChart("Test chart",
                JFreeChart.DEFAULT_TITLE_FONT,
                plot,
                true);
        ByteArrayOutputStream stream =  new  ByteArrayOutputStream();
        ChartUtilities.writeChartAsJPEG(stream, chart,  200 ,  200 );

        MultiPartEmail email =  new  MultiPartEmail();
        email.setHostName("smtp.mail.ru");
        email.setSmtpPort( 25 );
        email.addTo("xxx@xxx.com", "Denik");
        email.setFrom("xxx@mail.ru", "Me");
        email.setAuthentication("xxx", "xxx");
        email.setSubject("Test message");
        email.setMsg("This is a simple test");
         byte [] picture = stream.toByteArray();
        stream.flush();
        stream.close();
        email.attach( new  ByteArrayDataSource(picture, "image/jpeg"), "result.jpeg", "Otchet");
        email.send();

/*        ChartFrame frame = new ChartFrame("Test chart application", chart, true);
        frame.pack();
        RefineryUtilities.centerFrameOnScreen(frame);
        frame.setVisible(true);*/
    }
}

[DeNik]
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / JFreeChart + CommonEmail
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]