Jmeter Upload Error in Recording - java

I am trying to record a session in which there is a upload functionality.
I have used http proxy server for recording, recording controller and http cookie manager.
When I try to upload a file and click save it shows following error:
java.io.FileNotFoundException: a12-13538_110q.htm (The system cannot
find the file specified) at java.io.FileInputStream.open(Native
Method) at java.io.FileInputStream.(Unknown Source) at
java.io.FileInputStream.(Unknown Source) at
org.apache.jmeter.protocol.http.sampler.PostWriter.writeFileToStream(PostWriter.java:408)
at
org.apache.jmeter.protocol.http.sampler.PostWriter.sendPostData(PostWriter.java:117)
at
org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sendPostData(HTTPJavaImpl.java:115)
at
org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:510)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1060)
at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:238)
This functionality works fine when I am not using jmeter recording.
Kindly help on this.
Is there any way I can perform this test?

Bug 50079: Jmeter does not record the file path.
As per your exception jmeter cannot find file to upload, because of issue mentioned above.
So you have to set path manually in sampler, and it's better to use variable for this, for test parametrization.
Don't use record-and-playback at all, or at least check and adjust your recorded samplers.
In your case you have to set in recorded http [POST] request following:
Use multipart/form-data for POST = true - to sent file as part of request;
Send Files with Request -> File Path = PATH_TO_FILE - path to existent file, directly or using variable.
. . .
UPLOAD HTTP Request
Method = POST
Use multipart/form-data for POST = true
-- Send Files with Request -- section:
File Path = ${testFile}
Parameter Name = datafile
MIME Type = ...
. . .

This is related to the defect mentioned above. But the workaround is (On windows) to place the file that is being uploaded in the same folder as the JMX file is. (The file path is not captured only the file name is captured here. Hence need to update the correct absolute or relative path accordingly once the requests are captured.)

Related

Java sftpChannel put error (The system cannot find the path specified)

I am going to transfer files to remote sftp by Java sftpchannel. Everything are going to be as expected. It was well tested on STS (Spring Tool Suite 4.7.1). But it failed when it was deployed to tomcat server.
// Logs
File path: S:/System/AutoSend/Data.json
Remote path: Data.json
Before sftp put
Sftp error: 4: java.io.FileNotFoundException: S:\System\AutoSend\Data.json (The system cannot find the path specified)
(Unix-formated path has been transformed to windows format automatically?)
What can I do to fix the issue? Thanks a lot.
Have you tried making the File Path a String? Like this: "S:/System/AutoSend/Data.json"
and
is the "S" Drive on your Tomcat-Server? If not, try using the IP-address instead.

Azure specific reading files from local on spark

I am struggling with Azure wasb on spark
I am reading loading a .json.gz file from disk and loading it into hdfs. I have used the following code extensively on other systems.
val file_a_raw = sqlContext.read.json('/home/users/repo_test/file_a.json.gz')
However, on Azure, this returns:
java.io.FileNotFoundException: Filewasb://server-2017-03-07t08-13-41-314z#server.blob.core.windows.net/home/users/repo_test/file_a.json.gz does not exist.
I have checked this location and the file is there and correct.
I think there should be a : between .net and then file path, but I get a java error trying to manually add that in.
java.lang.IllegalArgumentException: java.net.URISyntaxException: Expected scheme name at index 0:
I've also tried:
Filewasb:///home/users/repo_test/file_a.json.gz
But that returns:
java.io.IOException: No FileSystem for scheme: Filewasb
This code works fine on non Azure spark
For Azure, you'll need to configure Spark with the proper credentials. Databricks has documentation on this: https://docs.databricks.com/user-guide/faq/azure-blob-storage.html

Tomcat directory navigation for Localhost

Hi I am in the process of creating a web application with jsp/javaservlet. The problem I have is opening a file that is in a different directory than my current java class. I need help to understand why it is not picking up the directory.
Note I am just creating the program on localhost until it is done then I will export it into a .war file and set the permissions with file zilla or linux commands.
I got my file location string from running my Index page and copying it from the address bar.
My Code:
Object obj = parser.parse(new FileReader("http://localhost:8080/Practical_3_JSP/inc/Data/MyData.json"));
The Result:
HTTP Status 404 -
The requested resource is not available.
Path Map:
Note I have tried:
"http://localhost:8080/Practical_3_JSP/inc/Data/MyData.json"
Image Location: http://postimg.org/image/xcu5y82vb/

Servlet - Addressing properties files

I have a simple Servlet that needs to pass some properties files to another class.
Properties prop = new Properties();
prop.load(new FileInputStream("/home/user/config.properties"));
Above works fine.
But I can't address the right absolute path in below:
String protocol = prop.getProperty("protocol", "/home/user/protocol.properties");
String routes = prop.getProperty("routes", "/home/user/routes.properties");
MyClass message = new MyClass(protocol, routes, 0);
At the end I receive below from tomcat log:
INFO: Server startup in 3656 ms
java.io.FileNotFoundException: routes.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at com.cc.verticals.Messenger.<init>(Messenger.java:134)
at com.foo.MyClass.<init>(MyClass.java:42)
at com.verticals.cc.util.VerticalUtil.setup(VerticalUtil.java:59)
at com.verticals.cc.util.VerticalUtil.main(VerticalUtil.java:259)
at com.verticals.cc.dao.VerticalDao.<init>(VerticalDao.java:24)
at com.verticals.cc.controller.VerticalController.<init>(VerticalController.java:33)
Line 42 is pointing to the constructor where routes.properties file goes in.
Messenger line 134 points to:
prop.load(new FileInputStream(routesFilename));
Any Idea how to address the properties files and send them as a String parameter? Thanks.
By the looks of it (I prefer if you post the content's of the properties files), there is a property within config.properties such that routes = routes.properties. When you call new file(routes); you get the FileNotFoundException because you are trying to open routes.properties in the current working directory where java was launched (which doesn't exist)
As a side note, you using one property file to reference another property, which is fine but a bit odd or unconventional. Further, you should stick these files in a 'resource' folder to remove absolute paths and gain portability.
Notice that prop.getProperty method cannot throw FileNotFoundException. So that exception must have been thrown earlier on prop.load();
Please make sure that you have opened the permissions on the file. Open a terminal and issue following command:
$ chmod 777 /home/user/routes.properties
$ chmod 777 /home/user/protocol.properties

Unable to Insert image to mysql database using servlet

Could anyone please help me out with the following?
I'm trying to insert an image to the blob column in mysql database through a servlet.
I'm selecting the image through the "HTML FILE INPUT TYPE" which is in a JSP file.So the full path of the image is selected.
The error I have been getting is:
HTTP Status 500 - Desert.jpg (The system cannot find the file specified)
type Exception report
message Desert.jpg (The system cannot find the file specified)
description The server encountered an internal error (Desert.jpg (The system cannot find the file specified)) that prevented it from fulfilling this request.
exception
java.io.FileNotFoundException: Desert.jpg (The system cannot find the file specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(Unknown Source)
Image.ImgInsert.doGet(ImgInsert.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.28 logs.
Apache Tomcat/7.0.28
Where "Desert.jpg" is the image which is on my desktop.
This same program works on my friends computer.
Here is the servlet code:
String s_id = request.getParameter("myid");
int id = Integer.parseInt(s_id);
//IMAGE ACQUIRED FROM THE FROM THE JSP PAGE
String img = request.getParameter("myimg");
File f = new File(img);
FileInputStream fis = new FileInputStream(f);
String query="insert into images.imageinsert(id,image) values(?,?)";
try
{
PreparedStatement pStatement = conn.prepareStatement(query);
pStatement.setInt(1, id);
pStatement.setBinaryStream(2, fis);
int result = pStatement.executeUpdate();
if(result != 0)
{
response.sendRedirect("ImageHome.html");
}
pStatement.close();
Could anyone please help me out?
There are at least two serious conceptual mistakes here.
You seem to think that having the client side local disk file system path is sufficient to obtain the entire file contents in the server side. This is impossible as the client and server don't share the same disk file system (unless they both happen to run on physically the same computer, which of course don't occur in real world).
You're relying on relative paths in java.io stuff. It becomes relative to the so-called "Current Working Directory" which is the folder which is been opened at exactly that moment the webserver was started. This is definitely not the folder where the webapplication is directly sitting in. This is for example C:\path\to\tomcat\bin. The uploaded file surely isn't magically been placed in there.
As to why it works on the machine of your "friend", that's undoubteldly because he's using Internet Explorer which has a security bug wherein the full file path instead of only the file name is been sent as request parameter on an <input type="file"> field of a <form> without enctype="multipart/form-data". Again, as answered, this approach surely won't work in a real production environment.
Your concrete problem can be understood and solved by carefully reading the following answers.
How to get the file path from HTML input form in Firefox 3
getResourceAsStream() vs FileInputStream
How to upload files to server using JSP/Servlet?

Categories