I have a string variable in my Java application that is being built by Jenkins. After Jenkins build is done, it sends a notification to our internal messenger. I need to include this Java string into the notification message. This string is not constant. It is dynamic and depends on the response that is being returned by a request that is handled in Java app.
Currently, the notification message consists of a build's metadata - status, build number, job name. These values are taken by Jenkins by getting the values of respective environment variables.
How can I get in Jenkins the value of the Java string variable?
According to our previuous comments, I guess you need to do something like this:
Create an API in your Java App: this API needs to publish an operation with the parsed response (the one which gets the 3rd service response).
Call this API from Jenkins, with, for example, a curl (you can do it with Groovy if you want to), something like this (assuming you return a json response):
//The next http://yourdomain... URL is the one your Java app will expose with your parsed response
def response = sh script: "curl 'http://yourdomain/api/v1/yourResource'", returnStdout: true
def jsonProcessed = readJSON text: response
//Do some post-process in Jenkins if you need to using readJSON. I just put a dummy raise error example (Check the readJSON link below)
if (jsonProcessed.key == 'whatever') {
error "Raise some error"
}
// Or directly the code to send the response to the messenger
// TODO Your sending code HERE
Send the response from Jenkins to your messenger.
Help with readJSON
Hope it helps.
Related
I am triggering the AWS SNS through the API Gateway.
JSONObject requestBody = new JSONObject();
requestBody.put("phone_number", receiverNumber);
requestBody.put("sender_id", senderAlias);
requestBody.put("message_text", messageText);
This JSONObject is being sent to the api gateway as a ByteArrayInputStream throug the AWS SDK for Java v1.
There are "\n" in the text, to create line breaks. The sms however does not have a new line there, it just prints \n.
In the Api Gateway the message is extracted like this: method.request.body.message_text
How do I have to set up the messageText variable to print new lines in the SMS? I tried replacing it with \n or \\n or \\\\n.. Also tried ASCII, didn't work.
Invocation
As this is a quite complex programm I can't show all of it. It's triggered via Insomnia with a String in Json format like this:
It has to be a double backslahed n because thats just how the code needs it. The aws integration is an additional provider so it has to fit in already existing frames. The json object looks like this before being executed.
So I need to find a way to manipulate the string thats going in the object. But I don't know how.
EDIT 3:
Deleting previous edits, as they were not helpful and did not target the problem as I know now.
Finally closing down the issue. It's a problem in the API-Gateway. The object reaches the gateway just fine, with a \n. Which would work in the SNS Service. But to trigger the SNS Service, it's all going into one URL, which converts the \n into %5Cn
Before transformation:
URL:
So the problem is in the URL encoding..
Thanks to the AWS Support I now am able to send SMS with line breaks through the api gateway.
It was wrong to use URL Query Parameters. I removed all of them
I needed one HTTP Header:
Content-Type: 'application/x-www-form-urlencoded'
Then I used a Messaging Template like this, with passthrough: Never:
#set($message = $input.path('$.message_text'))
#set($phoneNumber = $input.path('$.phone_number'))
Action=Publish&PhoneNumber=$util.urlEncode($phoneNumber)&Message=$util.urlEncode($message)&MessageAttributes.entry.1.Name=AWS.SNS.SMS.SenderID&MessageAttributes.entry.1.Value.DataType=String&MessageAttributes.entry.1.Value.StringValue=Alias
Having my JSON Object in the Request like this:
{
"phone_number": "+4912345678",
"message_text": "Break\nHere",
"sender_id":"Alias"
}
Works perfectly fine with a line break in the SMS
I am trying to make a local Java program run in AWS Lambda and make it such that it can be called with a HTTP request. All I need is just to be able to duplicate the functionality of running java locally from the command line through HTTP in AWS so other people in the company can run the code by just sending a HTTP request in Postman(for now, next step is a web form that just makes the request) instead of downloading the jar and launching the Java command line.
I went through the hello world tutorial in the Amazon website and was able to adapt my code, and run it successfully using the test function in the AWS Lambda control panel. I am also able to see the logs in cloudwatch that it ran and also observe the results. So it all works from the Lambda control panel test function.
So instead of command line arguments, I'm giving the arguments in JSON format as follows:
{
"environment": "dev",
"username": "Test",
"password": "Test22",
"storeId": "TESTMA0001",
"data": "a,b,c,d"
}
And this works quite well when invoking the lambda from the test function.
However I want to be able to enter this in the body of a HTTP request and have my lambda run so I added an api gateway through the gui in the aws lambda panel, chose HTTP API kind and default options.
Then I send a HTTP GET request to the api endpoint with the body being the same input I used in the testing panel, but whenever I run it, I get internal server error. I turned on access logs for the gateway api, and I get the following, my lambda is not being launched by the api since there is no lambda log being written when I use the API, it gets written when I launch it from the AWS lambda web panel.
{
"requestId": "KByVuheeoAMEPLA=",
"ip": "",
"requestTime": "27/Mar/2020:02:25:40 +0000",
"httpMethod": "GET",
"routeKey": "$default",
"status": "500",
"protocol": "HTTP/1.1",
"responseLength": "35"
}
My handleRequest function takes a string, string map as input and returns a string as output:
public class StoreCategoryImporter implements RequestHandler<Map<String,String>, String> {
#Override
public String handleRequest(Map<String,String> event, Context context)
I don't even use the context object but it was there in the tutorial so it remained.
I googled for hours and I have not been able to find a solution, any help would be appreciated. I find most AWS tutorials to skip over some crucial details or they don't have it for POJO developers and use js which I don't understand.
Thank you in advance.
To simulate API Gateway event for tests in your lambda you, the lambda console has some pre-set values. In your lambda you go to Configure test event and choose the event you want to simulate, e.g.:
Alternatively, you can print out real event in your lambda to CloudWatch logs, and use that for tests.
I have solved this problem by more googling and finding a closer solution. Forget about the AWS tutorial, you need to override the handleRequest(APIGatewayProxyRequestEvent, Context) method, not the one that just takes in a Map(String,String) event as described in the hello world tutorial if you want to be able to trigger your lambda through a HTTP request.
Also, the "configure test event" in the AWS GUI is useless in this case. It cannot parse JSON that isn't a primitive. Probably the CLI would work better.
I am new to jmeter (I am using version 3.3) and I created a test plan with the goal of sending an email on Assertion failure.
in this email I want to add some information about the name of the request and its reason
so I have added and if controller with this condition:
${JMeterThread.last_sample_ok}
a beanshell preprocess with this script:
and an SMTP Sampler with this body:
and a response assertion:
I want to get an email anytime it hits the condition of response code=500 and the info described above.
I got to receive the email on that condition but the body message is literally this:
${body}
this is the assertion result:
what am I doing wrong?
How to get what I need?
Thanks
Your prev variable is not defined in the Beanshell PreProcessor (it exists only for PostProcessor and Listener, I would suggest using ctx.getPreviousResult() instead where ctx stands for JMeterContextService instance.
You also need to enable your HTTP Request GET - posts as this will be this "previous result" you're interested in.
Be aware that starting from JMeter 3.1 it is recommended to use Groovy for any form of scripting so consider migrating to JSR223 PreProcessor and Groovy language on next available opportunity. You should be even able to re-use the same code as I don't see any Beanshell-specific features in it. See Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.
The script is sending an email if the last sampler is ok, therefore the assertion is ok too, so the body variable won't hold any value.
Just adjust your if statement to !${JMeterThread.last_sample_ok}, and then move up your HTTP sampler HTTP Request - POST/articles above the if controller.
This will make your script send an email if the sampler failed and you will have the body variable holding the failure message.
I'm trying to create a simple test plan in JMeter to send data over JMS, using a Publisher and a Subscriber. I've got a Java Request which returns a SampleResult object containing a list of subresults, each containing a String ("Hello, world!" + count), and I want to be able to send these Strings over JMS, but I can't work out how to access them.
Everything is working fine in isolation, but how can I plug the result that my Java Request spits out into my Publisher so it can be sent?
Add a Regular Expression Extractor as a child of your Java Request:
You can then use this in your JMS Sampler:
${data}
I am calling a soap web service in java and I am getting an attachment in response I get the name of the attachment and I want a java code to download and save that file to a specific location in my local machine ... Thank You
If have access that service in local machine you can access, but you have logon to particular remote server to download the file.
If you got any attachment response for file you can easily download the file by using below code
if(attachmentsResp!=null)
{
for(int j=0; j<attachmentsResp.length; j++)
{
if(attachmentsResp[j].getContent()!=null)
{
//getting the file to particular Driver Name(C drive ,D drive)
OutputStream out = new FileOutputStream("Driver Name:"+attachmentsResp[j].getName()+"."+attachmentsResp[j].getFileType());
}
}
}
If you want decode to file download let me know.
1. Login to the server by providing the server url and authentication credentials.
2. Create the request object GetFileAttachmentRequestType for the getFileAttachment operation
3. Create an array of requests of type SoapGetFileAttachmentRequestType. Batch operations may be
4. performed by populating as many request objects as required to retrieve several files
5. with one single operation.
6. For each batched request, specify the unique object from whose attachment tab
7. files shall be retrieved. Supply class identifier and object number information
8. for the same.
9. The exact specification of the attachment to be downloaded is defined as an
10. object of type SoapFileAttachmentRequestType. This object includes information
11. about rowId, a boolean to indicate whether all the files of the object are to
12. be downloaded and finally provision for fileIds to be used in special cases.
13. In this sample the boolean element 'allFiles' is set to true. By using this
14. option, the necessity to derive rowIds or fileIds is negated. The response
15. object will consist of all the files present in the attachment tab of the
16. soap object specified in the request.
17. The request objects are set and the soap Stub is used to make the getFileAttachment
18. webservice call. The status code obtained from the response object is printed to
19. verify the success of the getFileAttachment operation.
20. If the status code is not 'SUCCESS', then populate the list of exceptions
21. returned by the webservice.
22. If the webservice call was successful, then display information about the file(s) retrieved.