Class HttpService

  • All Implemented Interfaces:
    java.io.Serializable

    @ApplicationScoped
    @Named
    public class HttpService
    extends java.lang.Object
    implements java.io.Serializable
    Provides operations with http requests
    Author:
    Yuriy Movchan Date: 02/05/2013
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String constructServerUrl​(javax.servlet.http.HttpServletRequest request)  
      void consume​(org.apache.http.HttpResponse httpResponse)  
      java.lang.String convertEntityToString​(byte[] responseBytes)  
      java.lang.String convertEntityToString​(byte[] responseBytes, java.lang.String charsetName)  
      java.lang.String convertEntityToString​(byte[] responseBytes, java.nio.charset.Charset charset)  
      java.lang.String encodeBase64​(java.lang.String value)  
      java.lang.String encodeUrl​(java.lang.String value)  
      HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient, java.lang.String requestUri)  
      HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient, java.lang.String requestUri, java.util.Map<java.lang.String,​java.lang.String> headers)  
      HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient, java.lang.String uri, java.lang.String authData, java.lang.String postData, org.apache.http.entity.ContentType contentType)  
      HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient, java.lang.String uri, java.lang.String authData, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String postData)  
      HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient, java.lang.String uri, java.lang.String authData, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String postData, org.apache.http.entity.ContentType contentType)  
      org.apache.http.client.HttpClient getHttpsClient()  
      org.apache.http.client.HttpClient getHttpsClient​(java.lang.String trustStoreType, java.lang.String trustStorePath, java.lang.String trustStorePassword)  
      org.apache.http.client.HttpClient getHttpsClient​(java.lang.String trustStoreType, java.lang.String trustStorePath, java.lang.String trustStorePassword, java.lang.String keyStoreType, java.lang.String keyStorePath, java.lang.String keyStorePassword)  
      org.apache.http.client.HttpClient getHttpsClientTrustAll()  
      byte[] getResponseContent​(org.apache.http.HttpResponse httpResponse)  
      void init()  
      boolean isContentTypeXml​(org.apache.http.HttpResponse httpResponse)  
      boolean isResponseStastusCodeOk​(org.apache.http.HttpResponse httpResponse)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpService

        public HttpService()
    • Method Detail

      • init

        @PostConstruct
        public void init()
      • getHttpsClientTrustAll

        public org.apache.http.client.HttpClient getHttpsClientTrustAll()
      • getHttpsClient

        public org.apache.http.client.HttpClient getHttpsClient()
      • getHttpsClient

        public org.apache.http.client.HttpClient getHttpsClient​(java.lang.String trustStoreType,
                                                                java.lang.String trustStorePath,
                                                                java.lang.String trustStorePassword)
      • getHttpsClient

        public org.apache.http.client.HttpClient getHttpsClient​(java.lang.String trustStoreType,
                                                                java.lang.String trustStorePath,
                                                                java.lang.String trustStorePassword,
                                                                java.lang.String keyStoreType,
                                                                java.lang.String keyStorePath,
                                                                java.lang.String keyStorePassword)
      • executePost

        public HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                               java.lang.String uri,
                                               java.lang.String authData,
                                               java.util.Map<java.lang.String,​java.lang.String> headers,
                                               java.lang.String postData,
                                               org.apache.http.entity.ContentType contentType)
      • executePost

        public HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                               java.lang.String uri,
                                               java.lang.String authData,
                                               java.util.Map<java.lang.String,​java.lang.String> headers,
                                               java.lang.String postData)
      • executePost

        public HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                               java.lang.String uri,
                                               java.lang.String authData,
                                               java.lang.String postData,
                                               org.apache.http.entity.ContentType contentType)
      • encodeBase64

        public java.lang.String encodeBase64​(java.lang.String value)
      • encodeUrl

        public java.lang.String encodeUrl​(java.lang.String value)
      • executeGet

        public HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient,
                                              java.lang.String requestUri,
                                              java.util.Map<java.lang.String,​java.lang.String> headers)
      • executeGet

        public HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient,
                                              java.lang.String requestUri)
                                       throws org.apache.http.client.ClientProtocolException,
                                              java.io.IOException
        Throws:
        org.apache.http.client.ClientProtocolException
        java.io.IOException
      • getResponseContent

        public byte[] getResponseContent​(org.apache.http.HttpResponse httpResponse)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • consume

        public void consume​(org.apache.http.HttpResponse httpResponse)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • convertEntityToString

        public java.lang.String convertEntityToString​(byte[] responseBytes)
      • convertEntityToString

        public java.lang.String convertEntityToString​(byte[] responseBytes,
                                                      java.nio.charset.Charset charset)
      • convertEntityToString

        public java.lang.String convertEntityToString​(byte[] responseBytes,
                                                      java.lang.String charsetName)
                                               throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • isResponseStastusCodeOk

        public boolean isResponseStastusCodeOk​(org.apache.http.HttpResponse httpResponse)
      • isContentTypeXml

        public boolean isContentTypeXml​(org.apache.http.HttpResponse httpResponse)
      • constructServerUrl

        public java.lang.String constructServerUrl​(javax.servlet.http.HttpServletRequest request)