Getting IP Address Using CXF

Run Client

package com.client;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

// Getting The IP Address Of SOAP Clients Using CXF

public class PostStudentClient {

 
public static void main(String[] args) {
   
try {
URL url = new URL("http://localhost:8080/CXFRestfulTutorial/rest/changeName");
      HttpURLConnection conn =
(HttpURLConnection) url.openConnection();
      conn.setDoOutput
(true);
      conn.setRequestMethod
("POST");
      conn.setRequestProperty
("Content-Type", "application/json");

      String input =
"{\"Student\":{\"name\":\"Tom\"}}";

      OutputStream os = conn.getOutputStream
();
      os.write
(input.getBytes());
      os.flush
();

      Scanner scanner;
      String response;
     
if (conn.getResponseCode() != 200) {
       
scanner = new Scanner(conn.getErrorStream());
        response =
"Error From Server \n\n";
     
} else {
       
scanner = new Scanner(conn.getInputStream());
        response =
"Response From Server \n\n";
     
}
     
scanner.useDelimiter("\\Z");
      System.out.println
(response + scanner.next());
      scanner.close
();
      conn.disconnect
();
   
} catch (MalformedURLException e) {
     
e.printStackTrace();
   
} catch (IOException e) {
     
e.printStackTrace();
   
}
  }
}
Output
Response From Server 

{"Student":{"name":"HELLO Tom","studentIP":"117.196.145.171"}}





Previous 1 2








6 Responses to "Getting IP Address Using CXF"
  1. Becker 2012-03-20 07:43:31.0
  1. admin 2012-03-21 07:43:31.0
  1. guru 2012-03-22 07:43:31.0
  1. admin 2012-03-23 07:43:31.0
  1. Joseph 2012-03-24 07:43:31.0
  1. admin 2012-03-25 07:43:31.0

Your email address will not be published. Required fields are marked *