@Override
public HTTPRequest toHTTPRequest()
throws SerializeException {
if (getEndpointURI() == null)
throw new SerializeException("The endpoint URI is not specified");
URL endpointURL;
try {
endpointURL = getEndpointURI().toURL();
} catch (MalformedURLException e) {
throw new SerializeException(e.getMessage(), e);
}
HTTPRequest httpRequest = new HTTPRequest(httpMethod, endpointURL);
switch (httpMethod) {
case GET:
httpRequest.setAuthorization(getAccessToken().toAuthorizationHeader());
break;
case POST:
httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);
httpRequest.setQuery("access_token=" + getAccessToken().getValue());
break;
default:
throw new SerializeException("Unexpected HTTP method: " + httpMethod);
}
return httpRequest;
}