I would like to know if there is a way to convert EDI files to other format in mule. I have a requirement to convert from EDI to XML . I am able to do it using smooks plugin withing Mule. Wondering if there is more cleaner way to do it inside Mule, something like using datamapper. Please suggest.
I'm afraid the smooks comunity extension looks pretty much abandoned, however you could easily transform using a Java transformer like this:
public abstract class EdiSmooksTransformer extends AbstractTransformer
{
private Smooks smooks;
public EdiSmooksTransformer() throws IOException, SAXException
{
smooks = new Smooks();
smooks.setReaderConfig(new EDIReaderConfigurator("MY_EDI_CONFIG_FILE_PATH_HERE"));
}
#Override
protected Object doTransform(Object src, String enc) throws TransformerException
{
StringResult stringResult = new StringResult();
smooks.filterSource(new StreamSource((BufferedReader) src), stringResult);
return stringResult.getResult();
}
}
Related
Is there a way to use byte buddy to implement ClassFileTransformer#transform?
At the moment my implementation uses javassist but I want to replace it with byte buddy as it has a better generics support.
So far my implementation looks like this:
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer)
{
if (className.startsWith("my.package."))
{
try {
final CtClass ctClass = classPool.makeClass(new ByteArrayInputStream(classfileBuffer));
/* class manipulation */
return ctClass.toBytecode();
// remove class from class pool if it hasn't been modified
ctClass.detach();
} catch(final Exception ex) {
logger.error("failed to analyse/transform class {}", className, ex);
}
}
return classfileBuffer;
}
Is something similar possible with byte buddy? Are there ways to feed byte buddy with the byte code provided in parameter classfileBuffer?
The ClassFileTransformer implementation is configured into the Spring Load Time Weaver. So I already have the "infrastructure" available. Therefore I would rather not install another byte buddy agent to solve this problem.
Yes, look into AgentBuilder.Default. It offers a DSL for implementing Java agents. You do not need to implement your own class file transformer using it, just specify the transformations you want to make.
I am using jaxrs 2.0 & am trying to populate an object in the ContainerRequestContext & retrive it in the business logic.
I am populating the object in the ContainerRequestContext like :
#Override
public void filter(ContainerRequestContext requestContext) throws IOException {
MyObject myObject = new MyObject();
requestContext.setProperty("myObject", myObject);
}
And I am trying to read it in the business logic like :
#GET
#Path("/custom")
public String data(#Context ContainerRequestContext crc) {
Object pco = crc.getProperty("myObject");
}
I am using this approach from the example shared in : How to inject an object into jersey request context?
However I am getting the ContainerRequestContext crc as null. Can someone tell me what I could be doing wrong ?
I have tested the exact code asked in the question which works as it is with following setup:
spring-boot-starter-parent: 2.3.4.RELEASE
spring-boot-starter: inherited from parent
spring-boot-starter-jersey: inherited from parent
which evaluates to Spring 5.2.9.RELEASE, Jersey 2.30.1
Arquillian with Jersey can work.
I am trying to write a List of a specific type using Kryo serializer but I am getting errors when I try to read/write it. I am using source provided by apache spark for KryoRegistrator
List I am trying to write is of type List<A> which could be an ArrayList or any other type of list
Code
Class FakeRegsitrator implements KryoRegistrator{
#Override
public void registerClasses(Kryo kryo) {
CollectionSerializer listSerializer = new CollectionSerializer();
listSerializer.setElementClass(A.class, kryo.getSerializer(A.class));
listSerializer.setElementsCanBeNull(false);
kryo.register(A.class, new Serializer<A>(true, true) {
public void write(Kryo kryo, Output output, A a) {
output.writeLong(a.getFieldA)
output.WriteString(a.getFieldB)
}
public A read(Kryo kryo, Input input, Class type) {
return new A(input.readLong(), input.readString())
}
}
}
What am I missing here?
I was able to get it working by registering Arraylist.class
code :
kryo.register(ArrayList.class);
in read method use
kryo.readObject(input, ArrayList.class);
in write method use
kryo.writeObject(output, entry.getArchivePortions());
Mule : Could you please help following query : In Anypoint Mule IDE, How to assign values to a Payload like this "Value1|Value2|Value3|Value4|.." ? and then assign the payload to Java component in Mule?
I tried following approach:
(1) define Java component and return String object as output (by implementing callable method as below):
public class InputToJavaComponent implements Callable {
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
return "Value1|Value2|Value3";
}
I was checking if is there any other simple way to achieve same thing.
Thanks.
Can you please try like this in set payload and let us know whether it work or not
[flowVars.Value1+'|']#[flowVars.Value2+'|']#[flowVars.Value3+'|']#[flowVars.Value4]
hi i tried as the below way and it was working fine for me, try in this way
[sessionVars.Value1+'|']#[sessionVars.Value2+'|']#[sessionVars.Value3+'|']#[sessionVars.Value4]
Both approaches as follow works fine:
(1)
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
return "Value1|Value2|Value3";
}
(2)
[flowVars.Value1+'|']#[flowVars.Value2+'|']#[flowVars.Value3+'|']#[flowVars.Value4]
On one side, I have just update the version of spring-data-rest-webmc to the latest 2.0.0.RC1 version of my server. In this version, the json format change to an HAL format.
On the other side, I have a client which use the spring-hateoas library with the 0.9.0.RELEASE version.
In this client, I use RestTemplate to get a resource from my server like this :
AuthorResource authorResource = restTemplate.getForObject(BASE_URL+"authors/"+ authorId, AuthorResource.class);
The AuthorResource class extends ResourceSupport.
Now, I have this error :
Nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "_links" (class org.example.hateoas.AuthorResource)
How can i configure my client to support this new format ?
I try
#EnableHypermediaSupport(type =
EnableHypermediaSupport.HypermediaType.HAL)
But it does not work.
thx for your help.
Problem is that halMapperObject is not setted because of context is not spring web.
You have to create your own RestTemplate class like this
#Component
public class EraRestTemplate extends RestTemplate implements InitializingBean {
#Autowired
#Qualifier("_halObjectMapper")
ObjectMapper halObjectMapper;
static class HALMessageConverter extends MappingJackson2HttpMessageConverter {
}
#Override
public void afterPropertiesSet() throws Exception {
halObjectMapper.registerModule(new Jackson2HalModule());
HALMessageConverter converter = new HALMessageConverter();
converter.setObjectMapper(halObjectMapper);
this.getMessageConverters().clear();
this.getMessageConverters().add(converter);
}
}
It works fine now for me thanks a friend who knows Spring very well.