I want to avoid using the Callable interface in a Mule component, instead of this i want to use annotations based coding.
I am using the following code but getting an error.
How can i use the annotation based approach?
public Object processEvent(#Lookup MuleEventContext eventContext) throws Exception {
System.out.println("eventContext: " + eventContext.getMessage().getPayload());
return "GOT IT";
}
From the documentation:
The Lookup annotation is used to inject objects from the Mule registry
The MuleEventContext is not a registry object but a dynamic one, so this can not work.
What do you need the MuleEventContext for?
Related
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]
I have UI object that wraps JPA entity and in constructor of that UI object I do lazy loading of some properties. In that same constructor I need to know what JsonView is currently active so I dont lazy load some fields that are not needed if say its the List view.
Is there way to find out from constructor what is current active JsonView at runtime. Or is there any other way to achieve what I described above.
My current plan
create custom serializer that during serialization will call setJsonView(Class jsonView) of the object that it serializes. All my objects that serialized will have to support that method. Inside that metid I can do lazy loading based on now known json view. Something like this:
public class JsonViewSerializer extends JsonSerializer<BaseSerializableEntity> {
#Override
public void serialize(BaseSerializableEntity value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
value.setJsonView(provider.getSerializationView());
// need to pass serialization to base class...
}
}
Currently active view is accessible via context object (SerializerProvider or DeserializationContext), using method getActiveView().
I am working on creating a Mule Anypoint connector using DevKit to connect to an internally developed API. Using the #RestCall annotation, I was able to successfully use my connector in a Mule flow, with the connector returning a String of the following JSON:
{
"name": "Bryan",
"email": "bryan#myservice.com",
"uid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
"email_verified": true
}
I know I could implement a "JSON to Object" transformer in the Mule flow, but I would like for the connector to return a POJO instead. That being said, I modified abstract method annotated by the #RestCall to return an Account object:
#Processor
#RestCall(
uri="https://api.myservice.com/v2/account",
method=HttpMethod.GET,
contentType = "application/json")
public abstract Account getUserInformation() throws IOException;
Just for reference, here is how I defined Account:
package org.mule.modules.myservice.model;
import java.io.Serializable;
public class Account implements Serializable {
private static final long serialVersionUID = -1L;
private String name;
private String email;
private String uid;
private boolean emailVerified;
/**
* removed getters and setters for brevity
*/
}
However, now that I am trying to return the Account object, I receive the following error:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='/'}" to "SimpleDataType{type=org.mule.modules.myservice.model.Account, mimeType='/'}".
I see that there is a #Transformer annotation, but documentation is lacking on how to implement this in regards to working with JSON and/or working within the context of a #RestCall within a Mule connector.
Can anyone offer up advice on how to transform a String of JSON into an Account object within the connector?
At some point (not where you are pointing at) you are trying to pass an String to an operation that needs Account. Register a transformer for that or transform manually before the operation.
I received the following response in another forum and wanted to pass it along:
In order to use DevKit #RestCall with pojos, you need to define the transformers from String to your POJO.
Check this example: https://github.com/pablocabrera85/json-place-holder-connector
For my specific question, this was the type of example I was looking for and indeed worked.
i'm using EasyNetQ library in my project and I would like to use Ninject as IoC Container for EasyNetQ components.
I created a custom logger in order to log anythong from EasyNetQ:
public class LogNothingLogger : IEasyNetQLogger
{
...
}
And then using the Ninject extension in my main function:
public class Program
{
static void Main(string[] args)
{
// Container creation and custom logger registration
IKernel cointainer = new StandardKernel();
cointainer.Bind<IEasyNetQLogger>().To<LogNothingLogger>();
// Register Ninject as IoC Container for EasyNetQ
cointainer.RegisterAsEasyNetQContainerFactory();
// Create bus
using (IBus bus = RabbitHutch.CreateBus("host=localhost"))
{
// Do something with bus...
}
}
}
But I get the following exception:
Ninject.ActivationException was unhandled
More than one matching bindings are available.
Matching bindings:
1) binding from IEasyNetQLogger to LogNothingLogger
2) binding from IEasyNetQLogger to method
Activation path:
2) Injection of dependency IEasyNetQLogger into parameter logger of constructor of type RabbitBus
1) Request for RabbitBus
Suggestions:
1) Ensure that you have defined a binding for IEasyNetQLogger only once.
[...]
Am I using this package in the wrong way? Is there any solution?
Thanks!
As the exception says, there are two bindings for IEasyNetQLogger.
I suppose that an ninject extension you are using is already binding an IEasyNetQLogger.
You could use Rebind (IBindingRoot.Rebind<IEasyNetQLogger>()) to override any existing binding for IEasyNetQLogger.
But i would also advise you to look into why the extension is already creating a binding and how it is supposed to be used.
What is the extension you are using?
Edit: i took a glance at https://github.com/mikehadlow/EasyNetQ/tree/master/Source/EasyNetQ.DI.Ninject
and i did not find any binding for IEasyNetQLogger. Are you sure you don't have defined an additional IBindingRoot.Bind<IEasyNetQLogger>().ToMethod(...) binding?
It could also be NinjectAdapter.Register<IEasyNetQLogger>(Func<IEasyNetQLogger> ...).
If you have not done so, then the EasyNetQ is already registering a logger by NinjectAdapter.Register<IEasyNetQLogger>(Func<IEasyNetQLogger> ...).
As before, you can use Rebind(..) to replace the binding (which must be done after the original binding was created!) or look into how it is supposed to work.
Of course you might also just want to skip the binding since you only created one for "log nothing logger"...
I have a base class ReportElement which has type property:
public abstract class ReportElement {
private ReportElementType type;
public ReportElementType getType() {
return type;
}
public void setType(ReportElementType type) {
this.type = type;
}
}
ReportElementType is just an enum with specified code and i18nKey properties for each element. I have a couple of subclasses of ReportElement, each of them introducing their own properties. One of them is Plot:
public class Plot extends ReportElement {
public Plot() {
setType(ReportElementType.PLOT);
}
private Collection<Parameter> parameters = new ArrayList<Parameter>();
public Collection<Parameter> getParameters() {
return parameters;
}
}
On some page I needed to display a collection of different ReportElement instances, so I just used struts2 select tag:
<s:select list="myElements" listKey="type.code" listValue="type.i18nKey" size="20"/>
This worked like a charm for every element except for Plot instaces. Instead of invoking getType().getCode() or getType().getI18nKey() plain toString() was invoked on every instance of Plot! After several hours of fun debugging I noticed that during tag evaluation Plot's getParameters() method is called! So it seems struts was trying to evaluate type.code and type.i18nKey using getParameters() method! Failing to do that it ignored the existence of the properties, that I have clearly specified for usage!
After renaming getParameters to a kind of odd name like getParamms the problem gone. Also the problem hasn't occured when using iterator tag together with property tag instead of select tag.
Does anyone have an idea WHY struts select tag uses parameters property of my bean, when I have clearly specified what property should be used? Is it some "cool" feature or a bug?
P.S. I use struts 2.2.3.1
The argument used in all the FreeMarker templates representing a tag's parameters is called parameters. By providing a parameters property that takes precedence, S2 was unable to get to the object on the stack containing the tag's parameters.
It's neither a cool feature nor a bug, it's just how the templates are implemented. Checking the template source may have saved the few hours of debugging.
Found corresponding issue in struts JIRA: https://issues.apache.org/jira/browse/WW-3268
2.3 is specified as fix version.