Error When trying to use XSSF on Jmeter - jmeter

I am getting error when trying to create xlsx file using Jmeter. actually I already try using HSSF (for .xls) and it is works fine. But when I am trying to change it using xlsx, I am getting error. I already copy the jar file for poi and poi-ooxml on jmeter lib file. here is my simple script :
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.lang.String;
import java.lang.Object;
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sample sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("HENCIN");
try {
FileOutputStream out = new FileOutputStream(new File("D:\\Jmeter\\testhencin.xlsx"));
workbook.write(out);
out.close();
System.out.println("Excel written successfully..");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Actually when I am trying to find the error, the problem are getting from this line :
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sample sheet");
Please someone help me to figure it out. it works on HSSF but on XSSF it is not working. I am getting error :Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval org/apache/xmlbeans/XmlObject

I would suggest:
Catching all the possible exceptions and printing the stacktrace to jmeter.log file as well
Re-throwing the exception to make sure you won't get false positive sampler result, something like:
} catch (Throwable e) {
e.printStackTrace();
log.info("Error in Beanshell", e);
throw e;
}
With regards to your question, most likely it is due to missing XMLBeans jar in JMeter classpath. I would suggest the following:
Get "clean" installation of the latest JMeter version
Download the latest version of tika-app.jar and drop it to JMeter's "lib" folder
Restart JMeter to pick the jar up
Using Tika you will get all the necessary libraries bundled, moreover, you JMeter will display content of the binary files in the View Results Tree listener. See How to Extract Data From Files With JMeter article for more details.

Related

Informatica Java transformation to generate output file for each MQ message in Realtime MQ schedule

I am trying to generate FlatFile as output contains MQ message Data which is configured to run in Real time. need help with Java code configuration in Informatica PowerCenter Java transformation.
Source is MQ message, Target is Flatfile. Schedule is MQ Realtime with Destructive Read option for MQSeries messages and recovery strategy configured.
I am trying below code, but output is not generated.
Writer writer = null;
filename_1 = o_File_Name;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(o_File_Name), "utf-8"));
writer.write(MESSAGE_DATA);
} catch (Exception ex) {
// Report
} finally
{
try {writer.close();
} catch (Exception e)
{/*ignore*/}
}
For each M.Q. message it should generate a separate output file which contains message data in it.
Configure below code in Java transformation in "Java Code" tab in "On Input Row" box.
Writer writer = null;
//just writing out the filename here so that you can write to your target for reconciling
filename1 = o_File_Name;
try {
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(o_File_Name), "utf-8"));
writer.write(MESSAGE_DATA);
} catch (Exception ex) {
// Report
} finally {
try {writer.close();} catch (Exception e) {/*ignore*/}
}
under Import Packages table - add below packages.
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
pass MESSAGE_DATA as input data which should be content in a file. and pass o_File_Name as location of your file -- $$TGTPATH\\FLATFILES\\xyz.txt

How to update Atlassian Confluence Wiki using JMeter and the REST API

I wanted a way to update a wiki status page and upload a file after a JMeter test was done running. This is something that you could conditionally kick off depending on the results of your Jenkins job.
I did this with these steps:
in a setup thread group, added a BeanShell Sampler to locate the most recent report file in my results folder.
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.io.comparator.LastModifiedFileComparator;
log.info("GET MOST RECENT RESULTS REPORT FOR THE APP TESTED");
String dir_path = props.get("test_results_path");
File theNewestFile = null;
try {
File dir = new File(dir_path);
FileFilter fileFilter = new WildcardFileFilter("Results_${testApp}*.*");
File[] files = dir.listFiles(fileFilter);
if (files.length > 0) {
/** The newest file comes first **/
Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
theNewestFile = files[0];
String fileName = files[0].getName().toString();
log.info("fileName: "+fileName);
print("fileName: "+fileName);
props.put("varResultsReportFile",fileName);
}
return theNewestFile;
}
catch (Throwable ex) {
log.error("Failed in Beanshell", ex);
throw ex;
}
login with a wiki/confluence system account
GET rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=version,history
Use a JSON Extractors to extract page Version number(results..version.number) and page id(results..id)
Use a BeanShell PostProcessor to add 1 to the page version number and store that value in a variable. You will need this when you PUT your update into the wiki
GET rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=body.storage
Use JSON Extractor to extact page body value(results..body.storage.value)
Using a CSS/JQuery Extractor on the JMeter Variable you created in step 7, Extract all the table values. For example,CSS/JQuery Expression=td and Match No= 1 to extract first column value.
PUT rest/api/content/${varPageId} and in the JSON body, update the single table value that you need to update and restore the values you extracted that you dont need updated.
POST rest/api/content/${varResultsPageId}/child/attachment For the Files upload tab, File Path=${__P(test_results_path)}${__P(varResultsReportFile)}, Parameter Name=file, MIME Type=text/csv
logout

Getting exception on bean shell assertion for org/json/simple/JSONArray

error :_ jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval org/json/simple/JSONArray
Import java method from project jar file which is placed in lib folder.
source code on written for pass json value in arraylist:
import jsonresponse.common.JsonResponseProcessor;
import assertions.AssertResponse;
import databaseresponse.common.DbResponseProcessors;
import org.json.simple.JSONArray;
String resJson = prev.getResponseDataAsString();
String res = resJson.get("queueId");
log.info("----->>>>"+resJson);
ArrayList list1 = new ArrayList();
list1.add("queueId");
list1.add("name");
list1.add("faxNumber");
list1.add("description");
list1.add("type");
ArrayList list2 = new ArrayList();
list2.add("userId");
ArrayList list3 = new ArrayList();
list3.add("agencyId");
ArrayList list4 = new ArrayList();
list4.add("usertypeId");
JsonResponseProcessor obj = new JsonResponseProcessor();
System.out.println("%%%%%%%%%%%%%%fgfggfffgf%%%%%%%%%%%%%%%");
ArrayList Jsoin = obj.getvalueofsubmapoflist(resJson,".result[0]",list1);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" +Jsoin);
log.info(">>>"+Jsoin);
Make sure you have all referenced .jar files in JMeter classpath (i.e. copy them to JMeter's "lib" folder). Don't forget to restart JMeter to pick the jars up
If you still experience issues try putting your code inside try block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Problem in Beanshell", ex);
throw ex;
}
This way you'll have informative stacktrace printed to jmeter.log file.
One more way to get more information regarding your Beanshell script is putting debug(); directive to the beginning of your code. If will trigger debugging output into stdout
See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information on using Java and JMeter APIs from Beanshell test elements in JMeter tests.

JMeter: Send gzipped json?

I have a web service I need to test with JMeter but the spec requires compressed json. I need to create the json from data in a CSV file. I have been able to work that out using a beanshell preprocessor and a CSV dataset config. But now I need a way to gzip the data and send it to the server. Is there some sampler out there that will do this?
Hackish Solution
The only working solution I've found is to compress the data from the beanshell script then have JMeter send the file, but this seems a bit nasty to me.
import com.eclipsesource.json.*;
import java.io.FileOutputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.zip.GZIPOutputStream;
jsonObject = new JsonObject();
// populate json data here
GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream("c:\\json.gz"));
writer = new BufferedWriter(new OutputStreamWriter(zip, "UTF-8"));
jsonObject.writeTo(writer);
writer.close();
If there are no samplers that do the compression, is there a way to avoid writing the data to the file system? Should I make a post processor to delete the temp file? Thanks for your help!
None of the samplers I know will automatically zip for you.
You can use a ByteArrayOutputStream instead of FileOutputStream, then toString it to a jmeter variable or property, so you can use it in the sampler using the variable name.
import com.eclipsesource.json.*;
import java.io.ByteArrayOutputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.zip.GZIPOutputStream;
jsonObject = new JsonObject();
// populate json data here
GZIPOutputStream zip = new GZIPOutputStream(new ByteArrayOutputStream());
writer = new BufferedWriter(new OutputStreamWriter(zip, "UTF-8"));
jsonObject.writeTo(writer);
writer.close();
vars.put("ZIPFILE", zip.toString());
Then in the Body Data section of your http request, refer to the variable ${ZIPFILE}

PDF Box generating blank images due to JBIG2 Images in it

Let me give you an overview of my project first. I have a pdf which I need to convert into images(One image for one page) using PDFBox API and write all those images onto a new pdf using PDFBox API itself. Basically, converting a pdf into a pdf, which we refer to as PDF Transcoding.
For certain pdfs, which contain JBIG2 images, PDFbox implementation of convertToImage() method is failing silently without any exceptions or errors and finally, producing a PDF, but this time, just with blank content(white). The message I am getting on the console is:
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.filter.JBIG2Filter decode
SEVERE: Can't find an ImageIO plugin to decode the JBIG2 encoded datastream.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage
SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke process
WARNING: getRGBImage returned NULL
I need to know how to resolve this issue? We have something like:
import org.apache.pdfbox.filter.JBIG2Filter;
which I don't know how to implement.
I am searching on that, but to no avail. Could anyone please suggest?
Take a look at this ticket in PDFBox https://issues.apache.org/jira/browse/PDFBOX-1067 . I think the answer to your question is:
to make sure that you have JAI and the JAI-ImageIO plugins installed for your version of Java: decent installation instructions are available here: http://docs.geoserver.org/latest/en/user/production/java.html
to use the JBIG2-imageio plugin, (newer versions are licensed under the Apache2 license) https://github.com/levigo/jbig2-imageio/
I had the same problem and I fixed it by adding this dependency in my pom.xml :
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.2</version>
</dependency>
Good luck.
I had the exact same problem.
I downloaded the jar from
jbig2-imageio
and I just included it in my project's application libraries, and it worked right out of the box. As adam said, it uses GPL3.
Installing the JAI seems not needed.
I only needed to download the levigo-jbig2-imageio-1.6.5.jar, place it in the folder of my dependency-jars and in eclipse add it to the java build path libraries.
https://github.com/levigo/jbig2-imageio/
import java.awt.image.BufferedImage
import org.apache.pdfbox.cos.COSName
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.PDPage
import org.apache.pdfbox.pdmodel.PDPageTree
import org.apache.pdfbox.pdmodel.PDResources
import org.apache.pdfbox.pdmodel.graphics.PDXObject
import org.apache.pdfbox.rendering.ImageType
import org.apache.pdfbox.rendering.PDFRenderer
import org.apache.pdfbox.tools.imageio.ImageIOUtil
import javax.imageio.ImageIO
import javax.imageio.spi.IIORegistry
import javax.imageio.spi.ImageReaderSpi
import javax.swing.*
import javax.swing.filechooser.FileNameExtensionFilter
public class savePDFAsImage{
String path = "c:/pdfImage/"
//allow pdf file selection for extracting
public static File selectPDF() {
File file = null
JFileChooser chooser = new JFileChooser()
FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF", "pdf")
chooser.setFileFilter(filter)
chooser.setMultiSelectionEnabled(false)
int returnVal = chooser.showOpenDialog(null)
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile()
println "Please wait..."
}
return file
}
public static void main(String[] args) {
try {
// help to view list of plugin registered. check by adding JBig2 plugin and JAI plugin
ImageIO.scanForPlugins()
IIORegistry reg = IIORegistry.getDefaultInstance()
Iterator spIt = reg.getServiceProviders(ImageReaderSpi.class, false)
spIt.each(){
println it.getProperties()
}
testPDFBoxSaveAsImage()
testPDFBoxExtractImagesX()
} catch (Exception e) {
e.printStackTrace()
}
}
public static void testPDFBoxExtractImagesX() throws Exception {
PDDocument document = PDDocument.load(selectPDF())
PDPageTree list = document.getPages()
for (PDPage page : list) {
PDResources pdResources = page.getResources()
for (COSName c : pdResources.getXObjectNames()) {
PDXObject o = pdResources.getXObject(c)
if (o instanceof org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) {
File file = new File( + System.nanoTime() + ".png")
ImageIO.write(((org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) o).getImage(), "png", file)
}
}
}
document.close()
println "Extraction complete"
}
public static void testPDFBoxSaveAsImage() throws Exception {
PDDocument document = PDDocument.load(selectPDF().getBytes())
PDFRenderer pdfRenderer = new PDFRenderer(document)
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page,300, ImageType.BINARY)
// suffix in filename will be used as the file format
OutputStream fileOutputStream = new FileOutputStream(+ System.nanoTime() + ".png")
boolean b = ImageIOUtil.writeImage(bim, "png",fileOutputStream,300)
}
document.close()
println "Extraction complete"
}
}

Resources