001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk.http; 019 020 021import net.jcip.annotations.ThreadSafe; 022 023 024/** 025 * Abstract retrieved of resources by URL with HTTP timeout and entity size 026 * restrictions. 027 */ 028@ThreadSafe 029@Deprecated 030public abstract class AbstractRestrictedResourceRetriever implements RestrictedResourceRetriever { 031 032 033 /** 034 * The HTTP connect timeout, in milliseconds. 035 */ 036 private int connectTimeout; 037 038 039 /** 040 * The HTTP read timeout, in milliseconds. 041 */ 042 private int readTimeout; 043 044 045 /** 046 * The HTTP entity size limit, in bytes. 047 */ 048 private int sizeLimit; 049 050 051 /** 052 * Creates a new abstract restricted resource retriever. 053 * 054 * @param connectTimeout The HTTP connects timeout, in milliseconds, 055 * zero for infinite. Must not be negative. 056 * @param readTimeout The HTTP read timeout, in milliseconds, zero 057 * for infinite. Must not be negative. 058 * @param sizeLimit The HTTP entity size limit, in bytes, zero for 059 * infinite. Must not be negative. 060 */ 061 public AbstractRestrictedResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit) { 062 setConnectTimeout(connectTimeout); 063 setReadTimeout(readTimeout); 064 setSizeLimit(sizeLimit); 065 } 066 067 068 @Override 069 public int getConnectTimeout() { 070 071 return connectTimeout; 072 } 073 074 075 @Override 076 public void setConnectTimeout(final int connectTimeoutMs) { 077 078 if (connectTimeoutMs < 0) { 079 throw new IllegalArgumentException("The connect timeout must not be negative"); 080 } 081 082 this.connectTimeout = connectTimeoutMs; 083 } 084 085 086 @Override 087 public int getReadTimeout() { 088 089 return readTimeout; 090 } 091 092 093 @Override 094 public void setReadTimeout(final int readTimeoutMs) { 095 096 if (readTimeoutMs < 0) { 097 throw new IllegalArgumentException("The read timeout must not be negative"); 098 } 099 100 this.readTimeout = readTimeoutMs; 101 } 102 103 104 @Override 105 public int getSizeLimit() { 106 107 return sizeLimit; 108 } 109 110 111 @Override 112 public void setSizeLimit(int sizeLimitBytes) { 113 114 if (sizeLimitBytes < 0) { 115 throw new IllegalArgumentException("The size limit must not be negative"); 116 } 117 118 this.sizeLimit = sizeLimitBytes; 119 } 120}