Class JettyHttpClient

java.lang.Object
org.oddjob.jetty.JettyHttpClient
All Implemented Interfaces:
Callable<Integer>

public class JettyHttpClient extends Object implements Callable<Integer>
Author:
rob

Description

Execute an HTTP client request.

This is a very simple wrapper around Jetty's HTTPClient. Only PUT and GET requests are supported. Basic Authentication is supported, and so are SSL connections.

Example

Get the content of a URL using a parameter.

<oddjob>

    <job>

        <sequential>

            <jobs>

                <properties>

                    <values>

                        <value key="some.url" value="http://www.google.com/search"/>

                    </values>

                </properties>

                <web:client id="request" url="${some.url}" xmlns:web="oddjob:web">

                    <parameters>

                        <map>

                            <values>

                                <value key="q" value="gold fish"/>

                            </values>

                        </map>

                    </parameters>

                </web:client>

                <echo>${request.content}</echo>

            </jobs>

        </sequential>

    </job>

</oddjob>
Basic Authentication.

<oddjob id="oddjob">

    <job>

        <web:client id="client" url="http://localhost:${server.port}" xmlns:web="oddjob:web">

            <basicAuthentication>

                <is username="alice" password="secret"/>

            </basicAuthentication>

        </web:client>

    </job>

</oddjob>
Download to a file.
<oddjob>

    <job>

        <sequential>

            <jobs>

                <properties>

                    <values>

                        <value key="some.url" value="http://ipv4.download.thinkbroadband.com/1GB.zip"/>

                        <value key="some.file" value="download.zip"/>

                    </values>

                </properties>

                <web:client id="request" name="Download Example" url="${some.url}" xmlns:web="oddjob:web">

                    <output>

                        <file file="${some.file}"/>

                    </output>

                </web:client>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Field Details

    • DEFAULT_TIMEOUT_SECONDS

      public static final int DEFAULT_TIMEOUT_SECONDS
      See Also:
  • Constructor Details

    • JettyHttpClient

      public JettyHttpClient()
  • Method Details

    • call

      public Integer call() throws Exception
      Specified by:
      call in interface Callable<Integer>
      Throws:
      Exception
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • setUrl

      public void setUrl(String url)
    • getUrl

      public String getUrl()
    • getStatus

      public int getStatus()
    • getContent

      public String getContent()
      Reference Property:
      content

      Description

      The request body to send or the response body received. This maps to requestBody and responseBody as a convenience but is confusing so should probably be deprecated.
      Required:
      No.
    • setContent

      public void setContent(String content)
    • getRequestBody

      public String getRequestBody()
    • setRequestBody

      public void setRequestBody(String requestBody)
    • getResponseBody

      public String getResponseBody()
    • getMethod

      public JettyHttpClient.RequestMethod getMethod()
    • setMethod

      public void setMethod(JettyHttpClient.RequestMethod method)
    • getParameters

      public Map<String,String> getParameters()
    • setParameters

      public void setParameters(Map<String,String> properties)
    • getContentType

      public String getContentType()
    • setContentType

      public void setContentType(String contentType)
    • getBasicAuthentication

      public JettyHttpClient.UsernamePassword getBasicAuthentication()
    • setBasicAuthentication

      public void setBasicAuthentication(JettyHttpClient.UsernamePassword basicAuthentication)
    • getSsl

      public ClientSslProvider getSsl()
    • setSsl

      public void setSsl(ClientSslProvider ssl)
    • getProgress

      public Progress getProgress()
    • getContentLength

      public long getContentLength()
    • getDownloadCount

      public long getDownloadCount()
    • getOutput

      public OutputStream getOutput()
    • setOutput

      public void setOutput(OutputStream output)
    • getTimeout

      public long getTimeout()
    • setTimeout

      public void setTimeout(long timeout)
    • toString

      public String toString()
      Overrides:
      toString in class Object