Fail to Read File In Mule Standalone Server - mule

Hi I am working with Mule Standalone server and when i am deploying my application as a ZIP to Standalone server as mentioned in the Mule Website Deployment Structure. In my project structure i have one file inside
src/main/resources/myfolder/myfile.xml.
When i am reading this file from Anypoint Studio using System.getProperty("user.dir") it is working fine .
When i am reading deploying the same in Standalone server it is throwing file not found exception, because their System.getProperty("user.dir") is returning till bin where file not exist \Java\MuleStandAlone\bin.
So to deploy to Mule Standalone where i will place my files so that i can read.

files under src/main/resources will be available from the classpath, so there should be no reason to lookup the root directory.
Just read it from classpath as "myfolder/myfile.xml".
E.g:
<set-payload value="#[Thread.currentThread().getContextClassLoader().getResourceAsStream('myfolder/myfile.xml')]" />

I have tried the way as Ryan Carter mention in the answer works for me and reading path as a String instead of Stream that also works for me.
String path= MyClass.class.getClassLoader().getResource("myfolder/myfile.xml").getPath();

Related

Weblogic server - Getting NoClassDeffError for TIFFImageReader even when the library is in classpath

I am working on TIFF to JPEG conversion program. I am using the TIFF implementation from jai-imageio-core.1.3.1.jar, which is available in the classpath.
Everything works fine in my local environment in eclipse (running on tomcat server). However, when I deploy the same in Weblogic, I am getting the following error. Weblogic server is unable to recognize the TIFF implementation classes. I am unable to find the missing link. Please help.
java.lang.NoClassDefFoundError: com/github/jaiimageio/impl/plugins/tiff/TIFFImageReader
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReaderSpi.createReaderInstance(TIFFImageReaderSpi.java:118)
at javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at javax.imageio.ImageIO.read(ImageIO.java:1443)
at javax.imageio.ImageIO.read(ImageIO.java:1308)
I will answer my own question. The issue is resolved. The problem was with the the jai-imageio-core.1.3.1.jar file present in multiple places. It was present in my application war file in WEB-INF/lib folder. however, the same jar file was also present outside the war in the weblogic adm root directory. (my bad)
I guess weblogic clearly expects the jar file only in 1 place (especially java SPI implementation jar)
It is also a good idea to search all directories under weblogic to make sure there are no additional jar files of the same name.
I had only one jai-imageio-core.1.3.1.jar file (in WAR file) and caught this error. Weblogic managed server restart helped me.

IBM MobileFirst war file unable to deploy to MFP server

I had tried deploy both war file without java and jar files and with java and jar files. The war file without java and jar files managed to deploy successfully without any error in the log. The runtime appear in the admin console and everything works.
If I deploy server/java and jar war files, my runtime will disappear from the admin console. Here is my java lib,
I am using the IBM Server Configuration Tool to deploy war.
axis.jar
bcprov-jdk14-143.jar
commons-discovery-0.2.jar
commons=logging.jar
CryptoPasswordTool_14.jar
e2eejslib2048_b1.4_v1.3jar
jaxrpc.jar
jcprov.jar
saaj.jar
wsdl4j.jar
xerces-2.9.1.jar
Here is my Java call
javax.xml.rpc.Service aacmService = javax.xml.rpc.ServiceFactory.newInstance().createService(new java.net.URL(connectionUrl),new javax.xml.namespace.QName(ssoLink, "SSOService"));
These library had been used in my server/java to make some customized server call.Is there any of these jar files that will crash with MFP?
In this environment, I unable to get to copy anything out from the server due to the client policy. But I managed to take a shot on the screen.
Without proper information to review, such as the complete log file to see all errors printed, the recommendation is to open a PMR instead of a question on stack overflow, which anyway is more suitable for programming questions rather than infrastructure questions.
Open a support ticket to IBM: http://www-01.ibm.com/support/docview.wss?uid=swg21507643

Mule requester module is not working in cloudhub

I am using Mule requester module for lookup service using the file connector.it is working perfectly in anypoint studio and not working in cloudhub environment.Does it requires any configuration in cloud hub?
Cloudhub only allows access to one flat directory '/tmp/'. That's the only directory you can use with the file connector on Cloudhub. https://github.com/mulesoft/mulesoft-docs/blob/9f9c8a3950c4cb68e22f579c0ef979658acd170d/runtime-manager/v/latest/cloudhub-and-mule.adoc#disk-persistence
UPDATE FROM COMMENT:
You shouldn't use the Maven directory structure src/main.. etc. as thats not part of the packaged zip so its not on the classpath. If you need to read a resource from the classpath i'm not sure you can do that with the file transport on Cloudhub. If you simply want to load a file from the classpath you're better off using something like:
<set-payload value="#[Thread.currentThread().getContextClassLoader().getResourceAsStream('my-file.abc')]" />
or use the parse-template transformer or other options detailed here:mule read single file from classpath during flow
when we worked on Mule requester with Anypoint studio version 5.4.2, it was working fine for us. We deployed to cloudhub also and it was working for us. we did not faced any issues.

mule anypoint studio class not found exception

If I run the application in server, which is working fine, but If i run application in anypoint studio doesn't run. Here is the error message for loading oracle driver.
error message:
2015-02-04 11:18:34 WARN DriverManagerDataSource:107 - Could not load driverClass oracle.jdbc.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
I have placed all jdbc and other jars under studio->project->properties->libraries.
This is caused by the Studio's classloading policies. The workaround is to copy the JDBC Driver .jar to ${studio.home}/plugins/org.mule.tooling.server.${mule.version}.ee_${mule.version}.${release.date}/mule/lib/user
Hi there actually that's kind of a hack :P though it works.
The more proper way to deal with this is, when coding your application (that's why one should use Mule Studio), to place the jars like drivers in a particular folder, like a /lib in the root of you project.
Then add these jars to the classpath.
I know what you did is the way it should be done when running on Mule stand alone in order to share such jars but try this one if you can ;)
I was also facing the same problem. As the application runtime fails to locate the jdbc driver jar in classpath So It is unable to load the same.
the simple and easiest way to handle this error is just put your lib folder containing the ojdbc jar file inside the app resource (src/main/app) of the project. During the building of project it will automatically be place in classpath.
I have tried the same approach and It works for me.
Hope this helps.
The way I fixed the problem was removing the .classpath / .project files from my project root folder. I re-imported the project and then I saw a bin folder created. I removed this bin folder then right-click on the project -> Refresh and then Run As -> Mule Application.

Mule Deployment properties file

I have seen some strange behaviour in Mule Application. I created a sample mule project(created flows) and opened mule-deploy.properties file "config.resources" value is empty.
But the same above mentioned key value is getting updated with "configuration xml file name" when i run my mule project.
Is this the behaviour or any updates need to be done.
Can some clarify?
Regards
Vikram
There are some known issues/features around mule-deploy.properties and Mule Studio.
Currently it is expected that when running your project from Mule Studio that mule-deploy.properties-config.resources is automatically populated with all your configuration files.
There are some open issues on this here: https://www.mulesoft.org/jira/browse/STUDIO-3297 that you can vote on.
Once you run the mule application it will automatically updated with the configuration file by default if you have only one main configuration file.But If you are using more configuration files in your application you should manually add all the filenames to the config.properties key separated by comma before run the application.