3939import javax .xml .xpath .XPathFactory ;
4040
4141import org .springframework .beans .factory .annotation .Autowired ;
42+ import org .springframework .http .HttpEntity ;
43+ import org .springframework .http .HttpHeaders ;
4244import org .springframework .http .HttpStatus ;
4345import org .springframework .http .MediaType ;
4446import org .springframework .http .ResponseEntity ;
@@ -157,8 +159,6 @@ public ResponseEntity<PostMetadataResponse> postMetadataNG(HttpServletRequest re
157159 // return Response.ok(xml).build();
158160 Document xmlDoc = document .getOutput ();
159161
160- service .saveMetadata (document , xml , elementList , service .isTestServer (req ));
161-
162162 document .saveTo ("/tmp/last_md.xml" );
163163
164164 try {
@@ -174,6 +174,7 @@ public ResponseEntity<PostMetadataResponse> postMetadataNG(HttpServletRequest re
174174 response .setMessages (document .getMessages ());
175175
176176 if ( elementList .getXsltChain () == null ) {
177+ service .saveMetadata (document , xml , elementList , service .isTestServer (req ));
177178 } else {
178179 log .info ("xsltChain is correctly defined in EDIML" );
179180 String xmlTemp = new String (document .xmlUTF8String (xmlDoc ), "utf-8" );
@@ -187,9 +188,10 @@ public ResponseEntity<PostMetadataResponse> postMetadataNG(HttpServletRequest re
187188 xmlTemp = new String (result , "utf-8" );
188189 }
189190 }
191+ document .setOutput (service .loadXMLFromString (xmlTemp ));
192+ service .saveMetadata (document , xml , elementList , service .isTestServer (req ));
190193 response .setGeneratedXml (xmlTemp );
191-
192- System .out .println ("Морски" );
194+
193195 return new ResponseEntity <PostMetadataResponse >(response , HttpStatus .OK );
194196 }
195197 } catch (Exception e ) {
@@ -210,6 +212,42 @@ public ResponseEntity<PostMetadataResponse> optionsPostMetadata(String xml) {
210212 }
211213
212214
215+ @ RequestMapping (method = RequestMethod .GET , value = "/rest/xml/{id}.{suffix}" , produces = MediaType .APPLICATION_XML_VALUE )
216+ @ ResponseBody
217+ public HttpEntity <byte []> getXml (@ PathVariable int id , @ PathVariable String suffix ) {
218+ log .info ("getXml " + id + ", " + suffix );
219+ Metadata md = service .getMetadata (id );
220+
221+ HttpHeaders header = new HttpHeaders ();
222+ // header.setContentType(new MediaType("application", "pdf"));
223+ header .set ("Content-Disposition" ,
224+ "attachment; filename=generated_" + id + ".xml" );
225+ // header.setContentLength(documentBody.length);
226+
227+ return new HttpEntity <byte []>(md .getOutput ().getBytes (), header );
228+ }
229+
230+ @ RequestMapping (method = RequestMethod .GET , value = "/rest/edimlFile/{id}.{suffix}" , produces = MediaType .APPLICATION_XML_VALUE )
231+ @ ResponseBody
232+ public HttpEntity <byte []> getEdimlFile (@ PathVariable int id , @ PathVariable String suffix ) {
233+ log .info ("getEdimlFile " + id + ", " + suffix );
234+ Metadata md = service .getMetadata (id );
235+
236+ HttpHeaders header = new HttpHeaders ();
237+ // header.setContentType(new MediaType("application", "pdf"));
238+ header .set ("Content-Disposition" ,
239+ "attachment; filename=ediml_" + id + ".xml" );
240+ // header.setContentLength(documentBody.length);
241+ Document doc = null ;
242+ try {
243+ doc = service .loadXMLFromString (md .getInput ());
244+ } catch (Exception e ) {
245+ // TODO Auto-generated catch block
246+ e .printStackTrace ();
247+ }
248+ return new HttpEntity <byte []>(doc .toString ().getBytes (), header );
249+ }
250+
213251 @ RequestMapping (method = RequestMethod .GET , value = "/rest/ediml/{id}" , produces = MediaType .APPLICATION_XML_VALUE )
214252 @ ResponseBody
215253 public String getEDIMLXml (@ PathVariable int id ) {
0 commit comments