Class AbstractWebProvider

  • Direct Known Subclasses:
    PluginWebProvider

    public abstract class AbstractWebProvider
    extends Object
    The Class provides necessary methods to handle a Web-Communication.
    It can handle for example OAuth2-communication WebDetails.
    • Constructor Detail

      • AbstractWebProvider

        public AbstractWebProvider()
    • Method Detail

      • createWebDetails

        public WebDetails createWebDetails​(Properties config)
        Reads the given properties and creates a webDetails object from it.
        The following information will be read:
        • ACCESS_TOKEN
        • REFRESH_TOKEN
        • GRANT_TYPE
        • CLIENT_ID
        • CLIENT_SECRET
        • SCOPE
        • AUTHENTICATION_SERVER_URI
        • ACCESS_TOKEN_URI
        • USERNAME
        • PASSWORD
        • RESOURCE_SERVER_URL

        The value for accessTokenRequest will be set to true if the properties does
        Parameters:
        config -
        Returns:
      • getClientConfigProps

        public Properties getClientConfigProps​(String path)
        Load the given Properties from the path.
        Parameters:
        path -
        Returns:
      • executeProtectedMethod

        public <E> E executeProtectedMethod​(WebDetails webDetails,
                                            AbstractWebProvider.MethodTypes methodType,
                                            Object data,
                                            org.apache.http.client.ResponseHandler<E> responseHandler)
                                     throws WebException
        Required fields in the webDetails are:
        WebDetails.getResourceServerUri()
        Parameters:
        webDetails - = holds the request/response informations (can not be null)
        methodType - = the kind of the method for a http-request (can not be null)
        responseHandler - = the handler will handle the response and returns the serialized object
        Throws:
        WebException
      • getProtectedResource

        public Map<String,​String> getProtectedResource​(WebDetails webDetails,
                                                             AbstractWebProvider.MethodTypes methodType,
                                                             Object data)
                                                      throws WebException
        Autorize to the given endpoint with the accessToken in the details and executes the method from the endpoint
        and add the given data as json in the request.
        Required fields in the webDetails are:
        WebDetails.getResourceServerUri() WebDetails.getAccessToken()
        Parameters:
        webDetails - = holds the request/response informations (can not be null)
        methodType - = the kind of the method for a http-request (can not be null)
        data - = json data (only needed if the methodType value is an instanceof HttpEntityEnclosingRequestBase, which can contain StringEntity)
        this value can be null. (can be null)
        Returns:
        Throws:
        WebException
      • getAccessToken

        public String getAccessToken​(String authServerUri,
                                     Map<String,​String> mapOfBodyPart,
                                     Map<String,​String> mapOfHeaderPart)
                              throws WebException
        Ask the endpoint in the details for an accessToken and send it back.
        The bodyPart-Entity is by default "UrlEncodedFormEntity".
        if you want to use another Entity-form then you have to use getAccessToken(String, WebConstants.ENTITY_TYPES, Map, Map)
        Parameters:
        authServerUri - = the authorization URI of the server we want to request for the access-token (can not be null)
        mapOfBodyPart - = a map which contains the input for the http-body-part (can not be null)
        mapOfHeaderPart - = a map which contains the input for the http-header (can be null)
        Returns:
        Throws:
        WebException
      • getAccessToken

        public String getAccessToken​(String authServerUri,
                                     WebConstants.ENTITY_TYPES entityType,
                                     Map<String,​String> mapOfBodyPart,
                                     Map<String,​String> mapOfHeaderPart)
                              throws WebException
        Ask the endpoint in the details for an accessToken and send it back.
        Parameters:
        authServerUri - = the authorization URI of the server we want to request for the access-token (can not be null)
        entityType - = the entity-type can be JSON or URL_ENCODED (default) andy specifies the kind of how the body-part is inserted in the request
        mapOfBodyPart - = a map which contains the input for the http-body-part (can not be null)
        mapOfHeaderPart - = a map which contains the input for the http-header (can be null)
        Returns:
        Throws:
        WebException
      • handleResponse

        protected Map<String,​String> handleResponse​(org.apache.http.HttpResponse response)
                                                   throws WebException
        Handles the given response depends on the content-type.
        supported types are:
        • JSON
        • URL_Encoded
        • XML

        Otherwise there will throw an exception!
        Parameters:
        response -
        Returns:
        Throws:
        WebException
      • handleJsonResponse

        protected Map<String,​String> handleJsonResponse​(org.apache.http.HttpResponse response)
                                                       throws WebException
        Handles the content of the response as JSON and return a parsed Map.
        Parameters:
        response -
        Returns:
        Throws:
        WebException
      • handleURLEncodedResponse

        protected Map<String,​String> handleURLEncodedResponse​(org.apache.http.HttpResponse response)
                                                             throws WebException
        Handles the content of the response as URL_Encoded and return a parsed Map.
        Parameters:
        response -
        Returns:
        Throws:
        WebException
      • handleXMLResponse

        protected Map<String,​String> handleXMLResponse​(org.apache.http.HttpResponse response)
                                                      throws WebException
        Handles the content of the response as XML and return a parsed Map.
        Parameters:
        response -
        Returns:
        Throws:
        WebException
      • parseXMLDoc

        protected void parseXMLDoc​(Element element,
                                   Document doc,
                                   Map<String,​String> oauthResponse)
        Parse the doc and fills the oauthResponse (key=tagname, value=content).
        Parameters:
        element -
        doc -
        oauthResponse -
      • getAuthorizationHeaderForAccessToken

        protected String getAuthorizationHeaderForAccessToken​(String accessToken)
        Returns the http-header for the given accesstoken value.
        Parameters:
        accessToken -
        Returns:
      • getBasicAuthorizationHeader

        protected String getBasicAuthorizationHeader​(String username,
                                                     String password)
        Return the http-header for the given username and password.
        Parameters:
        username -
        password -
        Returns: