@@ -90,7 +90,7 @@ public AsyncHTTPPushRequest(HandleMsgContext handleMsgContext,
9090
9191 @ Override
9292 public void tryHTTPRequest () {
93- String localAddress = IPUtils . getLocalAddress ();
93+
9494 currPushUrl = getUrl ();
9595
9696 if (StringUtils .isBlank (currPushUrl )) {
@@ -100,31 +100,30 @@ public void tryHTTPRequest() {
100100 HttpPost builder = new HttpPost (currPushUrl );
101101
102102 String requestCode = "" ;
103-
104103 if (SubscriptionType .SYNC == handleMsgContext .getSubscriptionItem ().getType ()) {
105104 requestCode = String .valueOf (RequestCode .HTTP_PUSH_CLIENT_SYNC .getRequestCode ());
106105 } else {
107106 requestCode = String .valueOf (RequestCode .HTTP_PUSH_CLIENT_ASYNC .getRequestCode ());
108107 }
109-
108+ String localAddress = IPUtils . getLocalAddress ();
110109 builder .addHeader (ProtocolKey .REQUEST_CODE , requestCode );
111110 builder .addHeader (ProtocolKey .LANGUAGE , Constants .LANGUAGE_JAVA );
112111 builder .addHeader (ProtocolKey .VERSION , ProtocolVersion .V1 .getVersion ());
113112 builder .addHeader (ProtocolKey .EventMeshInstanceKey .EVENTMESHCLUSTER ,
114- handleMsgContext .getEventMeshHTTPServer ()
115- .getEventMeshHttpConfiguration ().getEventMeshCluster ());
113+ handleMsgContext .getEventMeshHTTPServer ()
114+ .getEventMeshHttpConfiguration ().getEventMeshCluster ());
116115 builder .addHeader (ProtocolKey .EventMeshInstanceKey .EVENTMESHIP , localAddress );
117116 builder .addHeader (ProtocolKey .EventMeshInstanceKey .EVENTMESHENV ,
118- handleMsgContext .getEventMeshHTTPServer ().getEventMeshHttpConfiguration ().getEventMeshEnv ());
117+ handleMsgContext .getEventMeshHTTPServer ().getEventMeshHttpConfiguration ().getEventMeshEnv ());
119118 builder .addHeader (ProtocolKey .EventMeshInstanceKey .EVENTMESHIDC ,
120- handleMsgContext .getEventMeshHTTPServer ().getEventMeshHttpConfiguration ().getEventMeshIDC ());
119+ handleMsgContext .getEventMeshHTTPServer ().getEventMeshHttpConfiguration ().getEventMeshIDC ());
121120
122121 CloudEvent event = CloudEventBuilder .from (handleMsgContext .getEvent ())
123- .withExtension (EventMeshConstants .REQ_EVENTMESH2C_TIMESTAMP ,
124- String .valueOf (System .currentTimeMillis ()))
125- .withExtension (EventMeshConstants .RSP_URL , currPushUrl )
126- .withExtension (EventMeshConstants .RSP_GROUP , handleMsgContext .getConsumerGroup ())
127- .build ();
122+ .withExtension (EventMeshConstants .REQ_EVENTMESH2C_TIMESTAMP ,
123+ String .valueOf (System .currentTimeMillis ()))
124+ .withExtension (EventMeshConstants .RSP_URL , currPushUrl )
125+ .withExtension (EventMeshConstants .RSP_GROUP , handleMsgContext .getConsumerGroup ())
126+ .build ();
128127 handleMsgContext .setEvent (event );
129128
130129 String content = "" ;
@@ -134,7 +133,7 @@ public void tryHTTPRequest() {
134133 ProtocolAdaptor <ProtocolTransportObject > protocolAdaptor = ProtocolPluginFactory .getProtocolAdaptor (protocolType );
135134
136135 ProtocolTransportObject protocolTransportObject =
137- protocolAdaptor .fromCloudEvent (handleMsgContext .getEvent ());
136+ protocolAdaptor .fromCloudEvent (handleMsgContext .getEvent ());
138137 if (protocolTransportObject instanceof HttpCommand ) {
139138 content = ((HttpCommand ) protocolTransportObject ).getBody ().toMap ().get ("content" ).toString ();
140139 } else {
@@ -158,37 +157,37 @@ public void tryHTTPRequest() {
158157 body .add (new BasicNameValuePair (PushMessageRequestBody .CONTENT , content ));
159158 if (StringUtils .isBlank (handleMsgContext .getBizSeqNo ())) {
160159 body .add (new BasicNameValuePair (PushMessageRequestBody .BIZSEQNO ,
161- RandomStringUtils .generateNum (20 )));
160+ RandomStringUtils .generateNum (20 )));
162161 } else {
163162 body .add (new BasicNameValuePair (PushMessageRequestBody .BIZSEQNO ,
164- handleMsgContext .getBizSeqNo ()));
163+ handleMsgContext .getBizSeqNo ()));
165164 }
166165 if (StringUtils .isBlank (handleMsgContext .getUniqueId ())) {
167166 body .add (new BasicNameValuePair (PushMessageRequestBody .UNIQUEID ,
168- RandomStringUtils .generateNum (20 )));
167+ RandomStringUtils .generateNum (20 )));
169168 } else {
170169 body .add (new BasicNameValuePair (PushMessageRequestBody .UNIQUEID ,
171- handleMsgContext .getUniqueId ()));
170+ handleMsgContext .getUniqueId ()));
172171 }
173172
174173 body .add (new BasicNameValuePair (PushMessageRequestBody .RANDOMNO ,
175- handleMsgContext .getMsgRandomNo ()));
174+ handleMsgContext .getMsgRandomNo ()));
176175 body .add (new BasicNameValuePair (PushMessageRequestBody .TOPIC , handleMsgContext .getTopic ()));
177176
178177 body .add (new BasicNameValuePair (PushMessageRequestBody .EXTFIELDS ,
179- JsonUtils .serialize (EventMeshUtil .getEventProp (handleMsgContext .getEvent ()))));
178+ JsonUtils .serialize (EventMeshUtil .getEventProp (handleMsgContext .getEvent ()))));
180179
181180 HttpEntity httpEntity = new UrlEncodedFormEntity (body , StandardCharsets .UTF_8 );
182181
183182 builder .setEntity (httpEntity );
184183
185184 // for CloudEvents Webhook spec
186185 String urlAuthType = handleMsgContext .getConsumerGroupConfig ().getConsumerGroupTopicConf ()
187- .get (handleMsgContext .getTopic ()).getHttpAuthTypeMap ().get (currPushUrl );
186+ .get (handleMsgContext .getTopic ()).getHttpAuthTypeMap ().get (currPushUrl );
188187
189188 WebhookUtil .setWebhookHeaders (builder , httpEntity .getContentType ().getValue (),
190- eventMeshHttpConfiguration .getEventMeshWebhookOrigin (),
191- urlAuthType );
189+ eventMeshHttpConfiguration .getEventMeshWebhookOrigin (),
190+ urlAuthType );
192191
193192
194193 eventMeshHTTPServer .metrics .getSummaryMetrics ().recordPushMsg ();
@@ -199,7 +198,7 @@ public void tryHTTPRequest() {
199198
200199 if (CMD_LOGGER .isInfoEnabled ()) {
201200 CMD_LOGGER .info ("cmd={}|eventMesh2client|from={}|to={}" , requestCode ,
202- localAddress , currPushUrl );
201+ localAddress , currPushUrl );
203202 }
204203
205204 try {
@@ -215,18 +214,18 @@ public Object handleResponse(HttpResponse response) {
215214 String res = "" ;
216215 try {
217216 res = EntityUtils .toString (response .getEntity (),
218- Charset .forName (EventMeshConstants .DEFAULT_CHARSET ));
217+ Charset .forName (EventMeshConstants .DEFAULT_CHARSET ));
219218 } catch (IOException e ) {
220219 handleMsgContext .finish ();
221220 return new Object ();
222221 }
223222 ClientRetCode result = processResponseContent (res );
224223 if (MESSAGE_LOGGER .isInfoEnabled ()) {
225224 MESSAGE_LOGGER .info (
226- "message|eventMesh2client|{}|url={}|topic={}|bizSeqNo={}"
227- + "|uniqueId={}|cost={}" ,
228- result , currPushUrl , handleMsgContext .getTopic (),
229- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), cost );
225+ "message|eventMesh2client|{}|url={}|topic={}|bizSeqNo={}"
226+ + "|uniqueId={}|cost={}" ,
227+ result , currPushUrl , handleMsgContext .getTopic (),
228+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), cost );
230229 }
231230 if (result == ClientRetCode .OK || result == ClientRetCode .REMOTE_OK ) {
232231 complete ();
@@ -253,9 +252,9 @@ public Object handleResponse(HttpResponse response) {
253252 eventMeshHTTPServer .metrics .getSummaryMetrics ().recordHttpPushMsgFailed ();
254253 if (MESSAGE_LOGGER .isInfoEnabled ()) {
255254 MESSAGE_LOGGER .info (
256- "message|eventMesh2client|exception|url={}|topic={}|bizSeqNo={}"
257- + "|uniqueId={}|cost={}" , currPushUrl , handleMsgContext .getTopic (),
258- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), cost );
255+ "message|eventMesh2client|exception|url={}|topic={}|bizSeqNo={}"
256+ + "|uniqueId={}|cost={}" , currPushUrl , handleMsgContext .getTopic (),
257+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), cost );
259258 }
260259
261260 if (isComplete ()) {
@@ -268,14 +267,14 @@ public Object handleResponse(HttpResponse response) {
268267
269268 if (MESSAGE_LOGGER .isDebugEnabled ()) {
270269 MESSAGE_LOGGER .debug ("message|eventMesh2client|url={}|topic={}|event={}" , currPushUrl ,
271- handleMsgContext .getTopic (),
272- handleMsgContext .getEvent ());
270+ handleMsgContext .getTopic (),
271+ handleMsgContext .getEvent ());
273272 } else {
274273 if (MESSAGE_LOGGER .isInfoEnabled ()) {
275274 MESSAGE_LOGGER
276- .info ("message|eventMesh2client|url={}|topic={}|bizSeqNo={}|uniqueId={}" ,
277- currPushUrl , handleMsgContext .getTopic (),
278- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId ());
275+ .info ("message|eventMesh2client|url={}|topic={}|bizSeqNo={}|uniqueId={}" ,
276+ currPushUrl , handleMsgContext .getTopic (),
277+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId ());
279278 }
280279 }
281280 } catch (IOException e ) {
@@ -292,22 +291,22 @@ public Object handleResponse(HttpResponse response) {
292291 public String toString () {
293292 StringBuilder sb = new StringBuilder ();
294293 sb .append ("asyncPushRequest={" )
295- .append ("bizSeqNo=" ).append (handleMsgContext .getBizSeqNo ())
296- .append (",startIdx=" ).append (startIdx )
297- .append (",retryTimes=" ).append (retryTimes )
298- .append (",uniqueId=" ).append (handleMsgContext .getUniqueId ())
299- .append (",executeTime=" )
300- .append (DateFormatUtils .format (executeTime , Constants .DATE_FORMAT ))
301- .append (",lastPushTime=" )
302- .append (DateFormatUtils .format (lastPushTime , Constants .DATE_FORMAT ))
303- .append (",createTime=" )
304- .append (DateFormatUtils .format (createTime , Constants .DATE_FORMAT )).append ("}" );
294+ .append ("bizSeqNo=" ).append (handleMsgContext .getBizSeqNo ())
295+ .append (",startIdx=" ).append (startIdx )
296+ .append (",retryTimes=" ).append (retryTimes )
297+ .append (",uniqueId=" ).append (handleMsgContext .getUniqueId ())
298+ .append (",executeTime=" )
299+ .append (DateFormatUtils .format (executeTime , Constants .DATE_FORMAT ))
300+ .append (",lastPushTime=" )
301+ .append (DateFormatUtils .format (lastPushTime , Constants .DATE_FORMAT ))
302+ .append (",createTime=" )
303+ .append (DateFormatUtils .format (createTime , Constants .DATE_FORMAT )).append ("}" );
305304 return sb .toString ();
306305 }
307306
308307 boolean processResponseStatus (int httpStatus , HttpResponse httpResponse ) {
309308 if (httpStatus == HttpStatus .SC_OK || httpStatus == HttpStatus .SC_CREATED
310- || httpStatus == HttpStatus .SC_NO_CONTENT || httpStatus == HttpStatus .SC_ACCEPTED ) {
309+ || httpStatus == HttpStatus .SC_NO_CONTENT || httpStatus == HttpStatus .SC_ACCEPTED ) {
311310 // success http response
312311 return true ;
313312 } else if (httpStatus == 429 ) {
@@ -337,8 +336,8 @@ ClientRetCode processResponseContent(String content) {
337336
338337 try {
339338 Map <String , Object > ret =
340- JsonUtils .deserialize (content , new TypeReference <Map <String , Object >>() {
341- });
339+ JsonUtils .deserialize (content , new TypeReference <Map <String , Object >>() {
340+ });
342341 Integer retCode = (Integer ) ret .get ("retCode" );
343342 if (retCode != null && ClientRetCode .contains (retCode )) {
344343 return ClientRetCode .get (retCode );
@@ -348,19 +347,19 @@ ClientRetCode processResponseContent(String content) {
348347 } catch (NumberFormatException e ) {
349348 if (MESSAGE_LOGGER .isWarnEnabled ()) {
350349 MESSAGE_LOGGER .warn ("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}" , currPushUrl ,
351- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
350+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
352351 }
353352 return ClientRetCode .FAIL ;
354353 } catch (JsonException e ) {
355354 if (MESSAGE_LOGGER .isWarnEnabled ()) {
356355 MESSAGE_LOGGER .warn ("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}" , currPushUrl ,
357- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
356+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
358357 }
359358 return ClientRetCode .FAIL ;
360359 } catch (Throwable t ) {
361360 if (MESSAGE_LOGGER .isWarnEnabled ()) {
362361 MESSAGE_LOGGER .warn ("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}" , currPushUrl ,
363- handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
362+ handleMsgContext .getBizSeqNo (), handleMsgContext .getUniqueId (), content );
364363 }
365364 return ClientRetCode .FAIL ;
366365 }
@@ -372,7 +371,7 @@ private void addToWaitingMap(AsyncHTTPPushRequest request) {
372371 return ;
373372 }
374373 waitingRequests
375- .put (request .handleMsgContext .getConsumerGroup (), Sets .newConcurrentHashSet ());
374+ .put (request .handleMsgContext .getConsumerGroup (), Sets .newConcurrentHashSet ());
376375 waitingRequests .get (request .handleMsgContext .getConsumerGroup ()).add (request );
377376 }
378377
0 commit comments