3

I need to create custom Handler to be included in WSO2 api manager (i use version 1.10.0). My custom handler depends on org.apache.http.impl.nio.client.CloseableHttpAsyncClient class from org.apache.httpcomponents.httpasyncclient-4.1 package. this dependency also include some third party library such as org.apache.httpcomponents.httpclient-4.4.1.

As per this instruction https://docs.wso2.com/display/AM1100/Writing+Custom+Handlers, the jar needed to be placed in /repository/components/lib. So i put my custom handler jar with all it's dependency jar files.

But when i restarted the wso2am, i got some class not found exception.

titlement.internal.SchemaBuilder}
TID: [-1234] [] [2016-04-25 17:14:28,659] FATAL {org.wso2.carbon.mediation.initializer.ServiceBusInitializer} -  Failed to initialize ESB due to a fatal error {org.wso2.carbon.mediation.initializer.ServiceBusInitializer}
java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader
       at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:642)
       at id.co.telkom.dds.oam.wso2am.handler.api.client.BillingAPIClient.<init>(BillingAPIClient.java:28)
       at id.co.telkom.dds.oam.wso2am.handler.BillingHandler.<init>(BillingHandler.java:26)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
       at java.lang.Class.newInstance(Class.java:442)
       at org.apache.synapse.config.xml.rest.APIFactory.defineHandler(APIFactory.java:130)
       at org.apache.synapse.config.xml.rest.APIFactory.createAPI(APIFactory.java:101)

is it because somehow the class is already included in WSO2 OSGI dependencies?

What is the recommended way of creating additional jar file that included several third party library so that it can be safely included in wso2 api manager without having version conflict problem. Should i created an OSGI bundles, included all the third library in the bundles so that only my custom handler class can see it?

rucciva
  • 157
  • 1
  • 1
  • 11

1 Answers1

2

is it because somehow the class is already included in WSO2 OSGI dependencies?

No, API Manager can't find the JAR in the runtime. You are getting java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader

You need to add all of your dependency JARs of that custom handler to <APIM_HOME>/repository/components/lib directory.

Additionally you can check in the following directory for existing JARs in the system

<APIM_HOME>/repository/components/plugins
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
  • Actually, i already included all my dependency jar to the folder. Thats why i'm getting confused. My though is that my third party library which my custom handler depnds on is a newer version of a third party librry that is already included in wso2, so that when wso2 sees my third part library, its ignored it, making a new class from my third party library not available. Is it possible for scenario like this to occur? – rucciva Apr 25 '16 at 12:31
  • Yes, this can be possible. – Abimaran Kugathasan Apr 25 '16 at 12:33
  • If this is the cause, then how should i solve it? I havent learn about osgi but will creating it as osgi help? – rucciva Apr 25 '16 at 13:49