Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String REST_SERVICE_URL = "http://rnguy.no-ip.biz:8080/com.KNASK.TodayInTheCity.11.21.00.36/rest/show";
- private static final XmlFactory f = new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl());
- private static final JacksonXmlModule module = new JacksonXmlModule();
- private static final XmlMapper xmlMapper = new XmlMapper(f, module);
- @Override
- public int create(Show show) {
- try {
- URL currentURL = null;
- try {
- currentURL = new URL(REST_SERVICE_URL);
- } catch (MalformedURLException e) {
- }
- HttpURLConnection conn = (HttpURLConnection) currentURL.openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-Type", "application/xml");
- OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
- xmlMapper.writeValue(osw, show);
- if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
- throw new RuntimeException("Failed : HTTP error code : "
- + conn.getResponseCode());
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(
- (conn.getInputStream())));
- String output;
- System.out.println("Output from Server .... \n");
- while ((output = br.readLine()) != null) {
- System.out.println(output);
- }
- conn.disconnect();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement