0

I am using demo instance to query service-now. Using cURL works fine, but I want to use java to query the Table API. I have followed this. I have provided my instance credentials and the instance name correctly. I get error like this:

$ javac GetAction.java
GetAction.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpException;
                      ^
GetAction.java:7: error: package org.apache.http does not exist
import org.apache.http.HttpHost;
                      ^
GetAction.java:8: error: package org.apache.http.auth does not exist
import org.apache.http.auth.AuthScope;
                           ^
GetAction.java:9: error: package org.apache.http.auth does not exist
import org.apache.http.auth.UsernamePasswordCredentials;
                           ^
GetAction.java:10: error: package org.apache.http.client does not exist
import org.apache.http.client.CredentialsProvider;
                             ^
GetAction.java:11: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.CloseableHttpResponse;
                                     ^
GetAction.java:12: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpGet;
                                     ^
GetAction.java:13: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.BasicCredentialsProvider;
                                  ^
GetAction.java:14: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.CloseableHttpClient;
                                  ^
GetAction.java:15: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.HttpClients;
                                  ^
GetAction.java:16: error: package org.apache.http.util does not exist
import org.apache.http.util.EntityUtils;
                           ^
GetAction.java:19: error: cannot find symbol
        public static void main(String[] args) throws IOException, HttpException {
                                                                   ^
  symbol:   class HttpException
  location: class GetAction
GetAction.java:24: error: cannot find symbol
        public void getRequest() throws HttpException, IOException {
                                        ^
  symbol:   class HttpException
  location: class GetAction
GetAction.java:25: error: cannot find symbol
                CredentialsProvider credsProvider = new BasicCredentialsProvider();
                ^
  symbol:   class CredentialsProvider
  location: class GetAction
GetAction.java:25: error: cannot find symbol
                CredentialsProvider credsProvider = new BasicCredentialsProvider();
                                                        ^
  symbol:   class BasicCredentialsProvider
  location: class GetAction
GetAction.java:27: error: cannot find symbol
                new AuthScope(new HttpHost("xxxxxxxx.service-now.com")),
                    ^
  symbol:   class AuthScope
  location: class GetAction
GetAction.java:27: error: cannot find symbol
                new AuthScope(new HttpHost("xxxxxxxx.service-now.com")),
                                  ^
  symbol:   class HttpHost
  location: class GetAction
GetAction.java:28: error: cannot find symbol
                new UsernamePasswordCredentials("wwwww", "yyyyyy"));
                    ^
  symbol:   class UsernamePasswordCredentials
  location: class GetAction
GetAction.java:29: error: cannot find symbol
        CloseableHttpClient httpclient = HttpClients.custom()
        ^
  symbol:   class CloseableHttpClient
  location: class GetAction
GetAction.java:29: error: cannot find symbol
        CloseableHttpClient httpclient = HttpClients.custom()
                                         ^
  symbol:   variable HttpClients
  location: class GetAction
GetAction.java:34: error: cannot find symbol
            HttpGet httpget = new HttpGet("https://xxxxxxxx.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000057&sysparm_limit=1");
            ^
  symbol:   class HttpGet
  location: class GetAction
GetAction.java:34: error: cannot find symbol
            HttpGet httpget = new HttpGet("https://xxxxxxxx.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000057&sysparm_limit=1");
                                  ^
  symbol:   class HttpGet
  location: class GetAction
GetAction.java:37: error: cannot find symbol
            CloseableHttpResponse response = httpclient.execute(httpget);
            ^
  symbol:   class CloseableHttpResponse
  location: class GetAction
GetAction.java:41: error: cannot find symbol
                String responseBody = EntityUtils.toString(response.getEntity());
                                      ^
  symbol:   variable EntityUtils
  location: class GetAction
24 errors

How to make the documentation code work? Any help will be appreciated.

1 Answers1

0

The error says that the mentioned dependencies are not present. You need to add jar file for package org.apache.http. If you are using maven, you can get the library from here.

Kaushal28
  • 5,377
  • 5
  • 41
  • 72