Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
ef71254e
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef71254e
编写于
5月 12, 2013
作者:
J
Jake Wharton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Re-arrange package structure.
上级
4f3798e6
变更
51
隐藏空白更改
内联
并排
Showing
51 changed file
with
284 addition
and
280 deletion
+284
-280
retrofit/src/main/java/retrofit/Callback.java
retrofit/src/main/java/retrofit/Callback.java
+2
-2
retrofit/src/main/java/retrofit/CallbackRunnable.java
retrofit/src/main/java/retrofit/CallbackRunnable.java
+1
-1
retrofit/src/main/java/retrofit/ChangeableServer.java
retrofit/src/main/java/retrofit/ChangeableServer.java
+2
-2
retrofit/src/main/java/retrofit/Platform.java
retrofit/src/main/java/retrofit/Platform.java
+21
-16
retrofit/src/main/java/retrofit/Profiler.java
retrofit/src/main/java/retrofit/Profiler.java
+2
-2
retrofit/src/main/java/retrofit/RequestBuilder.java
retrofit/src/main/java/retrofit/RequestBuilder.java
+12
-13
retrofit/src/main/java/retrofit/RequestHeaders.java
retrofit/src/main/java/retrofit/RequestHeaders.java
+3
-3
retrofit/src/main/java/retrofit/ResponseWrapper.java
retrofit/src/main/java/retrofit/ResponseWrapper.java
+5
-6
retrofit/src/main/java/retrofit/RestAdapter.java
retrofit/src/main/java/retrofit/RestAdapter.java
+53
-36
retrofit/src/main/java/retrofit/RestMethodInfo.java
retrofit/src/main/java/retrofit/RestMethodInfo.java
+15
-5
retrofit/src/main/java/retrofit/RetrofitError.java
retrofit/src/main/java/retrofit/RetrofitError.java
+5
-3
retrofit/src/main/java/retrofit/Server.java
retrofit/src/main/java/retrofit/Server.java
+1
-1
retrofit/src/main/java/retrofit/Types.java
retrofit/src/main/java/retrofit/Types.java
+1
-1
retrofit/src/main/java/retrofit/Utils.java
retrofit/src/main/java/retrofit/Utils.java
+5
-18
retrofit/src/main/java/retrofit/android/AndroidApacheClient.java
...t/src/main/java/retrofit/android/AndroidApacheClient.java
+3
-3
retrofit/src/main/java/retrofit/android/MainThreadExecutor.java
...it/src/main/java/retrofit/android/MainThreadExecutor.java
+1
-1
retrofit/src/main/java/retrofit/client/ApacheClient.java
retrofit/src/main/java/retrofit/client/ApacheClient.java
+3
-3
retrofit/src/main/java/retrofit/client/Client.java
retrofit/src/main/java/retrofit/client/Client.java
+1
-1
retrofit/src/main/java/retrofit/client/Header.java
retrofit/src/main/java/retrofit/client/Header.java
+1
-1
retrofit/src/main/java/retrofit/client/OkClient.java
retrofit/src/main/java/retrofit/client/OkClient.java
+1
-1
retrofit/src/main/java/retrofit/client/Request.java
retrofit/src/main/java/retrofit/client/Request.java
+2
-2
retrofit/src/main/java/retrofit/client/Response.java
retrofit/src/main/java/retrofit/client/Response.java
+2
-2
retrofit/src/main/java/retrofit/client/UrlConnectionClient.java
...it/src/main/java/retrofit/client/UrlConnectionClient.java
+3
-3
retrofit/src/main/java/retrofit/converter/ConversionException.java
...src/main/java/retrofit/converter/ConversionException.java
+1
-1
retrofit/src/main/java/retrofit/converter/Converter.java
retrofit/src/main/java/retrofit/converter/Converter.java
+6
-6
retrofit/src/main/java/retrofit/converter/GsonConverter.java
retrofit/src/main/java/retrofit/converter/GsonConverter.java
+6
-5
retrofit/src/main/java/retrofit/http/Parameter.java
retrofit/src/main/java/retrofit/http/Parameter.java
+0
-79
retrofit/src/main/java/retrofit/http/Part.java
retrofit/src/main/java/retrofit/http/Part.java
+2
-2
retrofit/src/main/java/retrofit/mime/FormUrlEncodedTypedOutput.java
...rc/main/java/retrofit/mime/FormUrlEncodedTypedOutput.java
+1
-1
retrofit/src/main/java/retrofit/mime/MimeUtil.java
retrofit/src/main/java/retrofit/mime/MimeUtil.java
+38
-0
retrofit/src/main/java/retrofit/mime/MultipartTypedOutput.java
...fit/src/main/java/retrofit/mime/MultipartTypedOutput.java
+1
-1
retrofit/src/main/java/retrofit/mime/TypedByteArray.java
retrofit/src/main/java/retrofit/mime/TypedByteArray.java
+1
-1
retrofit/src/main/java/retrofit/mime/TypedFile.java
retrofit/src/main/java/retrofit/mime/TypedFile.java
+1
-1
retrofit/src/main/java/retrofit/mime/TypedInput.java
retrofit/src/main/java/retrofit/mime/TypedInput.java
+1
-1
retrofit/src/main/java/retrofit/mime/TypedOutput.java
retrofit/src/main/java/retrofit/mime/TypedOutput.java
+1
-1
retrofit/src/main/java/retrofit/mime/TypedString.java
retrofit/src/main/java/retrofit/mime/TypedString.java
+1
-1
retrofit/src/test/java/retrofit/CallbackRunnableTest.java
retrofit/src/test/java/retrofit/CallbackRunnableTest.java
+6
-2
retrofit/src/test/java/retrofit/RequestBuilderTest.java
retrofit/src/test/java/retrofit/RequestBuilderTest.java
+13
-9
retrofit/src/test/java/retrofit/RestAdapterTest.java
retrofit/src/test/java/retrofit/RestAdapterTest.java
+10
-8
retrofit/src/test/java/retrofit/RestMethodInfoTest.java
retrofit/src/test/java/retrofit/RestMethodInfoTest.java
+22
-7
retrofit/src/test/java/retrofit/TestingUtils.java
retrofit/src/test/java/retrofit/TestingUtils.java
+3
-3
retrofit/src/test/java/retrofit/client/ApacheClientTest.java
retrofit/src/test/java/retrofit/client/ApacheClientTest.java
+7
-7
retrofit/src/test/java/retrofit/client/DummyHttpUrlConnection.java
...src/test/java/retrofit/client/DummyHttpUrlConnection.java
+2
-2
retrofit/src/test/java/retrofit/client/UrlConnectionClientTest.java
...rc/test/java/retrofit/client/UrlConnectionClientTest.java
+5
-5
retrofit/src/test/java/retrofit/mime/FormUrlEncodingTypedOutputTest.java
...st/java/retrofit/mime/FormUrlEncodingTypedOutputTest.java
+1
-1
retrofit/src/test/java/retrofit/mime/MimeHelper.java
retrofit/src/test/java/retrofit/mime/MimeHelper.java
+1
-1
retrofit/src/test/java/retrofit/mime/MimeUtilTest.java
retrofit/src/test/java/retrofit/mime/MimeUtilTest.java
+3
-3
retrofit/src/test/java/retrofit/mime/MultipartTypedOutputTest.java
...src/test/java/retrofit/mime/MultipartTypedOutputTest.java
+1
-1
retrofit/src/test/java/retrofit/mime/TypedByteArrayTest.java
retrofit/src/test/java/retrofit/mime/TypedByteArrayTest.java
+1
-1
retrofit/src/test/java/retrofit/mime/TypedFileTest.java
retrofit/src/test/java/retrofit/mime/TypedFileTest.java
+1
-1
samples/github-client/src/main/java/com/example/retrofit/GitHubClient.java
...ient/src/main/java/com/example/retrofit/GitHubClient.java
+3
-3
未找到文件。
retrofit/src/main/java/retrofit/
http/
Callback.java
→
retrofit/src/main/java/retrofit/Callback.java
浏览文件 @
ef71254e
...
...
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
retrofit.
http.
client.Response
;
import
retrofit.client.Response
;
/**
* Communicates responses to server or offline requests. Contains a callback method for each
...
...
retrofit/src/main/java/retrofit/
http/
CallbackRunnable.java
→
retrofit/src/main/java/retrofit/CallbackRunnable.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.util.concurrent.Executor
;
...
...
retrofit/src/main/java/retrofit/
http/
ChangeableServer.java
→
retrofit/src/main/java/retrofit/ChangeableServer.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
/** A {@link Server} whose URL and name can be changed at runtime. */
public
class
ChangeableServer
extends
Server
{
...
...
@@ -39,7 +39,7 @@ public class ChangeableServer extends Server {
this
.
url
=
url
;
}
/** Update the URL and name returned by {@link #getUrl()} and {@link #getName()}, respetively. */
/** Update the URL and name returned by {@link #getUrl()} and {@link #getName()}, respe
c
tively. */
public
void
update
(
String
url
,
String
name
)
{
this
.
url
=
url
;
this
.
name
=
name
;
...
...
retrofit/src/main/java/retrofit/
http/
Platform.java
→
retrofit/src/main/java/retrofit/Platform.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
android.os.Build
;
import
android.os.Process
;
...
...
@@ -22,16 +22,16 @@ import com.google.gson.Gson;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ThreadFactory
;
import
retrofit.http.android.AndroidApacheClient
;
import
retrofit.http.android.MainThreadExecutor
;
import
retrofit.http.client.Client
;
import
retrofit.http.client.OkClient
;
import
retrofit.http.client.UrlConnectionClient
;
import
retrofit.android.AndroidApacheClient
;
import
retrofit.android.MainThreadExecutor
;
import
retrofit.client.Client
;
import
retrofit.client.OkClient
;
import
retrofit.client.UrlConnectionClient
;
import
retrofit.converter.Converter
;
import
retrofit.converter.GsonConverter
;
import
static
android
.
os
.
Process
.
THREAD_PRIORITY_BACKGROUND
;
import
static
java
.
lang
.
Thread
.
MIN_PRIORITY
;
import
static
retrofit
.
http
.
RestAdapter
.
IDLE_THREAD_NAME
;
import
static
retrofit
.
http
.
Utils
.
SynchronousExecutor
;
abstract
class
Platform
{
private
static
final
Platform
PLATFORM
=
findPlatform
();
...
...
@@ -49,10 +49,7 @@ abstract class Platform {
}
}
Converter
defaultConverter
()
{
return
new
GsonConverter
(
new
Gson
());
}
abstract
Converter
defaultConverter
();
abstract
Client
.
Provider
defaultClient
();
abstract
Executor
defaultHttpExecutor
();
abstract
Executor
defaultCallbackExecutor
();
...
...
@@ -60,6 +57,10 @@ abstract class Platform {
/** Provides sane defaults for operation on the JVM. */
private
static
class
Base
extends
Platform
{
@Override
Converter
defaultConverter
()
{
return
new
GsonConverter
(
new
Gson
());
}
@Override
Client
.
Provider
defaultClient
()
{
final
Client
client
;
if
(
hasOkHttpOnClasspath
())
{
...
...
@@ -82,13 +83,13 @@ abstract class Platform {
Thread
.
currentThread
().
setPriority
(
MIN_PRIORITY
);
r
.
run
();
}
},
IDLE_THREAD_NAME
);
},
RestAdapter
.
IDLE_THREAD_NAME
);
}
});
}
@Override
Executor
defaultCallbackExecutor
()
{
return
new
SynchronousExecutor
();
return
new
Utils
.
SynchronousExecutor
();
}
@Override
RestAdapter
.
Log
defaultLog
()
{
...
...
@@ -102,6 +103,10 @@ abstract class Platform {
/** Provides sane defaults for operation on Android. */
private
static
class
Android
extends
Platform
{
@Override
Converter
defaultConverter
()
{
return
new
GsonConverter
(
new
Gson
());
}
@Override
Client
.
Provider
defaultClient
()
{
final
Client
client
;
if
(
hasOkHttpOnClasspath
())
{
...
...
@@ -126,7 +131,7 @@ abstract class Platform {
Process
.
setThreadPriority
(
THREAD_PRIORITY_BACKGROUND
);
r
.
run
();
}
},
IDLE_THREAD_NAME
);
},
RestAdapter
.
IDLE_THREAD_NAME
);
}
});
}
...
...
@@ -156,7 +161,7 @@ abstract class Platform {
/**
* Indirection for OkHttp class to prevent VerifyErrors on Android 2.0 and earlier when the
* dependency is not present.
.
* dependency is not present.
*/
private
static
class
OkClientInstantiator
{
static
Client
instantiate
()
{
...
...
retrofit/src/main/java/retrofit/
http/
Profiler.java
→
retrofit/src/main/java/retrofit/Profiler.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
/**
* A hook allowing clients to log HTTP method times and response status codes.
...
...
@@ -26,7 +26,7 @@ public interface Profiler<T> {
* Invoked before an HTTP method call. The object returned by this method will be
* passed to {@link #afterCall} when the call returns.
* <p>
* This method gives implement
o
rs the opportunity to include information that may
* This method gives implement
e
rs the opportunity to include information that may
* change during the server call in {@code afterCall} logic.
*/
T
beforeCall
();
...
...
retrofit/src/main/java/retrofit/
http/
RequestBuilder.java
→
retrofit/src/main/java/retrofit/RequestBuilder.java
浏览文件 @
ef71254e
...
...
@@ -13,19 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.List
;
import
retrofit.http.client.Header
;
import
retrofit.http.client.Request
;
import
retrofit.http.mime.FormUrlEncodedTypedOutput
;
import
retrofit.http.mime.MultipartTypedOutput
;
import
retrofit.http.mime.TypedOutput
;
import
static
retrofit
.
http
.
RestMethodInfo
.
NO_BODY
;
import
retrofit.client.Header
;
import
retrofit.client.Request
;
import
retrofit.converter.Converter
;
import
retrofit.mime.FormUrlEncodedTypedOutput
;
import
retrofit.mime.MultipartTypedOutput
;
import
retrofit.mime.TypedOutput
;
/** Builds HTTP requests from Java method invocations. */
final
class
RequestBuilder
{
...
...
@@ -34,7 +33,7 @@ final class RequestBuilder {
private
RestMethodInfo
methodInfo
;
private
Object
[]
args
;
private
String
apiUrl
;
private
List
<
retrofit
.
http
.
client
.
Header
>
headers
;
private
List
<
retrofit
.
client
.
Header
>
headers
;
RequestBuilder
(
Converter
converter
)
{
this
.
converter
=
converter
;
...
...
@@ -59,7 +58,7 @@ final class RequestBuilder {
}
/** A list of custom headers. */
RequestBuilder
headers
(
List
<
retrofit
.
http
.
client
.
Header
>
headers
)
{
RequestBuilder
headers
(
List
<
retrofit
.
client
.
Header
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
...
...
@@ -100,7 +99,7 @@ final class RequestBuilder {
}
}
List
<
retrofit
.
http
.
client
.
Header
>
headers
=
new
ArrayList
<
retrofit
.
http
.
client
.
Header
>();
List
<
retrofit
.
client
.
Header
>
headers
=
new
ArrayList
<
retrofit
.
client
.
Header
>();
if
(
this
.
headers
!=
null
)
{
headers
.
addAll
(
this
.
headers
);
}
...
...
@@ -116,7 +115,7 @@ final class RequestBuilder {
if
(
name
==
null
)
continue
;
Object
arg
=
args
[
i
];
if
(
arg
!=
null
)
{
headers
.
add
(
new
retrofit
.
http
.
client
.
Header
(
name
,
String
.
valueOf
(
arg
)));
headers
.
add
(
new
retrofit
.
client
.
Header
(
name
,
String
.
valueOf
(
arg
)));
}
}
}
...
...
@@ -143,7 +142,7 @@ final class RequestBuilder {
switch
(
methodInfo
.
requestType
)
{
case
SIMPLE:
{
int
bodyIndex
=
methodInfo
.
bodyIndex
;
if
(
bodyIndex
==
NO_BODY
)
{
if
(
bodyIndex
==
RestMethodInfo
.
NO_BODY
)
{
return
null
;
}
Object
body
=
args
[
bodyIndex
];
...
...
retrofit/src/main/java/retrofit/
http/
RequestHeaders.java
→
retrofit/src/main/java/retrofit/RequestHeaders.java
浏览文件 @
ef71254e
...
...
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.util.Collections
;
import
java.util.List
;
import
retrofit.
http.
client.Header
;
import
retrofit.client.Header
;
/** Manages headers for each request. */
public
interface
RequestHeaders
{
...
...
@@ -25,7 +25,7 @@ public interface RequestHeaders {
* Get a list of headers for a request. This method will be called once for each request allowing
* you to change the list as the state of your application changes.
*/
List
<
retrofit
.
http
.
client
.
Header
>
get
();
List
<
Header
>
get
();
/** Empty header list. */
RequestHeaders
NONE
=
new
RequestHeaders
()
{
...
...
retrofit/src/main/java/retrofit/
http/
ResponseWrapper.java
→
retrofit/src/main/java/retrofit/ResponseWrapper.java
浏览文件 @
ef71254e
...
...
@@ -13,22 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
retrofit.
http.
client.Response
;
import
retrofit.client.Response
;
/**
* A wrapper that holds the {@link Response} and {@link
Converter} response to be used by the
* {@link CallbackRunnable} for success method calls on {@link Callback}.
* A wrapper that holds the {@link Response} and {@link
retrofit.converter.Converter} response to
*
be used by the
{@link CallbackRunnable} for success method calls on {@link Callback}.
*
* @author JJ Ford (jj.n.ford@gmail.com)
*/
final
class
ResponseWrapper
{
final
Response
response
;
final
Object
responseBody
;
public
ResponseWrapper
(
Response
response
,
Object
responseBody
)
{
ResponseWrapper
(
Response
response
,
Object
responseBody
)
{
this
.
response
=
response
;
this
.
responseBody
=
responseBody
;
}
...
...
retrofit/src/main/java/retrofit/
http/
RestAdapter.java
→
retrofit/src/main/java/retrofit/RestAdapter.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
...
...
@@ -26,16 +26,17 @@ import java.util.LinkedHashMap;
import
java.util.Map
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.TimeUnit
;
import
retrofit.http.Profiler.RequestInformation
;
import
retrofit.http.client.Client
;
import
retrofit.http.client.Header
;
import
retrofit.http.client.Request
;
import
retrofit.http.client.Response
;
import
retrofit.http.mime.TypedByteArray
;
import
retrofit.http.mime.TypedInput
;
import
retrofit.http.mime.TypedOutput
;
import
static
retrofit
.
http
.
Utils
.
SynchronousExecutor
;
import
retrofit.Profiler.RequestInformation
;
import
retrofit.client.Client
;
import
retrofit.client.Header
;
import
retrofit.client.Request
;
import
retrofit.client.Response
;
import
retrofit.converter.ConversionException
;
import
retrofit.converter.Converter
;
import
retrofit.mime.MimeUtil
;
import
retrofit.mime.TypedByteArray
;
import
retrofit.mime.TypedInput
;
import
retrofit.mime.TypedOutput
;
/**
* Adapts a Java interface to a REST API.
...
...
@@ -44,42 +45,47 @@ import static retrofit.http.Utils.SynchronousExecutor;
* the form in which the HTTP call should be made.
* <p>
* The relative path for a given method is obtained from an annotation on the method describing
* the request type. The built-in methods are {@link GET}, {@link PUT}, {@link POST}, {@link HEAD},
* and {@link DELETE}. You can define your own HTTP method by creating an annotation that takes a
* {code String} value and itself is annotated with {@link RestMethod @RestMethod}.
* the request type. The built-in methods are {@link retrofit.http.GET GET},
* {@link retrofit.http.PUT PUT}, {@link retrofit.http.POST POST}, {@link retrofit.http.HEAD HEAD},
* and {@link retrofit.http.DELETE DELETE}. You can define your own HTTP method by creating an
* annotation that takes a {code String} value and itself is annotated with
* {@link retrofit.http.RestMethod @RestMethod}.
* <p>
* Method parameters can be used to replace parts of the URL by annotating them with
* {@link Path @Path}. Replacement sections are denoted by an identifier surrounded by curly braces
* (e.g., "{foo}"). To add items to the query string of a URL use {@link Query @Query}.
* {@link retrofit.http.Path @Path}. Replacement sections are denoted by an identifier surrounded
* by curly braces (e.g., "{foo}"). To add items to the query string of a URL use
* {@link retrofit.http.Query @Query}.
* <p>
* HTTP requests happen in one of two ways:
* <ul>
* <li>On the provided HTTP {@link Executor} with callbacks marshaled to the callback
* {@link Executor}. The last method parameter should be of type {@link Callback}. The HTTP
* response will be converted to the callback's parameter type using the specified
* {@link
Converter}. If the callback parameter type uses a wildcard, the lower bound will be
* used as the conversion type.
* {@link
retrofit.converter.Converter Converter}. If the callback parameter type uses a wildcard,
*
the lower bound will be
used as the conversion type.
* <li>On the current thread returning the response or throwing a {@link RetrofitError}. The HTTP
* response will be converted to the method's return type using the specified {@link Converter}.
* response will be converted to the method's return type using the specified
* {@link retrofit.converter.Converter Converter}.
* </ul>
* <p>
* The body of a request is denoted by the {@link Body @Body} annotation. The object will be
* converted to request representation by a call to {@link Converter#toBody(Object) toBody} on the
* supplied {@link Converter} for this instance. The body can also be a {@link TypedOutput} where
* it will be used directly.
* The body of a request is denoted by the {@link retrofit.http.Body @Body} annotation. The object
* will be converted to request representation by a call to
* {@link retrofit.converter.Converter#toBody(Object) toBody} on the supplied
* {@link retrofit.converter.Converter Converter} for this instance. The body can also be a
* {@link TypedOutput} where it will be used directly.
* <p>
* Alternative request body formats are supported by method annotations and corresponding parameter
* annotations:
* <ul>
* <li>{@link
FormUrlEncoded @FormUrlEncoded} - Form-encoded data with pairs specified by the
*
{@link
Field @Field} parameter annotation.
* <li>{@link
Multipart @Multipart} - RFC 2387-compliant multi-part data with parts specified by
*
the {@link
Part @Part} parameter annotation.
* <li>{@link
retrofit.http.FormUrlEncoded @FormUrlEncoded} - Form-encoded data with pairs
*
specified by the {@link retrofit.http.
Field @Field} parameter annotation.
* <li>{@link
retrofit.http.Multipart @Multipart} - RFC 2387-compliant multi-part data with parts
*
specified by the {@link retrofit.http.
Part @Part} parameter annotation.
* </ul>
* <p>
* Additional static headers can be added for an endpoint using the
{@link Headers @Headers} method
*
annotation. For per-request control over a header annotate a parameter with
* {@link Header @Header}.
* Additional static headers can be added for an endpoint using the
*
{@link retrofit.http.Headers @Headers} method annotation. For per-request control over a header
*
annotate a parameter with
{@link Header @Header}.
* <p>
* For example:
* <pre>
...
...
@@ -132,7 +138,7 @@ public class RestAdapter {
this
.
debug
=
debug
;
}
/** Toggle debug logging on
and
off. */
/** Toggle debug logging on
or
off. */
public
void
setDebug
(
boolean
debug
)
{
this
.
debug
=
debug
;
}
...
...
@@ -189,8 +195,8 @@ public class RestAdapter {
/**
* Execute an HTTP request.
*
* @return HTTP response object of specified {@code type}.
* @throws RetrofitError
Thrown
if any error occurs during the HTTP request.
* @return HTTP response object of specified {@code type}
or {@code null}
.
* @throws RetrofitError if any error occurs during the HTTP request.
*/
private
Object
invokeRequest
(
RestMethodInfo
methodDetails
,
Object
[]
args
)
{
methodDetails
.
init
();
// Ensure all relevant method information has been loaded.
...
...
@@ -227,6 +233,7 @@ public class RestAdapter {
int
statusCode
=
response
.
getStatus
();
if
(
profiler
!=
null
)
{
RequestInformation
requestInfo
=
getRequestInfo
(
serverUrl
,
methodDetails
,
request
);
//noinspection unchecked
profiler
.
afterCall
(
requestInfo
,
elapsedTime
,
statusCode
,
profilerObject
);
}
...
...
@@ -302,7 +309,7 @@ public class RestAdapter {
byte
[]
bodyBytes
=
baos
.
toByteArray
();
bodySize
=
bodyBytes
.
length
;
String
bodyMime
=
body
.
mimeType
();
String
bodyString
=
new
String
(
bodyBytes
,
Utils
.
parseCharset
(
bodyMime
));
String
bodyString
=
new
String
(
bodyBytes
,
MimeUtil
.
parseCharset
(
bodyMime
));
for
(
int
i
=
0
,
len
=
bodyString
.
length
();
i
<
len
;
i
+=
LOG_CHUNK_SIZE
)
{
int
end
=
Math
.
min
(
len
,
i
+
LOG_CHUNK_SIZE
);
log
.
log
(
bodyString
.
substring
(
i
,
end
));
...
...
@@ -342,7 +349,7 @@ public class RestAdapter {
byte
[]
bodyBytes
=
((
TypedByteArray
)
body
).
getBytes
();
bodySize
=
bodyBytes
.
length
;
String
bodyMime
=
body
.
mimeType
();
String
bodyCharset
=
Utils
.
parseCharset
(
bodyMime
);
String
bodyCharset
=
MimeUtil
.
parseCharset
(
bodyMime
);
String
bodyString
=
new
String
(
bodyBytes
,
bodyCharset
);
for
(
int
i
=
0
,
len
=
bodyString
.
length
();
i
<
len
;
i
+=
LOG_CHUNK_SIZE
)
{
int
end
=
Math
.
min
(
len
,
i
+
LOG_CHUNK_SIZE
);
...
...
@@ -397,17 +404,20 @@ public class RestAdapter {
private
Log
log
;
private
boolean
debug
;
/** API server base URL. */
public
Builder
setServer
(
String
endpoint
)
{
if
(
endpoint
==
null
)
throw
new
NullPointerException
(
"endpoint"
);
return
setServer
(
new
Server
(
endpoint
));
}
/** API server. */
public
Builder
setServer
(
Server
server
)
{
if
(
server
==
null
)
throw
new
NullPointerException
(
"server"
);
this
.
server
=
server
;
return
this
;
}
/** The HTTP client used for requests. */
public
Builder
setClient
(
final
Client
client
)
{
if
(
client
==
null
)
throw
new
NullPointerException
(
"client"
);
return
setClient
(
new
Client
.
Provider
()
{
...
...
@@ -417,6 +427,7 @@ public class RestAdapter {
});
}
/** The HTTP client used for requests. */
public
Builder
setClient
(
Client
.
Provider
clientProvider
)
{
if
(
clientProvider
==
null
)
throw
new
NullPointerException
(
"clientProvider"
);
this
.
clientProvider
=
clientProvider
;
...
...
@@ -433,41 +444,47 @@ public class RestAdapter {
*/
public
Builder
setExecutors
(
Executor
httpExecutor
,
Executor
callbackExecutor
)
{
if
(
httpExecutor
==
null
)
throw
new
NullPointerException
(
"httpExecutor"
);
if
(
callbackExecutor
==
null
)
callbackExecutor
=
new
SynchronousExecutor
();
if
(
callbackExecutor
==
null
)
callbackExecutor
=
new
Utils
.
SynchronousExecutor
();
this
.
httpExecutor
=
httpExecutor
;
this
.
callbackExecutor
=
callbackExecutor
;
return
this
;
}
/** */
public
Builder
setRequestHeaders
(
RequestHeaders
requestHeaders
)
{
if
(
requestHeaders
==
null
)
throw
new
NullPointerException
(
"requestHeaders"
);
this
.
requestHeaders
=
requestHeaders
;
return
this
;
}
/** The converter used for serialization and deserialization of objects. */
public
Builder
setConverter
(
Converter
converter
)
{
if
(
converter
==
null
)
throw
new
NullPointerException
(
"converter"
);
this
.
converter
=
converter
;
return
this
;
}
/** Set the profiler used to measure requests. */
public
Builder
setProfiler
(
Profiler
profiler
)
{
if
(
profiler
==
null
)
throw
new
NullPointerException
(
"profiler"
);
this
.
profiler
=
profiler
;
return
this
;
}
/** Configure debug logging mechanism. */
public
Builder
setLog
(
Log
log
)
{
if
(
log
==
null
)
throw
new
NullPointerException
(
"log"
);
this
.
log
=
log
;
return
this
;
}
/** Enable debug logging. */
public
Builder
setDebug
(
boolean
debug
)
{
this
.
debug
=
debug
;
return
this
;
}
/** Create the {@link RestAdapter} instances. */
public
RestAdapter
build
()
{
if
(
server
==
null
)
{
throw
new
IllegalArgumentException
(
"Server may not be null."
);
...
...
retrofit/src/main/java/retrofit/
http/
RestMethodInfo.java
→
retrofit/src/main/java/retrofit/RestMethodInfo.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
...
...
@@ -26,6 +26,16 @@ import java.util.List;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
retrofit.http.Body
;
import
retrofit.http.Field
;
import
retrofit.http.FormUrlEncoded
;
import
retrofit.http.Header
;
import
retrofit.http.Headers
;
import
retrofit.http.Multipart
;
import
retrofit.http.Part
;
import
retrofit.http.Path
;
import
retrofit.http.Query
;
import
retrofit.http.RestMethod
;
/** Request metadata about a service interface declaration. */
final
class
RestMethodInfo
{
...
...
@@ -57,7 +67,7 @@ final class RestMethodInfo {
String
requestUrl
;
Set
<
String
>
requestUrlParamNames
;
String
requestQuery
;
List
<
retrofit
.
http
.
client
.
Header
>
headers
;
List
<
retrofit
.
client
.
Header
>
headers
;
// Parameter-level details
String
[]
requestUrlParam
;
...
...
@@ -198,14 +208,14 @@ final class RestMethodInfo {
requestQuery
=
query
;
}
private
List
<
retrofit
.
http
.
client
.
Header
>
parseHeaders
(
String
[]
headers
)
{
List
<
retrofit
.
http
.
client
.
Header
>
headerList
=
new
ArrayList
<
retrofit
.
http
.
client
.
Header
>();
private
List
<
retrofit
.
client
.
Header
>
parseHeaders
(
String
[]
headers
)
{
List
<
retrofit
.
client
.
Header
>
headerList
=
new
ArrayList
<
retrofit
.
client
.
Header
>();
for
(
String
header
:
headers
)
{
int
colon
=
header
.
indexOf
(
':'
);
if
(
colon
==
-
1
||
colon
==
0
||
colon
==
headers
.
length
-
1
)
{
throw
new
IllegalStateException
(
"Header must be in the form 'Name: Value': "
+
header
);
}
headerList
.
add
(
new
retrofit
.
http
.
client
.
Header
(
header
.
substring
(
0
,
colon
),
headerList
.
add
(
new
retrofit
.
client
.
Header
(
header
.
substring
(
0
,
colon
),
header
.
substring
(
colon
+
1
).
trim
()));
}
return
headerList
;
...
...
retrofit/src/main/java/retrofit/
http/
RetrofitError.java
→
retrofit/src/main/java/retrofit/RetrofitError.java
浏览文件 @
ef71254e
...
...
@@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
import
retrofit.http.client.Response
;
import
retrofit.http.mime.TypedInput
;
import
retrofit.client.Response
;
import
retrofit.converter.ConversionException
;
import
retrofit.converter.Converter
;
import
retrofit.mime.TypedInput
;
public
class
RetrofitError
extends
RuntimeException
{
public
static
RetrofitError
networkError
(
String
url
,
IOException
exception
)
{
...
...
retrofit/src/main/java/retrofit/
http/
Server.java
→
retrofit/src/main/java/retrofit/Server.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
/**
* Represents an API endpoint URL and associated name. Callers should always consult the instance
...
...
retrofit/src/main/java/retrofit/
http/
Types.java
→
retrofit/src/main/java/retrofit/Types.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.GenericArrayType
;
...
...
retrofit/src/main/java/retrofit/
http/
Utils.java
→
retrofit/src/main/java/retrofit/Utils.java
浏览文件 @
ef71254e
...
...
@@ -14,22 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit
.http
;
package
retrofit
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.concurrent.Executor
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
retrofit.http.client.Response
;
import
retrofit.http.mime.TypedByteArray
;
import
retrofit.http.mime.TypedInput
;
import
retrofit.client.Response
;
import
retrofit.mime.TypedByteArray
;
import
retrofit.mime.TypedInput
;
import
static
java
.
util
.
regex
.
Pattern
.
CASE_INSENSITIVE
;
public
final
class
Utils
{
private
static
final
Pattern
CHARSET
=
Pattern
.
compile
(
"\\Wcharset=([^\\s;]+)"
,
CASE_INSENSITIVE
);
final
class
Utils
{
private
static
final
int
BUFFER_SIZE
=
0x1000
;
/**
...
...
@@ -71,14 +66,6 @@ public final class Utils {
return
new
Response
(
response
.
getStatus
(),
response
.
getReason
(),
response
.
getHeaders
(),
body
);
}
public
static
String
parseCharset
(
String
mimeType
)
{
Matcher
match
=
CHARSET
.
matcher
(
mimeType
);
if
(
match
.
find
())
{
return
match
.
group
(
1
).
replaceAll
(
"[\"\\\\]"
,
""
);
}
return
"UTF-8"
;
}
static
class
SynchronousExecutor
implements
Executor
{
@Override
public
void
execute
(
Runnable
runnable
)
{
runnable
.
run
();
...
...
retrofit/src/main/java/retrofit/
http/
android/AndroidApacheClient.java
→
retrofit/src/main/java/retrofit/android/AndroidApacheClient.java
浏览文件 @
ef71254e
...
...
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
android
;
package
retrofit.android
;
import
android.net.http.AndroidHttpClient
;
import
retrofit.
http.
client.ApacheClient
;
import
retrofit.client.ApacheClient
;
/**
* Provides a {@link retrofit.
http.
client.Client} which uses the Android-specific version of
* Provides a {@link retrofit.client.Client} which uses the Android-specific version of
* {@link org.apache.http.client.HttpClient}, {@link AndroidHttpClient}.
* <p>
* If you need to provide a customized version of the {@link AndroidHttpClient} or a different
...
...
retrofit/src/main/java/retrofit/
http/
android/MainThreadExecutor.java
→
retrofit/src/main/java/retrofit/android/MainThreadExecutor.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
android
;
package
retrofit.android
;
import
android.os.Handler
;
import
android.os.Looper
;
...
...
retrofit/src/main/java/retrofit/
http/
client/ApacheClient.java
→
retrofit/src/main/java/retrofit/client/ApacheClient.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
...
...
@@ -33,8 +33,8 @@ import org.apache.http.entity.AbstractHttpEntity;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.message.BasicHeader
;
import
org.apache.http.util.EntityUtils
;
import
retrofit.
http.
mime.TypedByteArray
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.mime.TypedByteArray
;
import
retrofit.mime.TypedOutput
;
/** A {@link Client} which uses an implementation of Apache's {@link HttpClient}. */
public
class
ApacheClient
implements
Client
{
...
...
retrofit/src/main/java/retrofit/
http/
client/Client.java
→
retrofit/src/main/java/retrofit/client/Client.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.io.IOException
;
...
...
retrofit/src/main/java/retrofit/
http/
client/Header.java
→
retrofit/src/main/java/retrofit/client/Header.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
/** Represents an HTTP header name/value pair. */
public
final
class
Header
{
...
...
retrofit/src/main/java/retrofit/
http/
client/OkClient.java
→
retrofit/src/main/java/retrofit/client/OkClient.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
com.squareup.okhttp.OkHttpClient
;
import
java.io.IOException
;
...
...
retrofit/src/main/java/retrofit/
http/
client/Request.java
→
retrofit/src/main/java/retrofit/client/Request.java
浏览文件 @
ef71254e
...
...
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.mime.TypedOutput
;
/** Encapsulates all of the information necessary to make an HTTP request. */
public
final
class
Request
{
...
...
retrofit/src/main/java/retrofit/
http/
client/Response.java
→
retrofit/src/main/java/retrofit/client/Response.java
浏览文件 @
ef71254e
...
...
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
retrofit.
http.
mime.TypedInput
;
import
retrofit.mime.TypedInput
;
/** An HTTP response. */
public
final
class
Response
{
...
...
retrofit/src/main/java/retrofit/
http/
client/UrlConnectionClient.java
→
retrofit/src/main/java/retrofit/client/UrlConnectionClient.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -22,8 +22,8 @@ import java.net.URL;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
retrofit.
http.
mime.TypedInput
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.mime.TypedInput
;
import
retrofit.mime.TypedOutput
;
/** Retrofit client that uses {@link HttpURLConnection} for communication. */
public
class
UrlConnectionClient
implements
Client
{
...
...
retrofit/src/main/java/retrofit/
http
/ConversionException.java
→
retrofit/src/main/java/retrofit/
converter
/ConversionException.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http
;
package
retrofit.
converter
;
/** Indicate that conversion was unable to complete successfully. */
@SuppressWarnings
(
"UnusedDeclaration"
)
...
...
retrofit/src/main/java/retrofit/
http
/Converter.java
→
retrofit/src/main/java/retrofit/
converter
/Converter.java
浏览文件 @
ef71254e
...
...
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http
;
package
retrofit.
converter
;
import
java.lang.reflect.Type
;
import
retrofit.
http.
mime.TypedInput
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.mime.TypedInput
;
import
retrofit.mime.TypedOutput
;
/**
* Arbiter for converting objects to and from their representation in HTTP.
...
...
@@ -32,9 +32,9 @@ public interface Converter {
* @param type Target object type.
* @return Instance of {@code type} which will be cast by the caller.
* @throws ConversionException if conversion was unable to complete. This will trigger a call to
* {@link
Callback#failure(RetrofitError)} or throw a {@link retrofit.http.RetrofitError}. The
*
exception message should report all necessary information about its cause as the response body
* will be set to {@code null}.
* {@link
retrofit.Callback#failure(retrofit.RetrofitError)} or throw a
*
{@link retrofit.RetrofitError}. The exception message should report all necessary information
*
about its cause as the response body
will be set to {@code null}.
*/
Object
fromBody
(
TypedInput
body
,
Type
type
)
throws
ConversionException
;
...
...
retrofit/src/main/java/retrofit/
http
/GsonConverter.java
→
retrofit/src/main/java/retrofit/
converter
/GsonConverter.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http
;
package
retrofit.
converter
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonParseException
;
...
...
@@ -22,8 +22,9 @@ import java.io.InputStreamReader;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Type
;
import
retrofit.http.mime.TypedInput
;
import
retrofit.http.mime.TypedOutput
;
import
retrofit.mime.MimeUtil
;
import
retrofit.mime.TypedInput
;
import
retrofit.mime.TypedOutput
;
/**
* A {@link Converter} which uses GSON for serialization and deserialization of entities.
...
...
@@ -38,7 +39,7 @@ public class GsonConverter implements Converter {
}
@Override
public
Object
fromBody
(
TypedInput
body
,
Type
type
)
throws
ConversionException
{
String
charset
=
Utils
.
parseCharset
(
body
.
mimeType
());
String
charset
=
MimeUtil
.
parseCharset
(
body
.
mimeType
());
InputStreamReader
isr
=
null
;
try
{
isr
=
new
InputStreamReader
(
body
.
in
(),
charset
);
...
...
@@ -65,7 +66,7 @@ public class GsonConverter implements Converter {
}
}
static
class
JsonTypedOutput
implements
TypedOutput
{
private
static
class
JsonTypedOutput
implements
TypedOutput
{
private
final
byte
[]
jsonBytes
;
JsonTypedOutput
(
byte
[]
jsonBytes
)
{
...
...
retrofit/src/main/java/retrofit/http/Parameter.java
已删除
100644 → 0
浏览文件 @
4f3798e6
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.http
;
import
java.lang.reflect.Type
;
/**
* Represents a named parameter and its value.
* <p>
* This is used in one of three places in a request:
* <ul>
* <li>Named replacement in the relative URL path.
* <li>As a URL query parameter.
* <li>As a POST/PUT body.
* </ul>
*/
public
final
class
Parameter
{
private
final
String
name
;
private
final
Type
type
;
private
final
Object
value
;
public
Parameter
(
String
name
,
Object
value
,
Type
valueType
)
{
if
(
name
==
null
)
{
throw
new
NullPointerException
(
"name == null"
);
}
this
.
name
=
name
;
this
.
type
=
valueType
;
this
.
value
=
value
;
}
public
String
getName
()
{
return
name
;
}
public
Object
getValue
()
{
return
value
;
}
/** The instance type of {@link #getValue()}. */
public
Type
getValueType
()
{
return
type
;
}
@Override
public
String
toString
()
{
return
name
+
"="
+
value
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Parameter
parameter
=
(
Parameter
)
o
;
if
(!
name
.
equals
(
parameter
.
name
))
return
false
;
if
(
value
!=
null
?
!
value
.
equals
(
parameter
.
value
)
:
parameter
.
value
!=
null
)
return
false
;
return
true
;
}
@Override
public
int
hashCode
()
{
int
result
=
name
.
hashCode
();
result
=
31
*
result
+
(
value
!=
null
?
value
.
hashCode
()
:
0
);
return
result
;
}
}
retrofit/src/main/java/retrofit/http/Part.java
浏览文件 @
ef71254e
...
...
@@ -26,10 +26,10 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* <p>
* The parameter type on which this annotation exists will be processed in one of two ways:
* <ul>
* <li>If the type implements {@link retrofit.
http.
mime.TypedOutput TypedOutput} the headers and
* <li>If the type implements {@link retrofit.mime.TypedOutput TypedOutput} the headers and
* body will be used directly.</li>
* <li>Other object types will be converted to an appropriate representation by calling {@link
* Converter#toBody(Object)}.</li>
*
retrofit.converter.
Converter#toBody(Object)}.</li>
* </ul>
* <p>
* <pre>
...
...
retrofit/src/main/java/retrofit/
http/
mime/FormUrlEncodedTypedOutput.java
→
retrofit/src/main/java/retrofit/mime/FormUrlEncodedTypedOutput.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
...
...
retrofit/src/main/java/retrofit/mime/MimeUtil.java
0 → 100644
浏览文件 @
ef71254e
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.mime
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
java
.
util
.
regex
.
Pattern
.
CASE_INSENSITIVE
;
public
final
class
MimeUtil
{
private
static
final
Pattern
CHARSET
=
Pattern
.
compile
(
"\\Wcharset=([^\\s;]+)"
,
CASE_INSENSITIVE
);
/** Parse the MIME type from a {@code Content-Type} header value. */
public
static
String
parseCharset
(
String
mimeType
)
{
Matcher
match
=
CHARSET
.
matcher
(
mimeType
);
if
(
match
.
find
())
{
return
match
.
group
(
1
).
replaceAll
(
"[\"\\\\]"
,
""
);
}
return
"UTF-8"
;
}
private
MimeUtil
()
{
// No instances.
}
}
retrofit/src/main/java/retrofit/
http/
mime/MultipartTypedOutput.java
→
retrofit/src/main/java/retrofit/mime/MultipartTypedOutput.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
...
...
retrofit/src/main/java/retrofit/
http/
mime/TypedByteArray.java
→
retrofit/src/main/java/retrofit/mime/TypedByteArray.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
...
...
retrofit/src/main/java/retrofit/
http/
mime/TypedFile.java
→
retrofit/src/main/java/retrofit/mime/TypedFile.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
retrofit/src/main/java/retrofit/
http/
mime/TypedInput.java
→
retrofit/src/main/java/retrofit/mime/TypedInput.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
retrofit/src/main/java/retrofit/
http/
mime/TypedOutput.java
→
retrofit/src/main/java/retrofit/mime/TypedOutput.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.IOException
;
import
java.io.OutputStream
;
...
...
retrofit/src/main/java/retrofit/
http/
mime/TypedString.java
→
retrofit/src/main/java/retrofit/mime/TypedString.java
浏览文件 @
ef71254e
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.UnsupportedEncodingException
;
...
...
retrofit/src/test/java/retrofit/
http/
CallbackRunnableTest.java
→
retrofit/src/test/java/retrofit/CallbackRunnableTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit
.http
;
package
retrofit
;
import
java.util.concurrent.Executor
;
import
org.junit.Before
;
import
org.junit.Test
;
import
retrofit.Callback
;
import
retrofit.CallbackRunnable
;
import
retrofit.ResponseWrapper
;
import
retrofit.RetrofitError
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
same
;
...
...
@@ -11,7 +15,7 @@ import static org.mockito.Mockito.mock;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
retrofit
.
http
.
Utils
.
SynchronousExecutor
;
import
static
retrofit
.
Utils
.
SynchronousExecutor
;
public
class
CallbackRunnableTest
{
private
Executor
executor
=
spy
(
new
SynchronousExecutor
());
...
...
retrofit/src/test/java/retrofit/
http/
RequestBuilderTest.java
→
retrofit/src/test/java/retrofit/RequestBuilderTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit
.http
;
package
retrofit
;
import
com.google.gson.Gson
;
import
java.io.ByteArrayOutputStream
;
...
...
@@ -10,16 +10,20 @@ import java.util.Arrays;
import
java.util.Iterator
;
import
java.util.List
;
import
org.junit.Test
;
import
retrofit.http.client.Header
;
import
retrofit.http.client.Request
;
import
retrofit.http.mime.MimeHelper
;
import
retrofit.http.mime.MultipartTypedOutput
;
import
retrofit.http.mime.TypedOutput
;
import
retrofit.http.mime.TypedString
;
import
retrofit.converter.Converter
;
import
retrofit.converter.GsonConverter
;
import
retrofit.RequestBuilder
;
import
retrofit.RestMethodInfo
;
import
retrofit.client.Header
;
import
retrofit.client.Request
;
import
retrofit.mime.MimeHelper
;
import
retrofit.mime.MultipartTypedOutput
;
import
retrofit.mime.TypedOutput
;
import
retrofit.mime.TypedString
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
retrofit
.
http
.
RestMethodInfo
.
NO_BODY
;
import
static
retrofit
.
http
.
RestMethodInfo
.
RequestType
;
import
static
retrofit
.
RestMethodInfo
.
NO_BODY
;
import
static
retrofit
.
RestMethodInfo
.
RequestType
;
public
class
RequestBuilderTest
{
@Test
public
void
normalGet
()
throws
Exception
{
...
...
retrofit/src/test/java/retrofit/
http/
RestAdapterTest.java
→
retrofit/src/test/java/retrofit/RestAdapterTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit
.http
;
package
retrofit
;
import
java.io.IOException
;
import
java.util.Collections
;
...
...
@@ -7,11 +7,13 @@ import java.util.List;
import
java.util.concurrent.Executor
;
import
org.junit.Before
;
import
org.junit.Test
;
import
retrofit.http.client.Client
;
import
retrofit.http.client.Header
;
import
retrofit.http.client.Request
;
import
retrofit.http.client.Response
;
import
retrofit.http.mime.TypedString
;
import
retrofit.converter.ConversionException
;
import
retrofit.http.GET
;
import
retrofit.client.Client
;
import
retrofit.client.Header
;
import
retrofit.client.Request
;
import
retrofit.client.Response
;
import
retrofit.mime.TypedString
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
fail
;
...
...
@@ -25,8 +27,8 @@ import static org.mockito.Mockito.spy;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyZeroInteractions
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
retrofit
.
http
.
Profiler
.
RequestInformation
;
import
static
retrofit
.
http
.
Utils
.
SynchronousExecutor
;
import
static
retrofit
.
Profiler
.
RequestInformation
;
import
static
retrofit
.
Utils
.
SynchronousExecutor
;
public
class
RestAdapterTest
{
private
static
List
<
Header
>
NO_HEADERS
=
Collections
.
emptyList
();
...
...
retrofit/src/test/java/retrofit/
http/
RestMethodInfoTest.java
→
retrofit/src/test/java/retrofit/RestMethodInfoTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit
.http
;
package
retrofit
;
import
com.google.gson.reflect.TypeToken
;
import
java.lang.annotation.Retention
;
...
...
@@ -11,14 +11,29 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Set
;
import
org.junit.Test
;
import
retrofit.http.mime.TypedOutput
;
import
retrofit.http.Body
;
import
retrofit.http.DELETE
;
import
retrofit.http.Field
;
import
retrofit.http.FormUrlEncoded
;
import
retrofit.http.GET
;
import
retrofit.http.HEAD
;
import
retrofit.http.Header
;
import
retrofit.http.Headers
;
import
retrofit.http.Multipart
;
import
retrofit.http.POST
;
import
retrofit.http.PUT
;
import
retrofit.http.Part
;
import
retrofit.http.Path
;
import
retrofit.http.Query
;
import
retrofit.http.RestMethod
;
import
retrofit.mime.TypedOutput
;
import
static
java
.
lang
.
annotation
.
ElementType
.
METHOD
;
import
static
java
.
lang
.
annotation
.
RetentionPolicy
.
RUNTIME
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
retrofit
.
http
.
RestMethodInfo
.
NO_BODY
;
import
static
retrofit
.
http
.
RestMethodInfo
.
RequestType
.
MULTIPART
;
import
static
retrofit
.
http
.
RestMethodInfo
.
RequestType
.
SIMPLE
;
import
static
retrofit
.
RestMethodInfo
.
NO_BODY
;
import
static
retrofit
.
RestMethodInfo
.
RequestType
.
MULTIPART
;
import
static
retrofit
.
RestMethodInfo
.
RequestType
.
SIMPLE
;
public
class
RestMethodInfoTest
{
@Test
public
void
pathParameterParsing
()
throws
Exception
{
...
...
@@ -678,8 +693,8 @@ public class RestMethodInfoTest {
methodInfo
.
init
();
assertThat
(
methodInfo
.
headers
).
isEqualTo
(
Arrays
.
asList
(
new
retrofit
.
http
.
client
.
Header
(
"X-Foo"
,
"Bar"
),
new
retrofit
.
http
.
client
.
Header
(
"X-Ping"
,
"Pong"
)));
Arrays
.
asList
(
new
retrofit
.
client
.
Header
(
"X-Foo"
,
"Bar"
),
new
retrofit
.
client
.
Header
(
"X-Ping"
,
"Pong"
)));
}
@Test
public
void
twoHeaderParams
()
{
...
...
retrofit/src/test/java/retrofit/
http/
TestingUtils.java
→
retrofit/src/test/java/retrofit/TestingUtils.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit
.http
;
package
retrofit
;
import
java.lang.reflect.Method
;
import
java.util.Map
;
import
retrofit.
http.
mime.MultipartTypedOutput
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.mime.MultipartTypedOutput
;
import
retrofit.mime.TypedOutput
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
...
...
retrofit/src/test/java/retrofit/
http/
client/ApacheClientTest.java
→
retrofit/src/test/java/retrofit/client/ApacheClientTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
client
;
package
retrofit.client
;
import
com.google.common.io.ByteStreams
;
import
java.util.ArrayList
;
...
...
@@ -15,14 +15,14 @@ import org.apache.http.client.methods.HttpUriRequest;
import
org.apache.http.message.BasicHttpResponse
;
import
org.apache.http.message.BasicStatusLine
;
import
org.junit.Test
;
import
retrofit.
http.
TestingUtils
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.
http.
mime.TypedString
;
import
retrofit.TestingUtils
;
import
retrofit.mime.TypedOutput
;
import
retrofit.mime.TypedString
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
retrofit
.
http
.
TestingUtils
.
assertBytes
;
import
static
retrofit
.
http
.
TestingUtils
.
assertMultipart
;
import
static
retrofit
.
http
.
client
.
ApacheClient
.
TypedOutputEntity
;
import
static
retrofit
.
TestingUtils
.
assertBytes
;
import
static
retrofit
.
TestingUtils
.
assertMultipart
;
import
static
retrofit
.
client
.
ApacheClient
.
TypedOutputEntity
;
public
class
ApacheClientTest
{
private
static
final
String
HOST
=
"http://example.com"
;
...
...
retrofit/src/test/java/retrofit/
http/
client/DummyHttpUrlConnection.java
→
retrofit/src/test/java/retrofit/client/DummyHttpUrlConnection.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
client
;
package
retrofit.client
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
...
...
@@ -13,7 +13,7 @@ import java.util.List;
import
java.util.Map
;
/**
* Provides POJO behavior for all of the APIs {@link retrofit.
http.
client.UrlConnectionClient}
* Provides POJO behavior for all of the APIs {@link retrofit.client.UrlConnectionClient}
* interacts with.
*/
public
class
DummyHttpUrlConnection
extends
HttpURLConnection
{
...
...
retrofit/src/test/java/retrofit/
http/
client/UrlConnectionClientTest.java
→
retrofit/src/test/java/retrofit/client/UrlConnectionClientTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
client
;
package
retrofit.client
;
import
com.google.common.io.ByteStreams
;
import
java.io.ByteArrayInputStream
;
...
...
@@ -10,12 +10,12 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.junit.Test
;
import
retrofit.
http.
TestingUtils
;
import
retrofit.
http.
mime.TypedOutput
;
import
retrofit.
http.
mime.TypedString
;
import
retrofit.TestingUtils
;
import
retrofit.mime.TypedOutput
;
import
retrofit.mime.TypedString
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
retrofit
.
http
.
TestingUtils
.
assertBytes
;
import
static
retrofit
.
TestingUtils
.
assertBytes
;
public
class
UrlConnectionClientTest
{
private
static
final
String
HOST
=
"http://example.com"
;
...
...
retrofit/src/test/java/retrofit/
http/
mime/FormUrlEncodingTypedOutputTest.java
→
retrofit/src/test/java/retrofit/mime/FormUrlEncodingTypedOutputTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.ByteArrayOutputStream
;
import
org.junit.Test
;
...
...
retrofit/src/test/java/retrofit/
http/
mime/MimeHelper.java
→
retrofit/src/test/java/retrofit/mime/MimeHelper.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.util.List
;
...
...
retrofit/src/test/java/retrofit/
http/Utils
Test.java
→
retrofit/src/test/java/retrofit/
mime/MimeUtil
Test.java
浏览文件 @
ef71254e
// Copyright 2012 Square, Inc.
package
retrofit.
http
;
package
retrofit.
mime
;
import
org.junit.Test
;
import
static
org
.
fest
.
assertions
.
api
.
Assertions
.
assertThat
;
import
static
retrofit
.
http
.
Utils
.
parseCharset
;
import
static
retrofit
.
mime
.
MimeUtil
.
parseCharset
;
public
class
Utils
Test
{
public
class
MimeUtil
Test
{
@Test
public
void
charsetParsing
()
{
assertThat
(
parseCharset
(
"text/plain;charset=utf-8"
)).
isEqualToIgnoringCase
(
"UTF-8"
);
assertThat
(
parseCharset
(
"text/plain; charset=utf-8"
)).
isEqualToIgnoringCase
(
"UTF-8"
);
...
...
retrofit/src/test/java/retrofit/
http/
mime/MultipartTypedOutputTest.java
→
retrofit/src/test/java/retrofit/mime/MultipartTypedOutputTest.java
浏览文件 @
ef71254e
// Copyright 2013 Square, Inc.
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.ByteArrayOutputStream
;
import
org.junit.Test
;
...
...
retrofit/src/test/java/retrofit/
http/
mime/TypedByteArrayTest.java
→
retrofit/src/test/java/retrofit/mime/TypedByteArrayTest.java
浏览文件 @
ef71254e
// Copyright 2010 Square, Inc.
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
org.junit.Test
;
...
...
retrofit/src/test/java/retrofit/
http/
mime/TypedFileTest.java
→
retrofit/src/test/java/retrofit/mime/TypedFileTest.java
浏览文件 @
ef71254e
// Copyright 2010 Square, Inc.
package
retrofit.
http.
mime
;
package
retrofit.mime
;
import
java.io.File
;
import
java.io.FileOutputStream
;
...
...
samples/github-client/src/main/java/com/
squareup/retrofit/sample/github/
Client.java
→
samples/github-client/src/main/java/com/
example/retrofit/GitHub
Client.java
浏览文件 @
ef71254e
...
...
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.
squareup.retrofit.sample.github
;
package
com.
example.retrofit
;
import
java.util.List
;
import
retrofit.http.GET
;
import
retrofit.http.Path
;
import
retrofit.
http.
RestAdapter
;
import
retrofit.RestAdapter
;
public
class
Client
{
public
class
GitHub
Client
{
private
static
final
String
API_URL
=
"https://api.github.com"
;
class
Contributor
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录