Getting NoSuchMethodError in Kafka Consumer v0.10.0.1 - websphere-liberty

I am trying to move to KafkaClient 0.10.0.1 from 0.9.0.0. The code is working fine in production with 0.9.0.0. Now the same code in development platform throwing exception when a consumer is started with following exception
javax.servlet.ServletException: java.lang.NoSuchMethodError: org/apache/kafka/clients/consumer/KafkaConsumer.subscribe(Ljava/util/List;)V (loaded from file:/home/vcap/app/wlp/usr/shared/config/lib/global/kafka-clients-0.10.0.1.jar by com.ibm.ws.classloading.internal.AppClassLoader#7a0d5027) called from class com.ibm.b2b.msghub.helper.AbstractB2BConsumer (loaded from file:/home/vcap/app/wlp/usr/shared/config/lib/global/B2BBlueMixLib-1.0.jar by com.ibm.ws.classloading.internal.AppClassLoader#7a0d5027).
Madhu

The client API has slightly changed between Kafka 0.9 and 0.10.
The definition of KafkaConsumer.subscribe() has changed. The first argument is now of type Collection instead of List.
This was done to make the API more consistent as now most (all?) calls take a Collection object whereas before it was a mix of several types.

Related

Undeclared Throwable Exception when using Spring Boot AOP controller advice with join points matching jpa repository functions

Problem:
Spring boot service using MVCS architecture. I am using Spring AOP advice (around advice) for all functions present in any class in repository directory. So for example when jpa save method is called, the around advice is triggered.
Now, Here is how things get called when no exception occurs.
CONTROLLER -> SERVICE LAYER -> call to repository layer function triggers advice function which allows join point to proceed -> REPOSITORY LAYER -> around advice -> and everything executes fine.
Now, Here is the flow when exception is thrown by the controller advice function.
CONTROLLER -> SERVICE LAYER -> call to repository layer function triggers advice function which allows join point to proceed -> REPOSITORY LAYER -> some DB exception occurs (for example trying to set a database attribute with NON NULL constraint to NULL) -> back to controller advice, it catches the exception then throws a custom checked exception to service layer and than going through service layer and then controller where the exception is handled.
The problem is that service layer doesn't know about controller advice (it acts like a proxy) and thinks that repository layer won't throw any exception since it doesn't declare throws in its methods signature (for example the default save method).
So the exception that reaches the controller is not the one which is thrown by the controller advice functions. In fact Java wraps that exception inside UndeclaredThrowableException.
One way to deal with this situation is to check ex.getCause() and get the exception which java wrapped in UndeclaredThrowableException.
Another is to declare throws in the repository methods signature so that the service layers can know about the repository function throwing exception. (But this is not possible for default implementation provided by jpa - like the save function - atleast not without overriding the save function) and this I don't want to do because there are a lot of jpa inbuilt functions to override.
Any elegant solution/suggestion to the problem ?
You cannot magically violate JVM restrictions about throwing undeclared checked exceptions. Therefore, you will have to
throw a checked exception which has actually been declared in the intercepted target method, or
throw a runtime exception instead, optionally wrapping it around the checked exception you want to throw.
Sorry, I cannot change the JVM for you. You need to play by its rules.

Lumen Reportable & Renderable Exception doesn't work

I am trying to define a custom renderable exception exactly as shown in the documentation example but when I throw my custom exception, the render and report functions inside the exception class are totally ignored.
I am aware that I can handle my custom exceptions inside the exception handler but this is something I would prefer to do inside the exception class.
Is it something more that I should do to register the exception in order for the render and report functions to be called? What am I missing?
Thank you!
EDIT: I'm using Lumen 5.7.
Turns out that this feature is not available in Lumen framework, only in Laravel. Lumen's documentation is very misleading as it lets one to imagine that the features concerning errors are common in Laravel and Lumen.
In any case, currently in Lumen only exception handling inside the exception handler is available.
Looks like it feature will be added in one of next 5.8.* releases.
PR: https://github.com/laravel/lumen-framework/pull/958

Jersey Exception Java 1.8

I am calling a REST service and the provider has supplied a client. Client's specification is to use Jersey 2.18. So i have used the below jersey dependencies
Jersey-client-2.18.jar
Jersey-common-2.18.jar
Jersey-entity-filtering-2.18.jar
Jersey-guava-2.18.jar
jersey-media-json-jackson-2.18.jar
I am making calls using scheduledThreadPoolExecutor and my application is running in tc server and JDK 1.8. Sporadically i get the below exception. I tried searching this exception in google but no luck. But i see the below for almost everytime
Cannot create new registration for component type class > org.glassfish.jersey.client.authentication.HttpAuthenticationFeature
Exception
java.lang.NullPointerException at
org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:694)
at
org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at
org.glassfish.jersey.client.ClientConfig$State.configureMetaProviders(ClientConfig.java:365)
at
org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:398)
at
org.glassfish.jersey.client.ClientConfig$State.access$000(ClientConfig.java:88)
at
org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:120)
at
org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:117)
at
org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:340)
at
org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:726)
at
org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285)
at
org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:126)
at
org.glassfish.jersey.client.JerseyInvocation.(JerseyInvocation.java:98)
at
org.glassfish.jersey.client.JerseyInvocation.(JerseyInvocation.java:91)
at
org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:411)
at
org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:307)
I resolved this issue. My implementation was wrong. The client object was defined as a class level variable and it was initialized during every method call. During parallel call. every thread concurrent call attacks the same class level object and tries to modify and hence the object was not properly initialized. Now i fixed it by injecting the class from spring so that it is not modified during every call.

Spring on WebSphere 8: Quartz job with web service call throws JAXBException "<class> is not known to this context"

I'm facing a JAXBException " is not known to this context" when calling a web service from within a job controlled by Quartz on Spring:
javax.xml.ws.WebServiceException: javax.xml.bind.JAXBException: com.xxxx.yyyy.zzzz.ImageMetaData is not known to this context
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMinimalMethodMarshaller.demarshalResponse(DocLitWrappedMinimalMethodMarshaller.java:624)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:593)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:432)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:213)
at com.sun.proxy.$Proxy299.findAllImageMetaData(Unknown Source)
I'm having a Spring 3.2.4 Java EE application with JSF running on IBM WebSphere v8.
When calling a specific web service from the JSF part of the application (i.e. from an action or a service), everything's ok.
The exception occurs only when the call is done from within a Quartz/Spring triggered job.
Executing exacty the same job code from the action does not result in an exception.
I tried a lot of different things like using a corresponding #XmlSeeAlso annotation in the JAXB generated classes but even using the annotation in the webservice interface itself does not solve the issue.
I also updated the Spring and Quartz libraries to more recent versions but this didn't help.
Anyone any idea?
I've finally solved the issue.
After much analysis I encountered the following issue in the Spring framework:
https://jira.spring.io/i#browse/SPR-11125
When a job is triggered via Spring/Quartz on WebSphere, the wrong ContextClassLoader is set.
This may cause many different problems - among them is the JAXBException as described.
The Spring bug is still open - so as a workaround I had to overwrite the context class loader of the current thread by the correct one:
ClassLoader cl = invoiceService.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
The correct class loader can be simply retrieved by a class that has been loaded by the container. Using this class loader as the context class loader for the current thread solved my issue.

java.lang.IllegalStateException: getWriter() has already been called for this response

I am doing training about CXF and Spring, so I wrote a very simple CXF demo which only has the interface "HelloWorld" and its implementor "HelloWorldWs".
I want to publish it with Tomcat. I wrote a web.xml and applicationContext.xml(Spring profile. Though i can publish the WSDL .But the console list a problem:
Servlet.service() for servlet [CXFServlet] in context with path [/cxf_spring] threw exception java.lang.IllegalStateException: getWriter() has already been called for this response
I did not use or write any io function, just a "sayhi" function. I am stumped.
This is actually a bug and is fixed as part of https://issues.apache.org/jira/browse/CXF-5620,
CXF 2.7.11 (released)

Resources