I'm using ActiveMQ to implement a messaging system in my current project. I need to send and receive Java objects instead of simple text or binary messages. The Java object (my message object) implements the Serializable interface as required.
Recent versions of ActiveMQ added some security and I need to set a property with the allowed packages as described here, but I haven't managed to make it work. I'm not sure where that property needs to be added.
Error message:
This class is not allowed to be serialized. Add package with 'org.apache.activemq.SERIALIZABLE_PACKAGES' system property
You need to either pass trusted packages in environment variable while running jar or you can do this programmatically by adding following line of code:
System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES","*");
I hope this will help
In your ActiveMQ config,add connectionFactory.setTrustedPackages(Arrays.asList("java.lang","your packagename"));
Related
We're using the Destinations service to configure connections to different kinds of systems. As part of this, we are using the "Additional Properties" section to add non-standard properties, such as my.custom.property=123.
We have successfully used the SAP Cloud SDK's MockUtil to write Spring integration tests that use the files systems.yml and credentials.yml as source for test systems.
However, we couldn't find a way to create an entry there that would provide a test system with a custom property like my.custom.property=123.
The erp section accepts only the properties known for ERP systems, such as sapClient. The general systems section accepts only the absolute basic properties name, type, uri, and proxy. Adding an unknown property in either section results in a runtime error because the mock utils are unable to parse the unknown property into the data classes with fixed structure.
Is there another way to mock a Destination that would allow us to include non-standard properties?
For example, the DestinationAccessorMocker looks promising, as it seems to enable setting up custom implementations of the Destination interface, but we couldn't figure out how to employ it.
Found an option that works.
MockUtil mockUtil = new MockUtil();
MockDestination destination = MockDestination
.builder("my-service", URI.create("http://localhost:1234/"))
.property("my.custom.property", "123")
.build();
mockUtil.mockDestination(destination);
Maybe somebody can confirm that this is an intended way to do this?
I come from Grails background and have recently started a project in Micronaut using GORM.
I tried to find required information in documentation but its not clear how we retrieve post data in controller, validate it similar to Command Objects offered in Grails and save it into database using interface service provided in documentation
PS : I know I can map every field to action argument in controller, and also declare a interface method specifying each argument as property but that does not seems right thing to do as my domain class has so many properties.
Making the action #Transactional or any method would work for saving data as far as I know but I want to know the proper way in Micronaut.
My requirement is simple, save post data in database using GORM in Micronaut.
If I were you I would look back at the documentation, sections 6.4 to 6.11:
https://docs.micronaut.io/snapshot/guide/index.html#binding
https://docs.micronaut.io/snapshot/guide/index.html#datavalidation
http://hibernate.org/validator/
Micronaut is very annotation based, unlike Grails which uses convention over configuration. However in Grails 4, Micronaut will toke over the application context, giving you some of the benefits of Micronaut, but still maintaining the convention over configuration.
I need to override configure() on my waveform and I tried to do it as suggested in the manual, by overriding PropertySet_impl::configure in my .[h,cpp] but calling the PropertySet_impl::configure in my override. It works when I configure my component using a python script, but it does NOT appear to be called for the initial configure by DomainManager using .prf.xml in the domain profile.
Do you send in this initial configure some other way and is there a way I can override for these too?
Try using the setPropertyConfigureImpl for properties that need custom configure logic instead of overriding configure. I believe this is invoked on the initial call to set properties.
Starting with REDHAWK 2.0, components support a new method initializeProperties() that is called once when the component is created, prior to the call to initialize(). Any properties of kind "property" are given their initial values via this call, using overridden values if provided. Legacy "configure" kind properties are still initialized via a configure() call following initialize().
If setting configure functions for your properties is sufficient, I'd encourage that approach. If you expect them to be called at initialization time, you'll want to set them in the C++ constructor, though, not the REDHAWK constructor() method.
Based on your question, property listeners are probably not suitable; property change notification is not triggered by initializeProperties(), only configure(). Note that the C++ interface is addPropertyListener(); registerPropertyListener() is a CORBA method that supports external notification of property changes.
I've got an SMTPAppender configured and I'd like to have email messages sent by that appender to have the header Auto-Submitted: auto-generated added to the messages. (This allows auto-responders, for example, to stop sending out-of-office messages to auto-generated error messages).
I don't see anything in the log4j 1.2.x API to handle this kind of thing. Is it possible to do with the existing library? If not, is it possible with a little extra hacking?
It seems as if this capability isn't available with log4j (at least the 1.x line) out of the box.
I've created a class that will do this through configuration. It can be found on GitHub here:
org/apache/log4j/extras/ExtendedSMTPAppender.java
In http://blog.bdoughan.com/2013/06/moxy-is-new-default-json-binding.html about halfway down there's a heading "Customizing the JSON-Binding". How do you similarly customize the XML binding?
There seem to be fundamental differences between the way Jersey handles Moxy JSON binding and the XML equivalent. If I follow the instructions in the Jersey documentation for creating a custom JAXBContext resolver to configure Moxy's mapping file, that resolver fires in the JSON case but not in the XML case. See https://bitbucket.org/jmetcher/resttest/ for a very small project demonstrating this.
I have the correct jaxb.properties file in place, and I'm building with the jersey-media-moxy module. I can get the identical Moxy JAXB setup working in standalone mode, I just can't get Jersey to take any notice of it.
The debugging I've done indicates that the only way to get this to work is to create a custom MessageBodyWriter. The jersey-media-moxy module registers a JSON MessageBodyWriter which will then invoke any registered ContextResolvers. It does not register an equivalent MessageBodyWriter for XML, and Jersey's default MBW's seem to completely ignore registered ContextResolvers.
Howver, the fact that the need to create a custom MessageBodyWriter is completely missing from the docs and nearly every example seems to indicate that I'm missing something fundamental.
I'd provide links to more info but I don't seem to have the rep to do much at all on SO.
EDIT: More info in response to comments:
Moxy is certainly being picked up as the JAXB provider. I can see this in the debugger.
Jersey version is 2.9, EclipseLink version is 2.5. Java 7.
The ContextResolver approach works fine for JSON. So does the approach of registering MoxyXMLFeature in an Application class. In both cases, the correct context configured with the right mapping file is used. In the XML case, it seems that Jersey never even attempts to create a context.
IF, however, I add an #XmlRootElement annotation to the class I'm trying to marshal, it all works. Even with no other annotations, the class can be marshaled to both XML and JSON according to the oxm mapping file. I've updated the bitbucket project to show this.
So, I can work around the issue either by creating a custom MBW or providing an annotated root class. I guess at this point I'm to work out what the best or recommended approach would be so I can log a documentation patch.
To have Jersey pick up MOXy as the JAXB provider, you simply need to add the jaxb.properties file with the correct entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html) in the same package as your domain model. In the case of JAX-RS if a ContextResolver is not specified this package needs to be the one that corresponds to the parameter to, or return type from from the method in your service mapped with JAX-RS annotations.
http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-35.html
Note:
There was a bug in an earlier version of Jersey that prevented MOXy from being picked up as the default JAXB provider, in that case you could:
Upgrade to a newer version of Jersey.
Create a ContextResolver to return an instance of a MOXy JAXBContext (see: http://blog.bdoughan.com/2011/04/moxys-xml-metadata-in-jax-rs-service.html)
In the case of the ContextResolver you could use code to directly create the MOXy JAXBContext instead of leveraging a jaxb.properites file. Refer to option #2 in the answer I linked to below:
How do I get EclipseLink JAXB (MOXy) to not display namespaces in XML output
It is indeed the case that the only way to marshal an unannotated domain model to XML using Jersey + Moxy is to register your own provider (aka MessageBodyWriter/MessageBodyReader).
Marshalling an unannotated model is supported Moxy functionality. However, Jersey's default JAXB providers mask this functionality by requiring that the model is annotated before they will pass off control to Moxy. The JSON case is implemented differently and does not have this restriction.
See http://lagod.id.au/blog/?p=472 for a fully worked example.
Doc bug reported: https://java.net/jira/browse/JERSEY-2552