Class HttpOp

java.lang.Object
org.apache.jena.http.HttpOp

public class HttpOp extends Object
This is a collection of convenience operations for HTTP requests, mostly in support of RDF handling and common, basic use cases for HTTP. It is not comprehensive. For more complicated requirements of HTTP, then the application can use HttpClient directly.

Authentication can be handled by supplying a HttpClient which has been built with an Authenticator or for challenge response (basic and digest) see AuthEnv.

Operations throw HttpException when the response is not 2xx, except for "httpGetString" and "httpPostRtnString" which return null for a 404 response.

Also supported:

  • GET and return a string
  • GET and return a JSON structure

See Also:
  • Method Details

    • httpGetString

      public static String httpGetString(String url)
      Perform an HTTP and return the body as a string, Return null for a "404 Not Found".
    • httpGetString

      public static String httpGetString(String url, String acceptHeader)
      Perform an HTTP and return the body as a string, Return null for a "404 Not Found".
    • httpGetString

      public static String httpGetString(java.net.http.HttpClient httpClient, String url)
      Perform an HTTP and return the body as a string. Return null for a "404 Not Found".
    • httpGetString

      public static String httpGetString(java.net.http.HttpClient httpClient, String url, String acceptHeader)
      Perform an HTTP and return the body as a string. Return null for a "404 Not Found".
    • httpPostRtnString

      public static String httpPostRtnString(String url)
      POST (without a body) - like httpGetString but uses POST - expects a response. Return null for a "404 Not Found".
    • httpPostRtnString

      public static String httpPostRtnString(java.net.http.HttpClient httpClient, String url)
      POST (without a body) - like httpGetString but uses POST - expects a response. Return null for a "404 Not Found".
    • httpPostForm

      public static void httpPostForm(String url, Params params)
      POST params as a HTML form.
    • httpPostForm

      public static TypedInputStream httpPostForm(String url, Params params, String acceptString)
      POST params as a HTML form.
    • httpPostRtnJSON

      public static JsonValue httpPostRtnJSON(String url)
    • httpGetJson

      public static JsonValue httpGetJson(String url)
    • httpGet

      public static TypedInputStream httpGet(String url)
      Perform an HTTP GET to a URL, with "Accept" header "*/*". The application MUST close the InputStream.
    • httpGet

      public static TypedInputStream httpGet(String url, String acceptHeader)
      Perform an HTTP GET to a URL. The application MUST close the InputStream.
    • httpGet

      public static TypedInputStream httpGet(java.net.http.HttpClient httpClient, String url)
      Perform an HTTP GET to a URL. The application MUST close the InputStream.
    • httpGet

      public static TypedInputStream httpGet(java.net.http.HttpClient httpClient, String url, String acceptHeader)
      Perform an HTTP GET to a URL. The application MUST close the InputStream.
    • httpPost

      public static void httpPost(String url)
      POST
    • httpPost

      public static void httpPost(String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      POST
      See Also:
      • HttpRequest.BodyPublishers
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpPost

      public static void httpPost(String url, String contentType, String body)
      POST to a URL with content=type and string.
    • httpPost

      public static void httpPost(java.net.http.HttpClient httpClient, String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      POST
      See Also:
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpPostStream

      public static TypedInputStream httpPostStream(String url)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(String url, String acceptHeader)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(java.net.http.HttpClient httpClient, String url)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(java.net.http.HttpClient httpClient, String url, String acceptHeader)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(String url, String contentType, java.net.http.HttpRequest.BodyPublisher bodyContent)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(String url, String contentType, String bodyContent)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(String url, String contentType, java.net.http.HttpRequest.BodyPublisher bodyContent, String acceptHeader)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(java.net.http.HttpClient httpClient, String url, String contentType, java.net.http.HttpRequest.BodyPublisher bodyContent)
      POST - the application MUST close the InputStream.
    • httpPostStream

      public static TypedInputStream httpPostStream(java.net.http.HttpClient httpClient, String url, String contentType, java.net.http.HttpRequest.BodyPublisher bodyContent, String acceptHeader)
      POST - the application MUST close the InputStream.
    • httpPut

      public static void httpPut(String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      PUT
      See Also:
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpPut

      public static void httpPut(java.net.http.HttpClient httpClient, String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      PUT
      See Also:
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpPatch

      public static void httpPatch(String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      PATCH
      See Also:
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpPatch

      public static void httpPatch(java.net.http.HttpClient httpClient, String url, String contentType, java.net.http.HttpRequest.BodyPublisher body)
      PATCH
      See Also:
      • HttpRequest.BodyPublishers
      • HttpRequest.BodyPublishers.ofFile(java.nio.file.Path)
      • HttpRequest.BodyPublishers.ofString(java.lang.String)
    • httpDelete

      public static void httpDelete(String url)
      DELETE
    • httpDelete

      public static void httpDelete(java.net.http.HttpClient httpClient, String url)
      DELETE
    • httpOptions

      public static String httpOptions(String url)
      OPTIONS. Returns the HTTP response "Allow" field string.
    • httpOptions

      public static String httpOptions(java.net.http.HttpClient httpClient, String url)
      OPTIONS. Returns the HTTP response "Allow" field string.
    • httpHead

      public static String httpHead(String url)
      HEAD request, return the Content-Type (if any). Return null for success (200) but no content type. Throw HttpException for any response that is not 2xx.
    • httpHead

      public static String httpHead(java.net.http.HttpClient httpClient, String url)
      HEAD request, return the Content-Type (if any). Return null for success (200) but no content type. Throw HttpException for any response that is not 2xx.
    • httpHead

      public static String httpHead(String url, String acceptHeader)
      HEAD request, return the Content-Type (if any). Return null for success (200) but no content type. Throw HttpException for any response that is not 2xx.
    • httpHead

      public static String httpHead(java.net.http.HttpClient httpClient, String url, String acceptHeader)
      HEAD request, return the Content-Type (if any). Return null for success (200) but no content type. Throw HttpException for any response that is not 2xx.