16
16
*/
17
17
package com .ericsson .ei .frontend ;
18
18
19
+ import java .io .BufferedInputStream ;
20
+ import java .io .BufferedReader ;
19
21
import java .io .File ;
20
22
import java .io .FileInputStream ;
21
23
import java .io .FileNotFoundException ;
22
24
import java .io .IOException ;
23
25
import java .io .InputStream ;
26
+ import java .io .InputStreamReader ;
27
+ import java .io .StringWriter ;
28
+ import java .net .URL ;
29
+ import java .nio .charset .Charset ;
30
+ import java .nio .charset .StandardCharsets ;
31
+ import java .nio .file .Files ;
32
+ import java .nio .file .Path ;
33
+ import java .nio .file .Paths ;
24
34
25
35
import javax .servlet .ServletContext ;
26
36
import javax .servlet .http .HttpServletRequest ;
27
37
import javax .servlet .http .HttpServletResponse ;
28
38
39
+ import org .omg .IOP .Encoding ;
29
40
import org .springframework .beans .factory .annotation .Autowired ;
30
41
import org .springframework .beans .factory .annotation .Value ;
31
42
import org .springframework .boot .context .properties .ConfigurationProperties ;
37
48
import org .springframework .web .bind .annotation .RequestMethod ;
38
49
import org .springframework .web .bind .annotation .ResponseBody ;
39
50
51
+ import com .google .common .io .CharStreams ;
40
52
import com .sun .glass .ui .Application ;
53
+ import org .apache .tomcat .util .http .fileupload .IOUtils ;
41
54
42
55
import org .springframework .web .bind .annotation .RequestBody ;
43
56
@@ -48,29 +61,31 @@ public class SubscriptionFilesController {
48
61
@ Autowired
49
62
private ResourceLoader resourceLoader ;
50
63
64
+ @ Autowired
65
+ ServletContext servletContext ;
66
+
51
67
@ Value ("${ei.subscriptionFilePath}" ) private String subscriptionFilePath ;
52
68
private static final String APPLICATION_JSON = "application/json" ;
53
69
54
70
55
71
@ RequestMapping (value = "/download/subscriptiontemplate" , method = RequestMethod .GET , produces = APPLICATION_JSON )
56
- public @ ResponseBody void getSubscriptionJsonTemplate (HttpServletResponse response ) throws IOException {
72
+ public void getSubscriptionJsonTemplate (HttpServletResponse response ) throws IOException {
57
73
58
- Resource resource = resourceLoader .getResource ("classpath:" + subscriptionFilePath );
59
- File file = resource .getFile ();
60
- InputStream in = new FileInputStream (file );
74
+ InputStream is = null ;
75
+ try {
76
+ is = getClass ().getResourceAsStream ("/subscriptionsTemplate.json" );
77
+ } catch (NullPointerException e ) {
78
+ System .out .println ("ERROR: " + e .getMessage ());
79
+ }
80
+
81
+ try {
82
+ IOUtils .copy (is , response .getOutputStream ());
83
+ response .getOutputStream ().flush ();
84
+ } catch (IOException e ) {
85
+ System .out .println ("Error :- " + e .getMessage ());
86
+ }
61
87
62
- response .setContentType (APPLICATION_JSON );
63
- response .setHeader ("Content-Disposition" , "attachment; filename=" + file .getName ());
64
- response .setHeader ("Content-Length" , String .valueOf (file .length ()));
65
- FileCopyUtils .copy (in , response .getOutputStream ());
66
88
}
67
-
68
-
69
- // @RequestMapping(value = "/upload/subscriptions", method = RequestMethod.GET, produces = APPLICATION_JSON)
70
- // public @ResponseBody void validateAndCreateSubscriptions(@RequestBody File subscriptionJsonFile) throws IOException {
71
- //
72
- //
73
- // }
74
89
75
90
76
91
private File getFile (String filePath ) throws FileNotFoundException {
0 commit comments