0

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;
    }
}

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response, i tried using multiple URLs. The issue is still the same .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.