FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

restserver jersey · sherlock111/java-code@bfc49a2 · GitHub

Repository navigation

Commit bfc49a2

Browse files
committed
restserver jersey
1 parent 4785452 commit bfc49a2

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎basicKnowledge/src/com/xdc/basic/api/restserver/jersey/ClientMain.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public class ClientMain
8989
public static final String ASYNC_MESSAGING_BLOCKING_PATH = "async/messaging/blocking";
9090
public static final String ASYNC_LONG_RUNNING_OP_PATH = "async/longrunning";
9191

92-
private WebTarget newTarget()
92+
/**
93+
* 注意:HTTP连接的建立比较耗时,使用WebTarget进行第一次访问时耗时达到秒级,是后续访问耗时(毫秒级)的级数倍,在密集访问下,建议尽量重用WebTarget实例。
94+
*/
95+
private WebTarget newWebTarget()
9396
{
9497
Credentials credentials = new Credentials(RestServerConfig.getAccessKey(), RestServerConfig.getSecretKey());
9598
Signer signer = new AwsSigner();
@@ -111,7 +114,7 @@ private int getAsyncTimeoutMultiplier()
111114
@Test
112115
public void testGetStudent() throws InterruptedException
113116
{
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)
115118
.request(MediaType.APPLICATION_JSON_TYPE).header(HttpHeaders.DATE, System.currentTimeMillis());
116119

117120
Response response = builder.get();
@@ -131,7 +134,7 @@ public void testGetStudent() throws InterruptedException
131134
@Test
132135
public void testCreateStudent() throws InterruptedException
133136
{
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)
135138
.header(HttpHeaders.DATE, System.currentTimeMillis());
136139

137140
Response response = builder.post(Entity.json(new Student(System.currentTimeMillis(), "xiaofang", "女")));
@@ -151,14 +154,14 @@ public void testCreateStudent() throws InterruptedException
151154
@Test
152155
public void testFireAndForgetChatResource() throws InterruptedException
153156
{
154-
executeChatTest(newTarget().path(ClientMain.ASYNC_MESSAGING_FIRE_N_FORGET_PATH),
157+
executeChatTest(newWebTarget().path(ClientMain.ASYNC_MESSAGING_FIRE_N_FORGET_PATH),
155158
FireAndForgetChatResource.POST_NOTIFICATION_RESPONSE);
156159
}
157160

158161
@Test
159162
public void testBlockingPostChatResource() throws InterruptedException
160163
{
161-
executeChatTest(newTarget().path(ClientMain.ASYNC_MESSAGING_BLOCKING_PATH),
164+
executeChatTest(newWebTarget().path(ClientMain.ASYNC_MESSAGING_BLOCKING_PATH),
162165
BlockingPostChatResource.POST_NOTIFICATION_RESPONSE);
163166
}
164167

@@ -372,7 +375,7 @@ private void get()
372375
@Test
373376
public void testLongRunningResource() throws InterruptedException
374377
{
375-
final WebTarget resourceTarget = newTarget().path(ClientMain.ASYNC_LONG_RUNNING_OP_PATH);
378+
final WebTarget resourceTarget = newWebTarget().path(ClientMain.ASYNC_LONG_RUNNING_OP_PATH);
376379
final String expectedResponse = SimpleLongRunningResource.NOTIFICATION_RESPONSE;
377380

378381
final int MAX_MESSAGES = 100;

‎basicKnowledge/src/com/xdc/basic/api/restserver/jersey/application/exceptionmapper/common/RESTServiceException.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public Map<String, Object> getDetails()
108108
return details;
109109
}
110110

111+
/**
112+
* errorId与errorMessage字段为必备,可附加其他参数,目的是帮助客户端理解导致错误的原因,后续在恰当的时间能够重建请求。
113+
*/
111114
public RESTServiceException addDetail(String name, Object value)
112115
{
113116
details.put(name, value);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL