0

i am facing problem when i am executing the following code. i am also having same kind of function which perform rest Method DELETE and PUT those are working great with the same config, but this is not.

public void Rest_POST(String cookie)
{
String urlString = "https://localhost:8443/rest/api/2/version";
    HttpsURLConnection urlConnection;
    String cookie = getCookie();
     String JSONString = "{" +
             "\"description\":\"An excellent version\"," +
             "\"name\":\"New Version 54164987\"," +
             "\"project\":\"zhelp\"" +
             "}";
URL url;
    OutputStream os;
    HttpsURLConnection connection = null;
    try {
        //this skips the certification check
        certificateManager.skipCertificateCheck();
        url = new URL(urlString);
        connection = (HttpsURLConnection) url.openConnection();
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Content-Language", "en-US");
        if(cookie != null) {
            System.out.println("Cookie : " + cookie.split(";", 2)[0]);
            connection.setRequestProperty("Cookie", cookie.split(";", 2)[0]);
        }

        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept", "application/json");
        connection.setAllowUserInteraction(true);

        os = connection.getOutputStream();
        System.out.println("JSONString : " + JSONString);
        os.write(JSONString.getBytes());
        os.flush();

        System.out.println("Connection : " + connection.getURL());
  }

this generates the error FileNotfound exception.

Error Message: https://localhost:8443/rest/api/2/version
Cause: java.io.FileNotFoundException: https://localhost:8443/rest/api/2/version
Sohil
  • 51
  • 7
  • In the method body you specify the port as 2990, yet the error message mentions port 8443, which one is right? – Jukka Jun 06 '13 at 05:40
  • See http://stackoverflow.com/questions/5379247/filenotfoundexception-while-getting-the-inputstream-object-from-httpurlconnectio for a possible solution – Jukka Jun 06 '13 at 05:58
  • I have seen that ! not resolved my problem! any other tip? – Sohil Jun 06 '13 at 06:19
  • Which line throws the exception? –  Jun 06 '13 at 06:39
  • What does the service return if you execute the POST e.g.with Firefox's restclient? – Jukka Jun 07 '13 at 15:08

1 Answers1

1

i'm newbie for java may be this solution useful to you

First give

connection.setDoOutput(true); connection.setDoInput(true);

if not resolved means any other service using your port 8443 when this case Resource was available through browser, but not from Java code. either stopping conflicting service or change port number of your server everything works fine

Anand saga
  • 1,433
  • 11
  • 23