title: Getting a 404 error when calling Get Request in Java
body: <p>I trying to call a GET request on a specific API endpoint in order to get product information. I have two netbeans projects, one for the server in which i have my end points and another for my GUI.</p>
  
  <p>In my GUI class I have button to GET product information and I am trying to put the returned JSON into a TextArea in Swing. I have two classes within my GUI project, one for a client get that returns the json as a string and another class for my jFrame.</p>
  
  <blockquote>
    <p>Strangely, when i call my client class on button click i get :
    !Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Failed >: HTTP error code : 404</p>
  </blockquote>
  
  <p>When I simply run the client class by itself i do get my expected output in the console, not sure how to fix this if anyone could help?</p>
  
  <p>ClientCall.java</p>
  
  <pre><code>public class ClientCall{
  
  String tempOut = "";
  
  public String getProduct() throws ClientProtocolException, IOException  {
  
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpGet getRequest = new HttpGet(
              "http://localhost:8080/api/product/1");
      getRequest.addHeader("accept", "application/json");
  
      HttpResponse response = httpClient.execute(getRequest);
  
      if (response.getStatusLine().getStatusCode() != 200) {
              throw new RuntimeException("Failed : HTTP error code : "
                 + response.getStatusLine().getStatusCode());
      }
  
      BufferedReader br = new BufferedReader(
               new InputStreamReader((response.getEntity().getContent())));
  
      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
              System.out.println(output);
      }
      tempOut = output;
      httpClient.getConnectionManager().shutdown();
  
      return tempOut;
  }
  
  /*public static void main(String args[]) throws IOException{
      ClientCall c = new ClientCall();
      System.out.println(c.getProduct());
  }*/
  </code></pre>
  
  <p>}</p>
  
  <p>GUI.java</p>
  
  <pre><code>private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
      // TODO add your handling code here:
      System.out.print("!");
      try {
          System.out.println(cc.getProduct());
  
      } catch (IOException ex) {
          Logger.getLogger(GetDetailsGUI.class.getName()).log(Level.SEVERE, null, ex);
      }
  }    
  </code></pre>
  
  <p>Note, In my code above (GUI) i am simply outputting the response, even this doesnt work.</p>