Can i get the filename like #[header:originalFilename] in a component in mule3 - file

I use
<gzip-compress-transformer/>
<base64-encoder-transformer/>
after a file connector, and then write a component to deal with the gzip+base64 content.
How can i get the file name in the component?

Note that we introduced annotations in Mule 3 for doing runtime injection, this means you can specify how to invoke a component without needing transformers i.e.
public void save(#Payload String fileContents, #InboundHeaders("originalFilename") String originalFilename)
See: http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Service+Objects+and+Transformers+Using+Annotations

Does your component implement Callable? If not, do you want to keep your component Mule-unaware?
Based on your answers to these questions, different options exist:
With Callable, you get the headers in message.getProperty...
Without implementing Callable, you can access RequestContext to get the current Mule event and from there reach the message properties. But this makes your component Mule aware.
Otherwise, have your component's method take a second parameter (String originalFilename) and use a standard expression transformer to transform the payload in an array that contains: #payload, #[header:originalFilename]. This arrays will then be passed as arguments to your component's method.

[message.outboundproperties[originalFilename]]
with this expression you can get the original file name in the component.

Related

How to get headers from within Exchange object in the body object

I have headers i'm setting within a function and then saving the Exchange objects to a list.
newExchange.`in`.setHeader("aggregationCount", 3)
Im then trying to retrieve this header later on and I can see it, in the object its in the path of Exchange.in.body.in.headers - How would I access this variable, I've tried (e.`in`.getHeader("aggregationCount") however this doesn't work. All i need to is to pass a variable/property through on the Exchange object, if there is other ways to do this, tell me and i can just use this instead.
Within the Camel route, you can simply use .header("HeaderName") to return the header value. In this case, something like:
.header("aggregationCount")
Or if you need to use the value in a conditional:
.when(header("aggregationCount").isGreaterThan(0))
https://camel.apache.org/components/latest/languages/header-language.html
To answer your other question, you could also use exchangeProperty to store and retrieve values.
https://camel.apache.org/components/3.4.x/languages/exchangeProperty-language.html

.when().jsonpath(myClass.getJsonPathExpressions().get(),true) not working if json path expression is null or empty

from("somegcpchannel").
.choice()
.when().jsonpath(myClassObject.getJsonPathExpressions().get(),true)//true will suppress exception if the path does not exist"
The problem with this camel jsonpath component is that if myClassObject.getJsonPathExpression() is null or empty it throws an exception.Hence I am forced to put some dummy json path to get it working.
How can I first check if the myClassObject.getJsonPathExpressions() if not null only then process the json path expression.All in one statement if possible(not nested choice / when).It is weird that json path component of camel does not do the null check
This is a pure Java problem. You want to use a value that is stored in an instance object of your RouteBuilder class to construct a Camel Route.
myClassObject.getJsonPathExpressions().get()
When myClassObject.getJsonPathExpressions() returns null then the following .get() method obviously throws a NPE. Therefore the Camel route cannot be constructed.
Sidenote: this is a static value anyway. The value returned from the object is used while constructing the route and will never change while the application is running.
Since it is a pure Java problem, you cannot use Camel to solve it. You have to solve it in Java.
The most simple solution (as you already stated) is to always provide a value. To make your Route happy, just add a method to your RouteBuilder class that returns the object value if present or a sensible default.
private String getJsonPathExpression() {
if (whatever checks are needed) {
return myClassObject.getJsonPathExpressions().get(); // value present
} else {
return "default JsonPath that works" // no value present
}
}
And then use this method in your route instead of using the object directly
.when().jsonpath(getJsonPathExpression(),true)
This way you simply hide all the value checking stuff in the method.

ODI 12C Smart import with actions using SDK

HI I'm able to smart import Projects in ODI using SDK. but i'm unable to use the predefined method which sets actions like merge, create copy, ignore, reuse, while importing the projects.
Please help me to implement the below method,
setMatchedFCODefaultImportAction(java.lang.String pFCOObjType, int pSmartImportAction)
by using below method i'm directly importing projects.
importObjectsFromXml (fnameAndPath, ExportKey, ExportWithoutCipherData);
I want to implement above mentioned actions, please help me.
thanks
Unfortunately you can not use setMatchedFCODefaultImportAction to specify the action for a specific object like a project as in your code :
smartImpServ.setMatchedFCODefaultImportAction("Dev_ODI_Project", 1);
It can only define the default action for a First Class Object i.e. for all the objects of a specific type. For instance you can set the default actions for any project as CREATE/COPY (equivalent to 1 as you used in your code):
smartImpServ.setMatchedFCODefaultImportAction(ISmartImportService.PROJECT_OBJECT_NAME, ISmartImportService.SMART_IMPORT_ACTION_CREATE_COPY);
The values you can use as the pFCOObjType parameters are all the Fields ending by _OBJECT_NAME in the ISmartImportService interface.
If you want to specify the action for a specific object, you would need to use a response file from a previous import with the importFromXml method.

Close method not working in Office

Im trying to use Microsoft.Office.Interop.Word._Document.Close() in a .net 3.5 windows form app.
No matter how much I search here and on Google I cannot find the correct parameters to put in the Close method.
I am using version 14.0.0.0 of Microsoft.Office.Interop.Word and I would like to close the document without saving and ideally ensure that the application can isolate the document thread so that users can still open word documents outside the running application.
See the Close method of the Document class described in MSDN. If you need to omit the parameter and use the default value - pass the Type.Missing parameter.
Try this:
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing = System.Reflection.Missing.Value;
_Document.Close(ref doNotSaveChanges, ref missing, ref missing);
This is the source
I'm not sure if you'll need the middle line or not. It's not from the original source it's from here

CakePHP RequestHandler: setContent/renderAs/respondAs .. what?

Can someone please explain these functions:
RequestHandlerComponent::renderAs()
RequestHandlerComponent::respondAs()
RequestHandlerComponent::setContent()
It feels slightly redundant to have all three of them (as public methods anyway). If I want to respond to a request with a PDF file, does that mean I'd have to call all three functions? How should I use these in my controller?
They're all different. From the API Docs:
renderAs
Sets the layout and template paths for the content type defined by $type.
I.e. more or less a shortcut for $this->layout = '...' and $this->render(...).
respondAs
Sets the response header based on type map index name. If DEBUG is greater than 2, the header is not set.
Outputs header(...).
setContent
Adds/sets the Content-type(s) for the given name. This method allows content-types to be mapped to friendly aliases (or extensions), which allows RequestHandler to automatically respond to requests of that type in the startup method.
Doesn't actually do anything to the output, just allows you to add new types that are not defined by default.
For outputting a PDF (assuming you have it as a file already) you should actually use a Media View.

Resources