public class HttpClient
extends java.lang.Object
This class does its best to comply with the "TAXII HTTP Protocol Binding Specification". It handles interaction with a TAXII HTTP server. This includes serializing TAXII Messages, managing the connection to the remote end point, parsing and unmarshaling the responses, and returning a TAXII Message back to the user.
There are two important components of this class.
HttpClient#getHttpClient
This manages the HTTP protocol interaction.
The default constructor will create a simple, pre-configured HttpClient based
on the system properties. If you wish to use an HttpClient configured to use
an explicit proxy, or a security certificate, you will need to construct and
configure it, then apply it to the TAXII HttpClient.
TaxiiXml
objects, stored in taxiiXmlMap
. These objects understand the TAXII JAXB environment.
They are configured to handle parsing and generating a certain version of TAXII
messages. There can be only one TaxiiXml
object per TAXII version.
The default constructor will create TaxiiXml
objects for TAXII 1.0 and 1.1.
You may, for example, want to provide a TaxiiXml
object configured to handle
STIX content blocks as well as TAXII 1.1 messages.
HttpClient taxiiClient = new HttpClient(); final String serverUrl = "http://127.0.0.1:8080/services/discovery/"; // Prepare the message to send. DiscoveryRequest dr = factory.createDiscoveryRequest() .withMessageId(MessageHelper.generateMessageId()); // Call the service Object responseObj = taxiiClient.callTaxiiService(new URI(serverUrl), dr);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HEADER_ACCEPT
HTTP Accept header name
|
static java.lang.String |
HEADER_CONTENT_TYPE
HTTP Content-Type header name
|
static java.lang.String |
HEADER_X_TAXII_ACCEPT
X-TAXII-Accept header name
|
static java.lang.String |
HEADER_X_TAXII_CONTENT_TYPE
X-TAXII-Content-Type header name
|
static java.lang.String |
HEADER_X_TAXII_PROTOCOL
The X-TAXII-Protocol header name
|
static java.lang.String |
HEADER_X_TAXII_SERVICES
The X-TAXII-Services header name
|
static java.lang.String |
SCHEME_HTTP |
static java.lang.String |
SCHEME_HTTPS |
Constructor and Description |
---|
HttpClient()
Default constructor.
|
HttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
Create a client with a pre-configured Apache HttpClient.
|
HttpClient(TaxiiXml taxiiXml,
org.apache.http.impl.client.CloseableHttpClient httpClient)
Create a client that uses a specific TaxiiXml object and a pre-configured
Apache HttpClient.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
callTaxiiService(java.net.URI uri,
java.lang.Object message)
Send a TAXII message to an endpoint.
|
org.apache.http.impl.client.CloseableHttpClient |
getHttpclient()
Get the Apache Components HTTP Client in use by this object.
|
TaxiiXml |
getVersionHandler(java.lang.String key) |
void |
setHttpclient(org.apache.http.impl.client.CloseableHttpClient httpclient)
Set the Apache Components HTTP Client.
|
void |
setVersionHandler(TaxiiXml taxiiXml)
Assign a TAXII message handler.
|
public static final java.lang.String SCHEME_HTTP
public static final java.lang.String SCHEME_HTTPS
public static final java.lang.String HEADER_ACCEPT
public static final java.lang.String HEADER_CONTENT_TYPE
public static final java.lang.String HEADER_X_TAXII_ACCEPT
public static final java.lang.String HEADER_X_TAXII_CONTENT_TYPE
public static final java.lang.String HEADER_X_TAXII_PROTOCOL
public static final java.lang.String HEADER_X_TAXII_SERVICES
public HttpClient(TaxiiXml taxiiXml, org.apache.http.impl.client.CloseableHttpClient httpClient)
taxiiXml
- httpClient
- public HttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
httpClient
- public HttpClient()
public java.lang.Object callTaxiiService(java.net.URI uri, java.lang.Object message) throws javax.xml.bind.JAXBException, java.io.UnsupportedEncodingException, java.io.IOException
TaxiiXml
object in the taxiiXmlMap. If an appropriate message handler cannot be found,
an exception is thrown.
NOTE: It is expected that the response received will match the version of
the message sent. The TAXII specification allows setting multiple values
in the "x-taxii-accept" header. This library only sets and sends the
version of the message being sent.uri
- The address of the endpoint to send the message tomessage
- The message to send.javax.xml.bind.JAXBException
java.io.UnsupportedEncodingException
java.io.IOException
public org.apache.http.impl.client.CloseableHttpClient getHttpclient()
public void setHttpclient(org.apache.http.impl.client.CloseableHttpClient httpclient)
httpclient
- public void setVersionHandler(TaxiiXml taxiiXml)
taxiiXml
- public TaxiiXml getVersionHandler(java.lang.String key)