コード例 #1
0
ファイル: RestClient.java プロジェクト: saeta/rest.li
 /**
  * @param baselineProtocolVersion baseline version on the client
  * @param latestVersion latest version on the client
  * @param nextVersion the next version on the client
  * @param announcedVersion version announced by the service
  * @param versionOption options present on the request
  * @param forceUseNextVersionOverride if we always want to use {@link
  *     com.linkedin.restli.client.ProtocolVersionOption#FORCE_USE_NEXT}
  * @return the {@link ProtocolVersion} that should be used to build the request
  */
 /*package private*/ static ProtocolVersion getProtocolVersion(
     ProtocolVersion baselineProtocolVersion,
     ProtocolVersion latestVersion,
     ProtocolVersion nextVersion,
     ProtocolVersion announcedVersion,
     ProtocolVersionOption versionOption,
     boolean forceUseNextVersionOverride) {
   if (versionOption == null) {
     throw new IllegalArgumentException("versionOptions cannot be null!");
   }
   if (forceUseNextVersionOverride) {
     return nextVersion;
   }
   switch (versionOption) {
     case FORCE_USE_NEXT:
       return nextVersion;
     case FORCE_USE_LATEST:
       return latestVersion;
     case USE_LATEST_IF_AVAILABLE:
       if (announcedVersion.compareTo(baselineProtocolVersion) == -1) {
         // throw an exception as the announced version is less than the default version
         throw new RuntimeException(
             "Announced version is less than the default version!"
                 + "Announced version: "
                 + announcedVersion
                 + ", default version: "
                 + baselineProtocolVersion);
       } else if (announcedVersion.compareTo(baselineProtocolVersion) == 0) {
         // server is running the default version
         return baselineProtocolVersion;
       } else if (announcedVersion.compareTo(latestVersion) == -1) {
         // use the server announced version if it is less than the latest version
         return announcedVersion;
       }
       // server is either running the latest version or something newer. Use the latest version in
       // this case.
       return latestVersion;
     default:
       return baselineProtocolVersion;
   }
 }
コード例 #2
0
ファイル: QueryParamsUtil.java プロジェクト: saeta/rest.li
 private static Object paramToDataObject(
     Object param, Class<?> paramClass, ProtocolVersion version) {
   if (param == null) {
     return null;
   } else if (param instanceof ComplexResourceKey) {
     return ((ComplexResourceKey) param).toDataMap();
   } else if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion())
           >= 0
       && param instanceof CompoundKey) {
     return URIParamUtils.compoundKeyToDataMap((CompoundKey) param);
   } else if (param instanceof DataTemplate) {
     @SuppressWarnings("rawtypes")
     final DataTemplate dataTemplate = (DataTemplate) param;
     return dataTemplate.data();
   } else if (param instanceof DataComplex) {
     return param;
   } else if (param instanceof List) {
     return coerceList((List) param, paramClass, version);
   } else {
     return DataTemplateUtil.stringify(param, paramClass);
   }
 }
コード例 #3
0
ファイル: RestClient.java プロジェクト: saeta/rest.li
 /**
  * Adds the protocol version of Rest.li used to build the request to the headers for this request
  *
  * @param builder
  * @param protocolVersion
  */
 private void addProtocolVersionHeader(
     RestRequestBuilder builder, ProtocolVersion protocolVersion) {
   builder.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
 }