How do you disable trusted.packages check for Spring-Kafka JsonDeserializer? - java

I have legacy Spring-Scala project. I have added new event type to one of the topics and now consumers throw exceptions
Caused by: java.lang.IllegalArgumentException: The class '...' is not in the trusted packages: [java.util, java.lang, ...].
It seems that a few classes are always added by Spring. I want to disable this feature but it seems that list of classes must be empty for the code to ignore it. But I don't see how that list would ever be empty if some java packages are added by Spring itself. Any suggestions?

I got this. There is a method called .addTrustedPackages and it handles "*" argument as one that clears the internal trustedPackages list. Neat design... >.<
So the following code works
val deserializer = new JsonDeserializer[...]()
deserializer.addTrustedPackages("*")

Related

Need to understand broadleaf commerce custom annotation implementation

I have been trying go through code of Broadleaf Commerce. There were multiple Custom Annotations used however I was not able to locate there Processor. Can anyone help me here. To take example #AdminPresentation it a custom annotation in package org.broadleafcommerce.common.presentation;
However how this is processed throughout the app, I was not able to locate. What I have understood till now we can use Reflection or AOP for its processing. But There was nothing for this.
Please help.
Source code - https://github.com/BroadleafCommerce/BroadleafCommerce
For a short answer, org.broadleafcommerce.openadmin.server.dao.provider.metadata.BasicFieldMetadataProvider#addMetadata is one place that processes those annotations.
On a broader level, the controllers in the openadmin will use the AdminEntityService to get ClassMetaData (all data about how a class should be displayed to an admin user). The #AdminPresentation annotation is one source of this data. The method AdminEntityServiceImpl#getClassMetadata is the main gateway for getting the ClassMetaData.
#getClassMetadata calls #inspect and eventually gets to PersistenceManager#inspect. This method uses the DynamicEntityDao to eventually get to Metadata#getFieldMetadataForTargetClass. That method gets each field of a class via reflection, and then each of those Fields is processed through the available FieldMetadataProviders. The FieldMetadataProviders turn a java.lang.reflect.Field into org.broadleafcommerce.openadmin.dto.FieldMetadata.
Any provided FieldMetadataProvider can contribute field metadata. This metadata is used in the FormBuilderService to construct the admin page.
Class References:
AdminEntityService - org.broadleafcommerce.openadmin.server.service.AdminEntityServiceImpl
PersistenceManager - org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManagerImpl#inspect
DynamicEntityDao - org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl#getPropertiesForEntityClass
Metadata - org.broadleafcommerce.openadmin.server.dao.Metadata#getFieldMetadataForTargetClass
FieldMetadataProvider - org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl#fieldMetadataProviders
FormBuilderService - org.broadleafcommerce.openadmin.web.service.FormBuilderServiceImpl
Have a look to :
https://www.baeldung.com/java-custom-annotation
You will get explanations about : "default" in the Custom Annotations.
Florent COUDERT.

Overriding/Wrapping spring beans in java based config multiple times

I have a (web-)application that needs special configurations and/or extensions based on the customer using the application. I call these additions "plugins" and they are auto discovered by classpath scanning when the application starts. For extensions that is incredibly easy. Let's say I want to have a plugin which adds an API that prints "hello world" when the URL /myplugin/greet is called: I just create a #Controller annotated class with the according #RequestMapping, put this in a myplugin.jar, copy that on the classpath and that's it.
Problems come up when I want to change some defaults and especially if I want to do this multiple times. Let's say my core application has a config like this:
#Configuration
public class CoreConfiguration {
#Bean
public Set<String> availableModules() {
return Collections.singleton("core");
}
}
Now I have two plugins that don't know about each other (but they do know the CoreConfig), but they both want to add themselves to the list of available modules. How would I do that? If I only had a single plugin that wants to override the module list I could override the existing bean from CoreConfiguration, but with two plugins that becomes a problem. What I imagine is something like this:
#Configuration
public class FirstPluginConfiguration {
#Bean
public Set<String> availableModules(Set<String> availableModules) {
Set<String> extendedSet = new HashSet<>(availableModules);
extendedSet.add("FirstPlugin");
return extendedSet;
}
}
Of course a SecondPluginConfiguration would look nearly exactly like this, except that the Set is not extended by "FirstPlugin", but by "SecondPlugin". I tested it to check what would happen and spring will just never call the First/SecondPluginConfiguration "availableModules" methods but it does not show an error either.
Now of course in this case this could easily be solved by using a mutable Set in the CoreConfiguration and then autowiring and extending the set in the other configurations, but for example I also want to be able to add method interceptors to some beans. So for example I might have an interface CrashLogger which has a logCrash(Throwable t) method and in CoreConfiguration a ToFileCrashLogger is created that writes stack traces to files as the name suggests. Now a plugin could say that he also wants to get notified about crashes, for example the plugin wants to ADDITIONALLY send the stacktrace to someone by email. For that matter that plugin could wrap the CrashLogger configured by the CoreConfiguration and fire BOTH. A second plugin could wrap the wrapper again and do something totally different with the stacktrace and still call both of the other CrashLoggers.
The later does sound somewhat like AOP and if I'd just let ALL my beans be proxied (I did not test that) I could autowire them into my plugin configurations, cast them to org.springframework.aop.framework.Advised and then add advices that manipulate behaviour. However it does seem like a huge overkill to generate proxies for each and everyone of my beans just so that that plugin can potentially add one or two advices one one or two beans.

IllegalArgumentException when using SpinnerItem in SmartGWT

I am trying to use a SpinnerItem as the editor type for a ListGridField
final ListGridField quantityGridField = new ListGridField("quantity", "Cantidad");
quantityGridField.setEditorType(SpinnerItem.class);
quantityGridField.setCanEdit(true);
But after I compile the project and deploy it this error comes up.
java.lang.IllegalArgumentException: No BeanFactory has been registered for: com.smartgwt.client.widgets.form.fields.SpinnerItem
This is the first time that I get this error and I have not found any related question here.
As it's described in javadoc to the method that you use (setEditorType(class)) you use Reflection mechanism of smartgwt. You can read about it here: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Reflection.html .
According to this documentation you should register SpinnerItem(which is a subclass of FormItem) prior of using it:
Similarly, to register FormItem and all its subclasses found in the
classpath (including your custom subclasses), you can use the
BeanFactory.FormItemMetaFactory.
GWT.create(BeanFactory.FormItemMetaFactory.class);
So just try to insert this GWT.create line somewhere in your code before using it, so gwt compiler will be able to find your editor.

Getting empty sequence for the complex type in generated XSD when developing JAX-WS web services

I seem to be having an issue with Java and NetBeans when it comes to writing web services.
I have searched for a couple of days with no luck, finding people with the same issue as me with zero replies.
I have created a web service which returns a complex type (LoginReply), and that complex type contains an array of another complex type (AppInfo)
However when I generate the WSDL from this, the complex type definition in the XSD is blank, and manually adding the information still makes the web service return null even when data is successfully passed to the web service.
<xs:complexType name="appInfo">
<xs:sequence/>
</xs:complexType>
LoginReply: http://pastebin.com/Umx6ayvi
AppInfo: http://pastebin.com/566WnZ4H
If anyone could point out what I'm doing wrong, or if this is a bug with NetBeans, I'm new to Java so I can't rule out that I'm simply not understanding something, but I'm close to pulling my hair out here.
EDIT:
Just noticed when i deploy to tomcat via NetBeans I get the following error:
WARNING: duplicate class definition bug occured? Please report this : uk/co/example/ComplexTypes/LoginReply$JaxbAccessorM_getApplications_setApplications_[Luk_co_example_ComplexTypes_AppInfo;
java.lang.ClassFormatError: Illegal class name "uk/co/example/ComplexTypes/LoginReply$JaxbAccessorM_getApplications_setApplications_[Luk_co_example_ComplexTypes_AppInfo;" in class file uk/co/example/ComplexTypes/LoginReply$JaxbAccessorM_getApplications_setApplications_[Luk_co_example_ComplexTypes_AppInfo;
Notice the random L before co_uk_example. My research suggests this is an old bug that should be fixed, and that no one else has reported this issue in over a year, no sure where to go from here.
Another edit:
Just added a new web method on the service that simply gets a list of appInfo and returns it to the client. This still fails the same way with NetBeans refusing to generate a sequence inside AppInfo.
I'm sure I'm missing something to declare the class, but I have checked it countless times to ensure I'm not missing anything.
warning gives you good hint: "WARNING: duplicate class definition bug occured"
your ws implementation class directly uses LoginReply class which directly uses AppInfo (+you are maybe also directly using this class in your ws implementation) => jaxb finds it
#XMLSeeAlso(...) tells jaxb to "link" referenced class
=> two definitions of the same class (not sure if it is by design or a bug that jaxb is not able to handle this case more gracefully)
to fix this just remove #XmlSeeAlso from your LoginReply class and you should be fine
This Issue came down to a very simple mistake. The AppInfo class was using non-standard getters and setters.
public void SetAppID(int AppID)
{
this.AppID = AppID;
}
This is INCORRECT (notice the capital on the Set), it should be:
public void setAppID(int AppID)
{
this.AppID = AppID;
}
Using a capital is not standard for JavaBeans and as such JAX-WS didn't know how to generate WSDL for this class. Thanks too shyam from the following link for answering the question
How to return a custom complex type in JAX-WS web services?
I don't think you can send "complex types" over the net (programmed port types) in http protocol, however an array may be implicitly converted to a delimited string set , check the docs for data transfer.

ApplicationError when trying to implement an edited version of the Secure module

I'm implementing an edited version of the Secure controller, default in the latest Play Framework.
I have read several times that, if you want to customize the Secure behaviour, you're better off copying the source of the Secure module, and start customizing it.
So I did, and after editing the needed dependencies I received following error:
Execution exception
NullPointerException occured : null
In /app/controllers/SecureController.java (around line 194)
190:
security = classes.get(0);
191:
}
192:
if(security==null)System.out.println("security is null");
193:
try {
194:
return Java.invokeStaticOrParent(security, m, args);
195:
} catch(InvocationTargetException e) {
196:
throw e.getTargetException();
197:
}
198:
}
199:
200:
}
The first logic conclusion to jump to is: there are no classes that implement the needed Secure$Security inner class. But there most certainly is a subclass, so I was wondering how this error can be fixed.
A debugging session learns that the classes.get(0) does contain the class that has the #With annotation. So the null pointer exception must be caused by something within the class that contains the #With(SecureController). But I left that class just the way it was, I just edited the reference within the With annotation.
So my guess is that somehow, there is a null pointer within the class implementation.
But even when I implement default behaviour, without any references, it still generates a nullpointerexception.
EDIT:
I found the cause of this error, but the 'why' isn't clear.
This line is found in the implementation of the authenticate(...) method in the subclass of SecureController$Security:
flash.put("url", request.url);
Why does this fail?
I understand this situation may be very hard to reproduce, but I was wondering if someone already experienced the same issue.
Thanks for the help (on many Play! related topics) so far.
the Scope.Flash class does not allow you to store null values. Perhaps you unset or failed to set request.url elsewhere in your modifications?

Categories

Resources