I need to write a simple function that takes a URL and processes the response which is XML or JSON, I have checked the Sun website https://swingx-ws.dev.java.net/servlets/ProjectDocumentList , but the HttpRequest object is to be found nowhere, is it possible to do this in Java? I`m writting a rich client end app.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Ok I think I have solves the problem below is a working code
Get your response via a regular http-request, using:
URLConnection con = new URL("http://example.com").openConnection()
;The next step is parsing it. Take a look at this article for a choice of parser.
For xml parsing of an inputstream you can do:
But to communicate over http from server to client I prefer using hessian library or springs http invoker lib
If you want to print XML directly onto the screen you can use TransformerFactory
[{ "id": "1", "firstName": "Tom", "lastName": "Cruise", "photo": "https://pbs.twimg.com/profile_images/735509975649378305/B81JwLT7.jpg" }, { "id": "2", "firstName": "Maria", "lastName": "Sharapova", "photo": "https://pbs.twimg.com/profile_images/3424509849/bfa1b9121afc39d1dcdb53cfc423bf12.jpeg" }, { "id": "3", "firstName": "James", "lastName": "Bond", "photo": "https://pbs.twimg.com/profile_images/664886718559076352/M00cOLrh.jpg" }] `
`
If you specifically want to use SwingX-WS, then have a look at XmlHttpRequest and JSONHttpRequest.
More on those classes in the XMLHttpRequest and Swing blog post.