I have a generated XML data file. I want it to be available in Endpoint instead of "hello".
In conclusion, I want to type localhost: 8080 / XML and see the data from the XML file I have in the folder.
Instead of hardcoded text just read the file content as bytes. The rest is the same. I'm sure you can google out plenty of examples like this one:
Path path = Paths.get("C:/temp/test.xml"); byte[] data = Files.readAllBytes(path);
Then :
exchange.getResponseHeaders().put("Content-Type", "text/xml"); exchange.sendResponseHeaders(200, data.length); OutputStream output = exchange.getResponseBody(); output.write(data); output.flush(); exchange.close();
Haven't checked it compiles but give it a try.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have a generated XML data file. I want it to be available in Endpoint instead of "hello".
In conclusion, I want to type localhost: 8080 / XML and see the data from the XML file I have in the folder.
Instead of hardcoded text just read the file content as bytes. The rest is the same.
I'm sure you can google out plenty of examples like this one:
Then :
Haven't checked it compiles but give it a try.