How to connect Jmeter to Java class? - java

I am new to Jmeter. Currently i have tested web service calls in Jmeter. I have sent a request to server through web service calls. My input is xml file and its encrypted form. So i given encrypted string in PostBody.
My problem is I'm not able to do the encryption process in Jmeter.
So i have decided to connect jmeter to my java class and send to server.
Jmeter--->Java class--->server.
I have used Jmeter 2.8
Is there any possible to connect Jmeter to java class?

I am not sure to understand but if what you want to do is the following:
Encrypt some XML
Pass it as Raw Post Body to the HTTP Sampler which will call your webservice
Then the answer to do that is the following:
Add groovy-all.jar in JMETER_HOME/lib folder
Use a JSR223 Pre Processor on your HTTP sampler, and put the following Groovy code:
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
HTTPSamplerBase httpSamplerBase = (HTTPSamplerBase) sampler;
HTTPArgument argument =
httpSamplerBase.getArguments().getArgument(0);
String valueToEncrypt = argument.getValue();
// Do you encryption here, in this example I put ENC for testing
valueToEncrypt = "ENC"+valueToEncrypt;
httpSamplerBase.getArguments().clear();
httpSamplerBase.addNonEncodedArgument("", valueToEncrypt, "");
In the HTTP Sampler, put your original XML to be encrypted in Raw Post Body text area
Plan will have following structure (HTTP mirror server is just for my test):
Note: I use current JMeter nightly build so I have Script Compilation caching part which is not yet available and will be in 2.9. Instead put your script in an external file and reference it in File Name field.

jMeter can talk to a lot of things (see this list at Apache). One is JMS and that could probably be used to connect to your java server. Or http (which it's normally used for). It all depends on what your java class is able to respond to.

You can also make a jar of your java class, and append it to your test plan. You can then reference them from the JSR223 preprocessor with the groovy engine.

Related

How to generate multiple login user in jmeter for java sampler request

Iam doing load test for gaming application which uses both https and websocket protocol.
I had used web-socket plugin by peter for ws connectio, but unable capture and handle all response.
I have a web-socket client connection java code(own websocket implementation)... How to integrate with jmeter???
If java sampler is a way to do it...then how to pass multiple user login for java request sampler..
In order to develop your own Java Request sampler you need to inherit your class from AbstractJavaSamplerClient and implement SampleResult runTest(JavaSamplerContext context); function
JavaSamplerContext in its turn provides getJMeterVariables() function which you can use for accessing JMeter Variables originating from i.e. CSV Data Set Config

Can .jar get POST params?

Can .jar file recieve POST params? I know with command line arguments I can pass data, but as I realise, this data is sent as string:
java -jar mylibrary.jar somepostdata
I am asking this because I know main class in Java recieves String[] args.. Now, I want to pass POST object, not just plain string. Can it be done?
Based on your comment below you would require a Jetty Web Server. A Jetty Web Server is a JAR file. So basically you would expose an endpoint. Your application jQuery or whatever you decide to do will send to this JAR at the endpoint and port number.
I hope that makes sense.

Calling Ab-initio web service from java

I have created a web service in Ab-initio, I want to call that web service from java, I have read a lot information from help file. It gives me some information about plugin, but they have not mentioned it specifically that how to call service mentioned in plugin from java. Will anyone please guide me through it.
Thank in advance.
Assuming you are using SOAP as your transport mechanism in RPC Subscribe -> Read XML Transform, the following link gives you a working example of a SOAP client:
Working Soap client example
if you can test your web service using the component Call Ab-Initio RPC, and a record format of:
include "~$AB_HOME/connectors/RPC/rpcheader.dml";
include "~$AB_HOME/connectors/SOAP/SOAPRequest.dml";
metadata type = record
rpcheader hdrs;
SOAPRequest soaphdrs;
utf8 string(big endian integer(4)) body;
end;
then modifying the java code in the link to assign appropriate field name values should work.

Converting documents via HTTP

With the documents4j-server running and listening at http://localhost:9998 is it possible to convert a document with a direct HTTP command?
Example:
http://localhost:9998?source=C:\Test.doc?target=C:\Test.pdf
More info:
I was a few steps ahead of myself...
I am using Apache FOP servlet running on Apache-Tomcat as a service to generate PDF documents from XML / XSLT.
Once running a PDF can be generated via http.
Example:
http://localhost:8080/fop/
?xml=C:/temp/Test.xml
&xslt=C:/temp/Test-Style-Sheet.xsl
&pdf=C:/temp/Test.pdf
I execute this command from my database application (which sets up the XML source and manages the resultant PDF).
I was looking for the ability to do something similar with documents4j for Word Doc to PDF conversion.
So I now realise that what I actually need is the ability to pass the name/type of the source document and the type of conversion (plus any other required parameters) to an external program / http port which can then package the request appropriately and then initiate the formal conversion process.
Would anyone be able to provide advice or a solution?
Not the way you attempt it, the conversion server would not be able to read from or write to your file system. No server can do that, this would be a severe security breach.
Instead, you can send the file via HTTP POST as the body of the message, that is what the client does. The answer then contains the converted file as the body of the response. You are using the request headers to specify your request:
For defining the input type, you are using the HTTP Content-Type header.
For defining the requested type, you are using the HTTP Accept header.
As an example, for converting a file from MS Word to PDF, you would for example use application/vnd.com.documents4j.any-msword as an input and application/pdf as the accept header's type.
You can also use the the client implementation that ships with documents4j and which is described under Converter client in the readme. This client sends exactly such a request.
Edit: You would need to set up your own minimal client application for that. A minimal application would look like this:
class MyApp {
public static void main(String[] args) {
IConverter converter = LocalConver.make();
converter
.convert(new File(args[0])).as(DocumentType.MS_WORD)
.to(new File(args[1])).as(DocumentType.PDF)
.execute();
converter.shutDown();
}
}
Given that you hand over the first and second command via the command line. Alternatively, you can connect to a server via the RemoteConverter. Of course, you can also use the built in command line tool for that which is however not available via HTTP. You could write a small app that delegates to that command line tool if this was your requirement.

how can i debug this issue with axis 2 web services and clients

I am learning to make web services with eclipse, apache and axis 2 following this tutorial. I am able to generate web services, create and upload .aar files and generate web service clients just like in the tutorial. But when I go to test the client it is not generating proper responses...
PersonalInfoServiceStub stub = new PersonalInfoServiceStub();
GetContactInfo atn = new GetContactInfo();
atn.setPersonID(1);
GetContactInfoResponse c = stub.getContactInfo(atn);
System.out.println(c.get_return()); //returns null
// The Java Class that serves as the basis for the web service works well...
PersonalInfoService s = new PersonalInfoService();
System.out.println(s.getContactInfo(1).getStreet()); //returns main street
This is all very new for me (I am still pretty dependent on following the tutorial) so I am not sure what might be causing this issue or how I might go about debugging what's wrong. What might be causing the problem and how would I go about debugging it?
If I try to call the webservice in the broswer using this url:
http://localhost:8080/axis2/services/PersonalInfoService/getContactInfo?personID=1
I get this
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ns:getContactInfoResponse xmlns:ns="http://webservices.com">
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns:getContactInfoResponse>
It looks like your client code is okay. The response from the server just doesn't contain any data. The simplest explanation is that the server sent back a response without any data. If I were you, I'd troubleshoot the server's behavior when it receives this request, rather than focusing on the client code.
I would start with Wireshark or tcpdump, this will help you capturing Network traffic that will help you debug at application and transport level what your Java code is generating and the response from server.

Categories

Resources