001package com.esri.arcgis.enterprise.interceptor.server;
002
003import com.esri.arcgis.enterprise.interceptor.IInterceptorRequest;
004import com.esri.arcgis.enterprise.interceptor.IInterceptorResponse;
005
006import java.io.IOException;
007import java.util.List;
008
009public interface IServerServicesInterceptorHelper {
010
011    /**
012     * Get username from the request
013     *
014     * @param request  the request to pass along the chain.
015     * @param response the response to pass along the chain.
016     * @return Username if available
017     */
018    String getUsername(IInterceptorRequest request, IInterceptorResponse response);
019
020    /**
021     * Get list of roles of the current user from the request
022     *
023     * @param request  the request to pass along the chain.
024     * @param response the response to pass along the chain.
025     * @return User role if available
026     */
027    List<String> getUserRole(IInterceptorRequest request, IInterceptorResponse response);
028
029    /**
030     * Get service type from the request
031     *
032     * @param request  the request to pass along the chain.
033     * @param response the response to pass along the chain.
034     * @return Service type if available
035     */
036    String getServiceType(IInterceptorRequest request, IInterceptorResponse response);
037
038    /**
039     * Get service name from the request
040     *
041     * @param request  the request to pass along the chain.
042     * @param response the response to pass along the chain.
043     * @return Service name
044     */
045    String getServiceName(IInterceptorRequest request, IInterceptorResponse response);
046
047    /**
048     * Get service operation from the request
049     *
050     * @param request  the request to pass along the chain.
051     * @param response the response to pass along the chain.
052     * @return Operation name if available
053     */
054    String getOperationName(IInterceptorRequest request, IInterceptorResponse response);
055
056    /**
057     * Check if the request is a REST request or not
058     *
059     * @param request          the request to pass along the chain.
060     * @param interceptorChain the chain object to pass the request along the chain.
061     * @return Flag indicating if REST request or not
062     */
063    boolean isRestRequest(IInterceptorRequest request, IServerServicesInterceptorChain interceptorChain);
064
065
066    /**
067     * Decompresses the response data which is in the GZIP file format and
068     * returns the uncompressed response body in String format
069     *
070     * @param compressedResponse compressed byte array representing the response data
071     * @return Return the decompressed response string
072     */
073    String getDecompressedResponseData(byte[] compressedResponse) throws IOException;
074
075    /**
076     * Compresses the String response body and returns a byte array compressed in the GZIP file format
077     *
078     * @param uncompressedData uncompressed response string
079     * @return Return the compressed response byte array
080     */
081    byte[] getCompressedResponseData(String uncompressedData) throws IOException;
082
083    /**
084     * Returns whether the response data is in compressed format or not
085     *
086     * @param request  the request to pass along the chain.
087     * @param response the response to pass along the chain.
088     * @return Boolean indicating whether response is compressed or not
089     */
090    boolean isOutputStreamCompressed(IInterceptorRequest request, IInterceptorResponse response);
091
092}