| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,7 +89,10 @@ public class ClientMain | |||
| 89 | 89 | public static final String ASYNC_MESSAGING_BLOCKING_PATH = "async/messaging/blocking"; | |
| 90 | 90 | public static final String ASYNC_LONG_RUNNING_OP_PATH = "async/longrunning"; | |
| 91 | 91 | ||
| 92 | - private WebTarget newTarget() | ||
| 92 | + /** | ||
| 93 | + * 注意:HTTP连接的建立比较耗时,使用WebTarget进行第一次访问时耗时达到秒级,是后续访问耗时(毫秒级)的级数倍,在密集访问下,建议尽量重用WebTarget实例。 | ||
| 94 | + */ | ||
| 95 | + private WebTarget newWebTarget() | ||
| 93 | 96 | { | |
| 94 | 97 | Credentials credentials = new Credentials(RestServerConfig.getAccessKey(), RestServerConfig.getSecretKey()); | |
| 95 | 98 | Signer signer = new AwsSigner(); | |
@@ -111,7 +114,7 @@ private int getAsyncTimeoutMultiplier() | |||
| 111 | 114 | @Test | |
| 112 | 115 | public void testGetStudent() throws InterruptedException | |
| 113 | 116 | { | |
| 114 | - Builder builder = newTarget().path("school/student/json/student/{id}").resolveTemplate("id", 20082890) | ||
| 117 | + Builder builder = newWebTarget().path("school/student/json/student/{id}").resolveTemplate("id", 20082890) | ||
| 115 | 118 | .request(MediaType.APPLICATION_JSON_TYPE).header(HttpHeaders.DATE, System.currentTimeMillis()); | |
| 116 | 119 | ||
| 117 | 120 | Response response = builder.get(); | |
@@ -131,7 +134,7 @@ public void testGetStudent() throws InterruptedException | |||
| 131 | 134 | @Test | |
| 132 | 135 | public void testCreateStudent() throws InterruptedException | |
| 133 | 136 | { | |
| 134 | - Builder builder = newTarget().path("school/student/json/student").request(MediaType.APPLICATION_JSON_TYPE) | ||
| 137 | + Builder builder = newWebTarget().path("school/student/json/student").request(MediaType.APPLICATION_JSON_TYPE) | ||
| 135 | 138 | .header(HttpHeaders.DATE, System.currentTimeMillis()); | |
| 136 | 139 | ||
| 137 | 140 | Response response = builder.post(Entity.json(new Student(System.currentTimeMillis(), "xiaofang", "女"))); | |
@@ -151,14 +154,14 @@ public void testCreateStudent() throws InterruptedException | |||
| 151 | 154 | @Test | |
| 152 | 155 | public void testFireAndForgetChatResource() throws InterruptedException | |
| 153 | 156 | { | |
| 154 | - executeChatTest(newTarget().path(ClientMain.ASYNC_MESSAGING_FIRE_N_FORGET_PATH), | ||
| 157 | + executeChatTest(newWebTarget().path(ClientMain.ASYNC_MESSAGING_FIRE_N_FORGET_PATH), | ||
| 155 | 158 | FireAndForgetChatResource.POST_NOTIFICATION_RESPONSE); | |
| 156 | 159 | } | |
| 157 | 160 | ||
| 158 | 161 | @Test | |
| 159 | 162 | public void testBlockingPostChatResource() throws InterruptedException | |
| 160 | 163 | { | |
| 161 | - executeChatTest(newTarget().path(ClientMain.ASYNC_MESSAGING_BLOCKING_PATH), | ||
| 164 | + executeChatTest(newWebTarget().path(ClientMain.ASYNC_MESSAGING_BLOCKING_PATH), | ||
| 162 | 165 | BlockingPostChatResource.POST_NOTIFICATION_RESPONSE); | |
| 163 | 166 | } | |
| 164 | 167 | ||
@@ -372,7 +375,7 @@ private void get() | |||
| 372 | 375 | @Test | |
| 373 | 376 | public void testLongRunningResource() throws InterruptedException | |
| 374 | 377 | { | |
| 375 | - final WebTarget resourceTarget = newTarget().path(ClientMain.ASYNC_LONG_RUNNING_OP_PATH); | ||
| 378 | + final WebTarget resourceTarget = newWebTarget().path(ClientMain.ASYNC_LONG_RUNNING_OP_PATH); | ||
| 376 | 379 | final String expectedResponse = SimpleLongRunningResource.NOTIFICATION_RESPONSE; | |
| 377 | 380 | ||
| 378 | 381 | final int MAX_MESSAGES = 100; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,9 @@ public Map<String, Object> getDetails() | |||
| 108 | 108 | return details; | |
| 109 | 109 | } | |
| 110 | 110 | ||
| 111 | + /** | ||
| 112 | + * errorId与errorMessage字段为必备,可附加其他参数,目的是帮助客户端理解导致错误的原因,后续在恰当的时间能够重建请求。 | ||
| 113 | + */ | ||
| 111 | 114 | public RESTServiceException addDetail(String name, Object value) | |
| 112 | 115 | { | |
| 113 | 116 | details.put(name, value); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments