Class BaseHTTPSender
- java.lang.Object
-
- org.certificateservices.messages.utils.BaseHTTPSender
-
- Direct Known Subclasses:
DefaultHTTPMsgSender
public abstract class BaseHTTPSender extends java.lang.ObjectAbstract Base implementation of a MsgSender using HTTP. Created by Philip Vendil on 23/06/16.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBaseHTTPSender.SendMsgRunnableRunnable that sends a HTTP call and wait for the response.protected classBaseHTTPSender.SynchronousCallbackSpecial case callback used for syncronious request calls.
-
Field Summary
Fields Modifier and Type Field Description protected java.net.URLbaseURLprotected java.lang.StringoutputContentTypeprotected java.lang.StringrequestType
-
Constructor Summary
Constructors Constructor Description BaseHTTPSender(java.lang.String url, java.lang.String requestType, java.lang.String outputContentType)Main constructor where it is possible to specify request type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]sendMsg(byte[] request)Synchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)protected voidsendMsg(byte[] request, MsgSender.MsgCallback callback)Asynchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)protected byte[]sendMsg(java.lang.String parameters)Synchronous call for sending HTTP request with parameters in URL string (usually using GET)protected voidsendMsg(java.lang.String parameters, MsgSender.MsgCallback callback)Asynchronous call for sending HTTP request with parameters in URL string (usually using GET)booleantestConnection()Synchronous call to test connection to the given url.
-
-
-
Constructor Detail
-
BaseHTTPSender
public BaseHTTPSender(java.lang.String url, java.lang.String requestType, java.lang.String outputContentType) throws java.net.MalformedURLExceptionMain constructor where it is possible to specify request type.- Parameters:
url- the URL to connect to.requestType- the HTTP request type in upper case (For example POST, GET)outputContentType- the content type on the output data.- Throws:
java.net.MalformedURLException- if URL was malformed.
-
-
Method Detail
-
testConnection
public boolean testConnection()
Synchronous call to test connection to the given url.- Returns:
- true if connection is working, otherwise false.
-
sendMsg
protected byte[] sendMsg(byte[] request) throws MessageContentException, MessageProcessingException, java.io.IOException, SpamProtectionException, TimeoutExceptionSynchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)- Parameters:
request- the data to send.- Returns:
- the response data.
- Throws:
MessageContentException- if request contained illegal content.MessageProcessingException- if internal problems occurred processing the request at the server.java.io.IOException- if communication problems occurred.SpamProtectionException- if server side regarded call as a SPAM request and denied it.TimeoutException- if timeout was detected when calling service.
-
sendMsg
protected void sendMsg(byte[] request, MsgSender.MsgCallback callback)Asynchronous call for sending HTTP request sending data in the HTTP request body (usually using POST)- Parameters:
request- the data to send.callback- the callback to signal the result to.
-
sendMsg
protected void sendMsg(java.lang.String parameters, MsgSender.MsgCallback callback) throws MessageContentExceptionAsynchronous call for sending HTTP request with parameters in URL string (usually using GET)- Parameters:
parameters- the parameter string to send (without ?)callback- the callback to signal the result to.- Throws:
MessageContentException
-
sendMsg
protected byte[] sendMsg(java.lang.String parameters) throws MessageContentException, MessageProcessingException, java.io.IOException, SpamProtectionExceptionSynchronous call for sending HTTP request with parameters in URL string (usually using GET)- Parameters:
parameters- the parameter string to send (without ?)- Returns:
- the response data.
- Throws:
MessageContentException- if request contained illegal content.MessageProcessingException- if internal problems occurred processing the request at the server.java.io.IOException- if communication problems occurred.SpamProtectionException- if server side regarded call as a SPAM request and denied it.
-
-