Java Spring end URL with a file extension
I have a service that returns a string. String is in the form of XML. The URL is /monitoring. But the client now wants, that the URL ends with /status.xml. How do I do that? I tried to change the value in the GetMapping, but then it stopped working. Is there anything special in URL ending with status.xml and how can I achieve this?
@GetMapping(value = "/monitoring")
public ResponseEntity getStatuses() throws TransformerException, UnsupportedEncodingException, JAXBException
return indexService.getStatusEntity();
public ResponseEntity getStatusEntity() throws JAXBException, UnsupportedEncodingException, TransformerException
byte xml = getStatus();
String xmlStr = new String(xml, "UTF-8");
xmlStr = xmlStr.replaceAll("<", "<");
xmlStr = xmlStr.replaceAll(">", ">");
Source src = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
transformer.transform(src, result);
return setDocumentHeaderAndReturnOK(bos.toByteArray());
private byte getStatus() throws JAXBException
String tomcat = ServerInfo.getServerInfo();
String pieces = tomcat.split("/");
App status = new App(applicationInfoService.getVersion().getBody(), "name", "OK", "",
new ServerPlatform(pieces[1], pieces[0]), new RunTimeEnvironment(System.getProperty("java.version"), "JAVA"),
checkExternalDependencies());
QName main = new QName("app");
JAXBElement<App> root = new JAXBElement<>(main, App.class, status);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(App.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(root, out);
jaxbMarshaller.marshal(root, System.out);
return out.toByteArray();
@Transactional
public ResponseEntity setDocumentHeaderAndReturnOK(byte contents) {
HttpHeaders headers = new HttpHeaders();
String fileType = "xml";
String filename = "status.xml";
headers.setContentType(MediaType.parseMediaType("application/" + fileType));
headers.add("Content-Disposition", "inline; filename=" + filename);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
return new ResponseEntity(contents, headers, HttpStatus.OK);
EDIT:
I tried generating the classes with jaxb and the use those to make the XML. But that does not change the url. I have the XML content generated correctly, i just need a way to get the GetMapping from /monitoring to /status.xml. What does it even mean to have a url in the form of status.xml ?
java spring
add a comment |
I have a service that returns a string. String is in the form of XML. The URL is /monitoring. But the client now wants, that the URL ends with /status.xml. How do I do that? I tried to change the value in the GetMapping, but then it stopped working. Is there anything special in URL ending with status.xml and how can I achieve this?
@GetMapping(value = "/monitoring")
public ResponseEntity getStatuses() throws TransformerException, UnsupportedEncodingException, JAXBException
return indexService.getStatusEntity();
public ResponseEntity getStatusEntity() throws JAXBException, UnsupportedEncodingException, TransformerException
byte xml = getStatus();
String xmlStr = new String(xml, "UTF-8");
xmlStr = xmlStr.replaceAll("<", "<");
xmlStr = xmlStr.replaceAll(">", ">");
Source src = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
transformer.transform(src, result);
return setDocumentHeaderAndReturnOK(bos.toByteArray());
private byte getStatus() throws JAXBException
String tomcat = ServerInfo.getServerInfo();
String pieces = tomcat.split("/");
App status = new App(applicationInfoService.getVersion().getBody(), "name", "OK", "",
new ServerPlatform(pieces[1], pieces[0]), new RunTimeEnvironment(System.getProperty("java.version"), "JAVA"),
checkExternalDependencies());
QName main = new QName("app");
JAXBElement<App> root = new JAXBElement<>(main, App.class, status);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(App.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(root, out);
jaxbMarshaller.marshal(root, System.out);
return out.toByteArray();
@Transactional
public ResponseEntity setDocumentHeaderAndReturnOK(byte contents) {
HttpHeaders headers = new HttpHeaders();
String fileType = "xml";
String filename = "status.xml";
headers.setContentType(MediaType.parseMediaType("application/" + fileType));
headers.add("Content-Disposition", "inline; filename=" + filename);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
return new ResponseEntity(contents, headers, HttpStatus.OK);
EDIT:
I tried generating the classes with jaxb and the use those to make the XML. But that does not change the url. I have the XML content generated correctly, i just need a way to get the GetMapping from /monitoring to /status.xml. What does it even mean to have a url in the form of status.xml ?
java spring
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29
add a comment |
I have a service that returns a string. String is in the form of XML. The URL is /monitoring. But the client now wants, that the URL ends with /status.xml. How do I do that? I tried to change the value in the GetMapping, but then it stopped working. Is there anything special in URL ending with status.xml and how can I achieve this?
@GetMapping(value = "/monitoring")
public ResponseEntity getStatuses() throws TransformerException, UnsupportedEncodingException, JAXBException
return indexService.getStatusEntity();
public ResponseEntity getStatusEntity() throws JAXBException, UnsupportedEncodingException, TransformerException
byte xml = getStatus();
String xmlStr = new String(xml, "UTF-8");
xmlStr = xmlStr.replaceAll("<", "<");
xmlStr = xmlStr.replaceAll(">", ">");
Source src = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
transformer.transform(src, result);
return setDocumentHeaderAndReturnOK(bos.toByteArray());
private byte getStatus() throws JAXBException
String tomcat = ServerInfo.getServerInfo();
String pieces = tomcat.split("/");
App status = new App(applicationInfoService.getVersion().getBody(), "name", "OK", "",
new ServerPlatform(pieces[1], pieces[0]), new RunTimeEnvironment(System.getProperty("java.version"), "JAVA"),
checkExternalDependencies());
QName main = new QName("app");
JAXBElement<App> root = new JAXBElement<>(main, App.class, status);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(App.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(root, out);
jaxbMarshaller.marshal(root, System.out);
return out.toByteArray();
@Transactional
public ResponseEntity setDocumentHeaderAndReturnOK(byte contents) {
HttpHeaders headers = new HttpHeaders();
String fileType = "xml";
String filename = "status.xml";
headers.setContentType(MediaType.parseMediaType("application/" + fileType));
headers.add("Content-Disposition", "inline; filename=" + filename);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
return new ResponseEntity(contents, headers, HttpStatus.OK);
EDIT:
I tried generating the classes with jaxb and the use those to make the XML. But that does not change the url. I have the XML content generated correctly, i just need a way to get the GetMapping from /monitoring to /status.xml. What does it even mean to have a url in the form of status.xml ?
java spring
I have a service that returns a string. String is in the form of XML. The URL is /monitoring. But the client now wants, that the URL ends with /status.xml. How do I do that? I tried to change the value in the GetMapping, but then it stopped working. Is there anything special in URL ending with status.xml and how can I achieve this?
@GetMapping(value = "/monitoring")
public ResponseEntity getStatuses() throws TransformerException, UnsupportedEncodingException, JAXBException
return indexService.getStatusEntity();
public ResponseEntity getStatusEntity() throws JAXBException, UnsupportedEncodingException, TransformerException
byte xml = getStatus();
String xmlStr = new String(xml, "UTF-8");
xmlStr = xmlStr.replaceAll("<", "<");
xmlStr = xmlStr.replaceAll(">", ">");
Source src = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
transformer.transform(src, result);
return setDocumentHeaderAndReturnOK(bos.toByteArray());
private byte getStatus() throws JAXBException
String tomcat = ServerInfo.getServerInfo();
String pieces = tomcat.split("/");
App status = new App(applicationInfoService.getVersion().getBody(), "name", "OK", "",
new ServerPlatform(pieces[1], pieces[0]), new RunTimeEnvironment(System.getProperty("java.version"), "JAVA"),
checkExternalDependencies());
QName main = new QName("app");
JAXBElement<App> root = new JAXBElement<>(main, App.class, status);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(App.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(root, out);
jaxbMarshaller.marshal(root, System.out);
return out.toByteArray();
@Transactional
public ResponseEntity setDocumentHeaderAndReturnOK(byte contents) {
HttpHeaders headers = new HttpHeaders();
String fileType = "xml";
String filename = "status.xml";
headers.setContentType(MediaType.parseMediaType("application/" + fileType));
headers.add("Content-Disposition", "inline; filename=" + filename);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
return new ResponseEntity(contents, headers, HttpStatus.OK);
EDIT:
I tried generating the classes with jaxb and the use those to make the XML. But that does not change the url. I have the XML content generated correctly, i just need a way to get the GetMapping from /monitoring to /status.xml. What does it even mean to have a url in the form of status.xml ?
java spring
java spring
edited Nov 28 '18 at 8:48
Marko Taht
asked Nov 13 '18 at 7:15
Marko TahtMarko Taht
3541419
3541419
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29
add a comment |
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275722%2fjava-spring-end-url-with-a-file-extension%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275722%2fjava-spring-end-url-with-a-file-extension%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi @Marko, would you add your code?
– Reg
Nov 13 '18 at 7:51
@Reg i added the code.
– Marko Taht
Nov 13 '18 at 8:02
Do you have any resource mappers?
– Reg
Nov 13 '18 at 8:34
For swagger. Cant seem to find anything else.
– Marko Taht
Nov 13 '18 at 10:29
@Reg what exactly do you mean under resource mappers?
– Marko Taht
Nov 27 '18 at 14:29