Unzip files in Mule 4 - mule

I have a requirement to unzip file. Currently this is done in Java code in Mule 3.x, but need to unzip file in Mule 4, how we can achieve this in Mule 4?
Tried to use same Mule 3 Java code in Mule 4 but some of the methods/functions are not supported in Mule 4. Any code snippet/suggestion?

You don't need to use Java code to decompress zip files with Mule 4. You can use the Mule Compression Module to compress/decompress zip or gzip files. The documentation has examples.
Extracted from documentation:
<compression:extract doc:name="Extract" >
<compression:extractor >
<compression:zip-extractor />
</compression:extractor>
</compression:extract>
<foreach doc:name="For Each" collection="payload">
<file:write doc:name="Write" config-ref="File_Config" path='#[output application/json
---
"output/" ++ (payload pluck $$)[0]]' >
<file:content ><![CDATA[#[output application/java --- ( payload pluck $ )[0]]]]></file:content>
</file:write>
</foreach>

Related

Allow more than 2 gb file upload in struts2

I am using Struts 2.1 in my project.
In struts.xml maxsize element in my project is as follows :
<constant name="struts.multipart.maxSize" value="2147483648" />
For the file upload process,
is it possible to supersede the normal 2 Gb file limit of Struts2 ?
You should migrate to the latest version of Struts2.
From 2.3.20 and above, a new MulitpartRequest implementation can be used to upload large files:
Alternate Libraries
The struts.multipart.parser used by the fileUpload interceptor to
handle HTTP POST requests, encoded using the MIME-type
multipart/form-data, can be changed out. Currently there are two
choices, jakarta and pell. The jakarta parser is a standard part of
the Struts 2 framework needing only its required libraries added to a
project. The pell parser uses Jason Pell's multipart parser instead of
the Commons-FileUpload library. The pell parser is a Struts 2 plugin,
for more details see:
http://cwiki.apache.org/S2PLUGINS/pell-multipart-plugin.html. There
was a third alternative, cos, but it was removed due to licensing
incompatibilities.
As from Struts version 2.3.18 a new implementation of MultiPartRequest
was added - JakartaStreamMultiPartRequest. It can be used to handle
large files, see WW-3025 for more details, but you can simple set
<constant name="struts.multipart.parser" value="jakarta-stream" />
> in struts.xml to start using it.

How do I change the default location for mule application log files?

I would like to change the log directory from MULE_HOME/logs to MULE_HOME/logs/apps. The only place I have found that refers to a file path is in MULE_HOME/conf/wrapper.conf. Editing the wrapper.logfile does allow me to relocate the mule_ee.log file, which seems to be the Mule application log, but I'd like to include Mule application logs there, too. If I create an application called FOO and deploy it to the runtime environment, it will create a file called MULE_HOME/logs/mule-app-FOO.log, but changing the location seems to be difficult short of completely messing things up writing custom log4j2 XML files.
If you have Mule version 3.6+, then it is recommended to use log4j2.xml instead of log4j.xml.... Using log4j2 you can change the path and get your application log ... a simple example would be :-
<RollingFile name="RollingFile" fileName="${env:MULE_HOME}/logs/${sys:CustomapplicationName}.log"
filePattern="${env:MULE_HOME}/logs/${sys:CustomapplicationName}-%d{yyyy-MM-dd}-%i.log"> <!-- CustomapplicationName is set at mule-app.properties or in VM argument in Run As Configure as -DCustomapplicationName=Log4j -->
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}- %c{1}: %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="120 KB" />
</Policies>
<DefaultRolloverStrategy max="1" />
</RollingFile>
Just put this above code in your log4j2.xml in src/main/resource folder
Here in above you can see that, you have configured your path of your log files by mentioning here:-
<RollingFile name="RollingFile" fileName="${env:MULE_HOME}/logs/apps/${sys:CustomapplicationName}.log"
filePattern="${env:MULE_HOME}/logs/apps/${sys:CustomapplicationName}-%d{yyyy-MM-dd}-%i.log">
where ${sys:CustomapplicationName} is the System variable set in mule-app.properties as following :-
CustomapplicationName=yourApplicationName
Right way is to have log4j properties / xml file for FOO application and have that define the desired path for FOO application log. This way will ensure mule_ee.log is not messed up and at the same time other applications too will have their own log files which will be easy to manage and easy to introspect specific application log in case of errors / exceptions
Define location in log4j.properties file.

Jruby: How to use third party java library?

I want to use java third party qr code libary https://github.com/kenglxn/QRGen library for generating qr code.
Please guide me as i don't know how to integrate java library in jruby.
The trick in this case is to find how to properly import the 3rd party libs.
Please download the needed jars using any dependency system (I use ant with ivy).
This will download 5 jars based on the qr code library you mentioned: core-2.0.jar core-3.1.0.jar javase-2.0.jar javase-3.1.0.jar jfreesvg-2.1.jar
build.xml for ant:
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="" default="retrieve">
<!--setproxy proxyhost="" proxyport="" proxyuser="" proxypassword=""/-->
<target name="retrieve">
<ivy:retrieve/>
</target>
</project>
ivy.xml for ivy:
<ivy-module version="2.0" >
<info organisation="" module=""/>
<dependencies defaultconf="default">
<dependency org="net.glxn.qrgen" name="javase" rev="2.0"/>
</dependencies>
</ivy-module>
Now typing ant retrieve will download and store 5 jars in lib subfolder.
If you do not have a dependency manager, here are the 5 jars urls you need to download manually and you need to move to a subfolder called lib:
http://search.maven.org/remotecontent?filepath=net/glxn/qrgen/javase/2.0/javase-2.0.jar
http://search.maven.org/remotecontent?filepath=com/google/zxing/javase/3.1.0/javase-3.1.0.jar
http://search.maven.org/remotecontent?filepath=com/google/zxing/core/3.1.0/core-3.1.0.jar
http://search.maven.org/remotecontent?filepath=net/glxn/qrgen/core/2.0/core-2.0.jar
http://search.maven.org/remotecontent?filepath=org/jfree/jfreesvg/2.1/jfreesvg-2.1.jar
I strongly advise you to use a java dependency manager if you wish one day to upgrade the revisions of the java libraries used in this code snippet.
Next step is to use the following ruby snip.rb code in the same folder. :
require 'java'
%w[
lib/core-2.0.jar
lib/core-3.1.0.jar
lib/javase-2.0.jar
lib/javase-3.1.0.jar
lib/jfreesvg-2.1.jar
].map &method(:require)
# this is the CRITICAL line to get it to work...
include_class 'net.glxn.qrgen.javase.QRCode'
# get QR file from text using defaults
# this will write a file (example: QRCode7247556396487679822.png) in java.io.tmpdir as defined in your JVM
file = QRCode.from("Hello World").file()
p file.name
# get QR stream from text using defaults
# if we redirect the stream as a byte array, we can have a better file control
include_class 'java.io.FileOutputStream'
stream = QRCode.from("Hello World").stream()
fos = FileOutputStream.new("QRCode.png")
fos.write(stream.toByteArray())
fos.close()
# fun with VCards
include_class 'net.glxn.qrgen.core.vcard.VCard'
johnDoe = VCard.new("John Doe")
johnDoe.setEmail("john.doe#example.org")
johnDoe.setAddress("John Doe Street 1, 5678 Doestown")
johnDoe.setTitle("Mister")
johnDoe.setCompany("John Doe Inc.")
johnDoe.setPhoneNumber("1234")
johnDoe.setWebsite("www.example.org")
stream = QRCode.from(johnDoe).stream()
fos = FileOutputStream.new("VCard.png")
fos.write(stream.toByteArray())
fos.close()
# all generated PNG can be decoded online using http://zxing.org/w/decode.jspx
Please note: jruby and java.io.tmpdir do not play well together in this particular jar case, as any call to QRcode creation with #file() will store file in java.io.tmpdir, whereever it is located. You've little control on the file location.
So I modified the original code answer to use the stream instead and create files with finer control.
You can verify all files generated with this useful URL: http://zxing.org/w/decode.jspx

Mule Joda-time error: later version is required but found version

Mule 3.5 shows the message "later version is required" "but found version" when I try to execute the operation "find object" from the connector Amazon S3.
This happens because Mule use an old version of joda-time.
To use a new version of this lib, I put the jar of the new version in the directory:
${ANYPOINT_HOME}\plugins\org.mule.tooling.server.3.5.0_3.5.0.201407241708\mule\lib\opt
It´s also necessary to change the file MANIFEST.MF in the directory:
${ANYPOINT_HOME}\plugins\org.mule.tooling.server.3.5.0_3.5.0.201407241708\META-INF

Axis2 embedded in my web app is not working

OKay I lost alsmost the whole day on this.
I have a webapp where I would like to add AXIS2 and start working.
I added AxisServlets in the web.xml file like -
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
I also added Services.xml file like
<service name="ReportViewerService">
<description>
This is a sample Web Service for illustrating Attachments API of Axis2
</description>
<parameter name="ServiceClass">myclass</parameter>
<operation name="getReport">
<actionMapping>urn:getReport</actionMapping>
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
The directory structure is as mentioned here
WEB-ING
| - conf
| |- axis2.xml
|-lib
| |- all libs
|-services
|-ReportViewerService
| - META-INF
|-services.xml
|- web.xml
The problem is - after all of these, the service endpoint will not come, I can not see the WSDL file http://localhost:8080/BOReportingServer/services/ReportViewerService?wsdl -- this gives an exception like -
Throwable occurred: javax.servlet.ServletException: File "/axis2-web/listSingleService.jsp" not found
Finally I am able to embed AXIS2 in my webapp.
It is as simple as mentioned in the tutorial , only thing is:
I never got the jars properly placed under WEB-INF/lib directory.
Once I started from the very beginning and removed all the unwanted jars and duplicate jars from the WEB-INF/lib directory, so started working.
I had this same symptom when trying to deploy an axis2 service with a packed (unexploded) .war file on a tomcat server.
"Throwable occurred: javax.servlet.ServletException: File "/axis2-web/listSingleService.jsp" not found"
The solution was to add the 'services.list' file to the /WEB-INF/services/ folder.
(There is also a modules.list file for the /WEB-INF/modules/ folder.)
These are just a text files listing out the service archive files in the folder.
/WEB-INF
|-modules
|-addressing-1.6.1.mar
|-...
|-modules.list
|-...
|-soapmonitor-1.6.1.mar
|-services
|-ReportViewerService.aar
|-services.list
In the .list files, contain just the names of the archive files, one entry per line.
Reference: http://axis.apache.org/axis2/java/core/docs/app_server.html
You also deployed axis2.war in your servlet container, right?
In order for Axis2 to work properly, you need to deploy it to a servlet container. A tutorial can be found here. You'll know you've done it properly when the Axis2 "Happy" page can be shown.
Once you've done that, you should be able to bundle up your service (in the structure you've described above in your question) into an .aar file and deploy it using the axis2 servlet.