Class UserAgentUtil


  • public class UserAgentUtil
    extends java.lang.Object
    Utilities for manipulating the HTTP User-Agent header from the JVM, following IVOA usage conventions. These conventions are codified in the SoftID IVOA Note.

    Typical usage for a validator client would be:

       String uaComment = UserAgentUtil.COMMENT_TEST;   // "(IVOA-test)"
       UserAgentUtil.pushUserAgentToken( uaComment );
       ... do validation ...
       UserAgentUtil.popUserAgentToken( uaComment );
     
    Since:
    12 Apr 2019
    Author:
    Mark Taylor
    See Also:
    RFC 7231 sec 5.5.3, NOTE-softid-1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AGENT_PROPNAME
      System property that can be used to manipulate the UserAgent header.
      static java.lang.String COMMENT_COPY
      Comment token indicating client performs VO copy/mirror/harvest.
      static java.lang.String COMMENT_TEST
      Comment token indicating client performs VO test/monitor/validate.
      static java.lang.String IVOA_PREFIX
      String prefixed to purpose verb to introduce IVOA operation comment.
      static java.lang.String PURPOSE_COPY
      Purpose verb indicating copying/mirroring/harvesting: "copy".
      static java.lang.String PURPOSE_TEST
      Purpose verb indicating testing/monitoring/validation: "test".
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String createOpPurposeComment​(java.lang.String purpose, java.lang.String extra)
      Assembles a string of the form (IVOA-<purpose> <extra>).
      static java.lang.String[] parseProducts​(java.lang.String productsTxt)
      Parses a products string as found in the HTTP User-Agent or Server header.
      static void popUserAgentToken​(java.lang.String token)
      Removes a token/comment from the currently-used User-Agent string.
      static void pushUserAgentToken​(java.lang.String token)
      Appends a token/comment to the currently used User-Agent string.
      • Methods inherited from class java.lang.Object

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

      • PURPOSE_TEST

        public static final java.lang.String PURPOSE_TEST
        Purpose verb indicating testing/monitoring/validation: "test".
        See Also:
        Constant Field Values
      • PURPOSE_COPY

        public static final java.lang.String PURPOSE_COPY
        Purpose verb indicating copying/mirroring/harvesting: "copy".
        See Also:
        Constant Field Values
      • IVOA_PREFIX

        public static final java.lang.String IVOA_PREFIX
        String prefixed to purpose verb to introduce IVOA operation comment.
        See Also:
        Constant Field Values
      • COMMENT_TEST

        public static final java.lang.String COMMENT_TEST
        Comment token indicating client performs VO test/monitor/validate.
      • COMMENT_COPY

        public static final java.lang.String COMMENT_COPY
        Comment token indicating client performs VO copy/mirror/harvest.
      • AGENT_PROPNAME

        public static final java.lang.String AGENT_PROPNAME
        System property that can be used to manipulate the UserAgent header.
        See Also:
        Constant Field Values
    • Method Detail

      • pushUserAgentToken

        public static void pushUserAgentToken​(java.lang.String token)
        Appends a token/comment to the currently used User-Agent string. This does not overwrite existing text, which is in general useful.
        Parameters:
        token - string to add
      • popUserAgentToken

        public static void popUserAgentToken​(java.lang.String token)
        Removes a token/comment from the currently-used User-Agent string. This only has effect if the given token is at the end of the current list, that is if it has just been added. If it's not present or not at the end, a warning is logged and there is no other effect.
        Parameters:
        token - previously added string to remove
      • createOpPurposeComment

        public static java.lang.String createOpPurposeComment​(java.lang.String purpose,
                                                              java.lang.String extra)
        Assembles a string of the form (IVOA-<purpose> <extra>).
        Parameters:
        purpose - operational purpose string; recommended values are PURPOSE_* static members of this class
        extra - free form additional text excluding "(" or ")"; may be null
        Returns:
        string suitable for User-Agent header comment
        Throws:
        java.lang.IllegalArgumentException - if rudimentary syntax checking detects errors
      • parseProducts

        public static java.lang.String[] parseProducts​(java.lang.String productsTxt)
        Parses a products string as found in the HTTP User-Agent or Server header. See RFC 7231 sec 5.5.3 and RFC 7230 sec 3.2.6 for the relevant syntax productions.
        Parameters:
        productsTxt - string giving product and comment tokens as found in User-Agent or Server header
        Returns:
        array of tokens; each may be either a product or a comment; comments start with a "("
        Throws:
        java.lang.IllegalArgumentException - if the syntax is not as required