Chitra
Chitra

Reputation: 21

404 error while connecting to Jira server using java

I'm trying to connect jira server using java, I'm receiving "404 error". I'm sharing the base url and code using which i'm trying to connect the jira server, please let me know what is wrong

public class Automate {
    public static void main(String[] args) {
    String baseURL = "https://thread.atlassian.net/";
        String loginURL = "auth/1/session";
        String loginUserName = "*********.com";
        String loginPassword = "*******";
if (!errorOccurred) {
            loginResponse = loginToJira(baseURL, loginURL, loginUserName, loginPassword);
            if (loginResponse == "ERROR") {
                errorOccurred = true;
            }
        }
public static String loginToJira(String baseURL, String loginURL, String loginUserName, String loginPassword) {
        String loginResponse = "";
        URL url = null;
        HttpURLConnection conn = null;
        String input = "";
        OutputStream outputStream = null;
        BufferedReader bufferedReader = null;
        String output = null;
        try {
            //Create URL
            url = new URL(baseURL + loginURL);
            //Use URL to create connection
            conn = (HttpURLConnection) url.openConnection();
            //Set properties
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("content.type", "application/json");
            //Create Json post object
            input = "{\"Username\" :\"" + loginUserName + "\" \"Password\" :\"" + loginPassword + "\"}";
            //Send our request
            outputStream = conn.getOutputStream();
            //System.out.println("outputStream:"+outputStream);
            outputStream.write(input.getBytes());
            //System.out.println("outputStream after writing input:"+outputStream);
            outputStream.flush();
            //System.out.println("outputStream after Flushing:"+outputStream);
            //Handle our response
            System.out.println("Get Response :"+ conn.getResponseCode() );
            if (conn.getResponseCode() == 200) {
                bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                System.out.println("Connection Stream:"+bufferedReader);
                while ((output = bufferedReader.readLine()) != null) {
                    loginResponse += output;

                }
                conn.disconnect();
            }
        } catch (Exception ex) {
            //Handle errors
            System.out.println("Error in login Jira" + ex.getMessage());
            return loginResponse = "ERROR";
        }
        System.out.println("\nloginResponse:");
        System.out.println(loginResponse);
        return loginResponse;
    }
}

Upvotes: 0

Views: 156

Answers (1)

Please check the URL again. The page does not exist even when accessed from a browser. Try using just base URL as it redirects to login or a different login URL.

Upvotes: 1

Related Questions