Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[management] WebhookNotifier doesn't support multiple languages #2727

Closed
humblemh opened this issue Oct 8, 2019 · 7 comments
Assignees
Milestone

Comments

@humblemh
Copy link

@humblemh humblemh commented Oct 8, 2019

Expected Behavior

WebhookNotifier sends json file with multiple languages in user information to specified URL

Current Behavior

If the user information contains multiple languages, json parsing fails because the contents are missing.

fail case:
{"event":"SUBSCRIPTION_ACCEPTED","scope":"API","api":{"id":"dbc3186b-ec75-4710-8318-6bec757710cb","name":"Transcription API","version":"1.0"},"application":{"id":"22683e3a-3287-4590-a83e-3a3287859042","name":"Default application"},"owner":{"id":"25d85863-2e80-4204-9858-632e8062046a","username":"진환 김"},"plan":{"id":"af6dd540-a78a-493e-add5-40a78a093eaf","name":"DEMO","security":"API_KEY"},"subscription":{"id":"8c677380-f641-4556-a773-80f641f55641","status":"ACCEP

success case:
{"event":"SUBSCRIPTION_ACCEPTED","scope":"API","api":{"id":"dbc3186b-ec75-4710-8318-6bec757710cb","name":"Transcription API","version":"1.0"},"application":{"id":"4584a967-e450-458c-84a9-67e450558c63","name":"Default application"},"owner":{"id":"d26d96ab-66a6-4cbe-ad96-ab66a67cbe2d","username":"Jinhwan Kim"},"plan":{"id":"af6dd540-a78a-493e-add5-40a78a093eaf","name":"DEMO","security":"API_KEY"},"subscription":{"id":"70410579-8542-4070-8105-798542a07089","status":"ACCEPTED"}}

Possible Solution

Do not use multilanguage for user information.

Steps to Reproduce (for bugs)

  1. User registration with multilanguage. ex: username : 홍길동
  2. Webhook notifiers registration in any api.
  3. User subscribe that api.

Context

I have a user who has registered a user name in multiple languages. The API that the user uses is registered with a webhook notifier.

Your Environment

  • Version used: 1.28.1
  • Browser Name and version: chrome 77.0.3865.90
  • Operating System and version: Centos 7.5
@brasseld

This comment has been minimized.

Copy link
Member

@brasseld brasseld commented Oct 8, 2019

Hi @humblemh

Do you have a stack trace for this ?
Or parsing is failing from the browser ?

@humblemh

This comment has been minimized.

Copy link
Author

@humblemh humblemh commented Oct 8, 2019

Hi @brasseld
this is the my server log who receive webhook request from management api server.
the post request is just printed.

@brasseld

This comment has been minimized.

Copy link
Member

@brasseld brasseld commented Oct 8, 2019

Where is the server log?

@humblemh

This comment has been minimized.

Copy link
Author

@humblemh humblemh commented Oct 8, 2019

this is my server code. thanks!

router.post("/subscribe").blockingHandler(routingContext -> {
	    
	    // from webhook notification
	    // {"event":"SUBSCRIPTION_ACCEPTED","scope":"API","api":{"id":"240a6065-9290-4661-8a60-659290b661dc","name":"Transcription
	    // API"
	    // ,"version":"1.0"},"application":{"id":"324877f6-0ebd-40cb-8877-f60ebd80cba6","name":"Default
	    // application"}
	    // ,"owner":{"id":"b6236890-b5ae-4a7d-a368-90b5ae6a7da1","username":"minho
	    // Kang"},
	    // "plan":{"id":"37b103fb-7c8b-415b-b103-fb7c8b115b4a","name":"Demo","security":"API_KEY"},
	    // "subscription":{"id":"3701fd59-c659-416a-81fd-59c659d16a43","status":"ACCEPTED"}}

	    JsonObject subscriptionJO = null;

	    try {

		subscriptionJO = routingContext.getBodyAsJson();
		String userID = subscriptionJO.getJsonObject("subscription").getString("id");

		String planName = subscriptionJO.getJsonObject("plan").getString("name");

		........
		
		logger.info("[CONN][SUBSCRIPTION][OK]" + subscriptionJO.encode());
		routingContext.response().end();

		// TODO mongo에 기록
	    } catch (Exception e) {
		logger.warn("[CONN][SUBSCRIPTION][FAIL]" + routingContext.getBodyAsString(), e);
		routingContext.response().setStatusCode(400).end();
	    }

	}, false);

2019-10-08 19:22:41,500 [vert.x-worker-thread-0] WARN billing.MainVerticle - [CONN][SUBSCRIPTION][FAIL]{"event":"SUBSCRIPTION_ACCEPTED","scope":"API","api":{"id":"dbc3186b-ec75-4710-8318-6bec757710cb","name":"Transcription API","version":"1.0"},"application":{"id":"22683e3a-3287-4590-a83e-3a3287859042","name":"Default application"},"owner":{"id":"25d85863-2e80-4204-9858-632e8062046a","username":"진환 김"},"plan":{"id":"af6dd540-a78a-493e-add5-40a78a093eaf","name":"DEMO","security":"API_KEY"},"subscription":{"id":"8c677380-f641-4556-a773-80f641f55641","status":"ACCEP
io.vertx.core.json.DecodeException: Failed to decode:Unexpected end-of-input in VALUE_STRING
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 945]
at io.vertx.core.json.Json.decodeValue(Json.java:222)
at io.vertx.core.json.JsonObject.fromBuffer(JsonObject.java:960)
at io.vertx.core.json.JsonObject.(JsonObject.java:73)
at io.vertx.ext.web.impl.RoutingContextImpl.getBodyAsJson(RoutingContextImpl.java:275)
at io.vertx.ext.web.impl.RoutingContextDecorator.getBodyAsJson(RoutingContextDecorator.java:128)
at billing.MainVerticle.lambda$doRESTAPI$2(MainVerticle.java:184)
at io.vertx.ext.web.impl.BlockingHandlerDecorator.lambda$handle$0(BlockingHandlerDecorator.java:48)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input in VALUE_STRING
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 945]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:618)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:595)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._loadMoreGuaranteed(UTF8StreamJsonParser.java:2348)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:2433)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishAndReturnString(UTF8StreamJsonParser.java:2413)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.getText(UTF8StreamJsonParser.java:269)
at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:672)
at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:880)
at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:654)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:527)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:364)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
at io.vertx.core.json.Json.decodeValue(Json.java:220)

@brasseld

This comment has been minimized.

Copy link
Member

@brasseld brasseld commented Oct 8, 2019

So it means that the issue is coming from billing.MainVerticle and not gravitee itself, am I wrong?

@humblemh humblemh closed this Oct 8, 2019
@humblemh

This comment has been minimized.

Copy link
Author

@humblemh humblemh commented Oct 8, 2019

I found the bug in io.gravitee.management.service.impl.HttpClientServiceImpl.
HTTP header Content-Length is byte length, not character length.
multiple languages character is multi bytes.

public class HttpClientServiceImpl extends AbstractService implements HttpClientService {
....
request.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length()));
.......
}

fixed:
request.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.getBytes().length));

@humblemh humblemh reopened this Oct 8, 2019
@brasseld

This comment has been minimized.

Copy link
Member

@brasseld brasseld commented Oct 9, 2019

Well done @humblemh

Can you provide a pull Request for this ?

@brasseld brasseld changed the title WebhookNotifier doesn't support multiple languages [management] WebhookNotifier doesn't support multiple languages Oct 29, 2019
@brasseld brasseld self-assigned this Oct 29, 2019
@brasseld brasseld added this to the APIM - 1.25.x milestone Oct 29, 2019
brasseld added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Oct 29, 2019
NicolasGeraud added a commit to gravitee-io/gravitee-management-rest-api that referenced this issue Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
API Management
Awaiting triage
3 participants
You can’t perform that action at this time.