[MGNLRESTCL-151] Refactor rest-client-module Created: 16/Mar/20  Updated: 19/May/20  Resolved: 14/Apr/20

Status: Closed
Project: REST Client
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.1

Type: Improvement Priority: Neutral
Reporter: Jorge Franco Assignee: Quach Hao Thien
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 11d 1h 10m
Original Estimate: Not Specified

Issue Links:
Cloners
is cloned by MGNLRESTUI-27 Update RestClient version Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:
Epic Link: Declarative REST clients
Sprint: 6.2.1 Ramp-up 21, 6.2.1 Ramp-up 22
Story Points: 8

 Description   

2020-03-13 16:27:56,865 TRACE class org.ehcache.core.Ehcache-REST_CLIENT_CACHE : Initializing
2020-03-13 16:27:56,866 DEBUG class org.ehcache.core.Ehcache-REST_CLIENT_CACHE : Initialize successful.
2020-03-13 16:29:20,378 WARN org.jboss.resteasy.resteasy_jaxrs.i18n : RESTEASY002160: Provider instance info.magnolia.rest.client.app.ui.debug.DebugFilter is already registered. 2nd registration is being ignored.
2020-03-13 16:37:48,575 WARN org.jboss.resteasy.client.jaxrs.i18n : RESTEASY004687: Closing a class org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine instance for you. Please close clients yourself.
2020-03-13 16:37:48,576 WARN org.jboss.resteasy.client.jaxrs.i18n : RESTEASY004687: Closing a class org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine instance for you. Please close clients yourself.

 

info.magnolia.rest.client.app.ui.debug.DebugFilter is already registered. 2nd registration is being ignored.

After discussed with dai.ha, this log entry could be ignored since it causes no harm.

 

Criteria:

  • Refactor RestClient, RestClientFactory:
    • Do not expose Client, WebTarget to user
    • Client should be closed after used via RestClient's api
    • All cached Client should be closed when module is stopped
    • Custom Filter could be register on demand via RestClient's api
  • Using RestClient:
    • Share RestClient should be cached and handled by RestClientProvider
    • RestClient which is not cached should be closed right after used
  • Register custom filter on demand
    • RestClient allows to register/unregister custom filter without expose jaxrs Client or WebTarget

 

 



 Comments   
Comment by Roman Kovařík [ 16/Apr/20 ]

Up until recently, my old rest client worked without a problem.

Now I get:

2020-04-16 11:00:00,067 ERROR info.magnolia.module.scheduler.CommandJob         : Cannot execute command {0}-{1}.
java.lang.NullPointerException: null
	at info.magnolia.rest.client.DefaultRestClient.buildWebTarget(DefaultRestClient.java:297) ~[magnolia-rest-client-2.0.1-SNAPSHOT.jar:?]
	at info.magnolia.rest.client.DefaultRestClient.buildWebTarget(DefaultRestClient.java:283) ~[magnolia-rest-client-2.0.1-SNAPSHOT.jar:?]
	at info.magnolia.rest.client.DefaultRestClient.proxy(DefaultRestClient.java:195) ~[magnolia-rest-client-2.0.1-SNAPSHOT.jar:?]
	at info.magnolia.resteasy.client.RestEasyClient.getClientService(RestEasyClient.java:65) ~[magnolia-rest-client-2.0.1-SNAPSHOT.jar:?] 

The deprecated ctor doesn't set the client field.

Could you also update the title to reflect the refactoring?

Comment by Quach Hao Thien [ 16/Apr/20 ]

rkovarik

since 2.0, I suggest to create RestClient via DefaultRestClientFactory

Comment by Roman Kovařík [ 16/Apr/20 ]

I can see
(RestEasyClient)restClientFactory.createClient(restClientRegistry.getProvider(...).get());
in my code.

Anyway it's not so much about my code, I could workaround it, but we shouldn't break the compatibility .

Comment by Quach Hao Thien [ 16/Apr/20 ]

To have a WebTarget, the jaxrs Client requires to open a connection and the deprecated ctor allows to pass that webtarget to create RestClient, which should be avoid, since we don't want the Client opens connection before the RestClient is actual created.

I understand that we should keep the compatibility, but in this case to control the webTarget keep the RestClient more messy. Do you think this is the perfect time to remove those deprecated ctors and methods?

WDYT? dai.ha jfranco jsimak

Generated at Mon Feb 12 10:43:41 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.