Print correlation values on console in gatling - console

How can we print the values captured using saveAs("myValue") on the console of gatling, like we do System.out.println() in Java?

Values saved with saveAs, are saved into session :
Docs : http://gatling.io/docs/2.2.0/session/session_api.html#id2
Those values are actually logged into console automatically if you turn logging on in settings: resources/logback.xml
uncomment :
<logger name="io.gatling.http.ahc" level="TRACE" />
<logger name="io.gatling.http.response" level="TRACE" />
With this settings you will see this before each reqest:
Session:
Session(<Session desc.>,5846298469383031361-23,Map(<session vars>),1463134760217,8,KO,List(),<function1>)
Or you have to print your vars in session function:
val printSesssionVar = scenario("print session var").exec{
session =>
println(session("<your session var>").as[String])
session
}

umm good to know. I thought we had to use always brackets after .exec
val printSesssionVar = scenario("print session var")
.exec(session => {
val mySesionVariable = session("your session var").as[String]
println(mySesionVariable)
session
})

Related

413 request entity too large - Web API

I'm running into a 413 issue while trying to send data from my web application (.netfx 4.6.1) to my web api (.net core 3.1). In the code below, I send a list over containing byte data of images along with additional data needed to build a file. The expected output is to return a byte array containing the new file. Unfortunately when sending the request I receive an error: Response status code does not indicate success: 413 (Request Entity Too Large).
The error only seems to occur when the file is large to begin with, which makes sense. The research I've done seems to point to settings in IIS, the main ones being maxAllowedContentLength, maxRequestLength, and uploadReadAheadSize. I've tried increasing these values to ones more suited to this process but nothing seems to work. I've adjusted them for both the web application and the web api, as I was not sure which one was causing the problem.
Where does the problem lie? In the application, the API, or both? Is there an additional setting I'm missing to allow an increased size? Is there an issue with how I'm sending the request? Any help is appreciated.
public static async Task<byte[]> CreatePdfFromImageFilesAsync(List<ImageFile> imageFiles)
{
var list = new List<dynamic>();
foreach (var item in imageFiles)
{
list.Add(new
{
Data = Convert.ToBase64String(item.Bytes),
PageOrder = item.PageOrder,
Rotation = item.Rotation,
Type = "PDF"
});
}
var response = _client.PostAsJsonAsync($"{FileCreatorAPI}/api/files/CreateFileFromMultiple", list).Result;
var result = response.EnsureSuccessStatusCode();
var bytes = await result.Content.ReadAsAsync<byte[]>();
return bytes;
}
Below changes worked for me
// If using Kestrel:
.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
//options.Limits.MaxRequestBodySize = null; --did not worked
options.Limits.MaxRequestBodySize = int.MaxValue;
})
// If using IIS:
.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
//options.MaxRequestBodySize = null;
options.MaxRequestBodySize = int.MaxValue;
});
create web.config file and add following configuration
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
Can you check that attribute https://github.com/aspnet/Announcements/issues/267 ?
Using
[RequestSizeLimit(100_000_000)]
on your controller entry point, or more globally setting it this way:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
EDIT: article from MS: https://dotnet.microsoft.com/download/dotnet-core
I think the problem is on the server. The server is terminating the request because it exceeds it's configured maximum allowable request size.
Which server are you using?
For Nginx users, the directive which determines what the allowable HTTP request size can be is client_max_body_size, the default maximum allowable request size is 1MB.
The limit in Apache is set via the LimitRequestBody directive and defaults to 0 (meaning unlimited) to 2147483647 (2GB).
Check out this article on how you can fix it if you are using any of those two servers.

Why Firebase's getAuth() returns an object with past expiry

Is that possible that getAuth() will return an object with expires in the past?
I was under impression that if expires is in the past, getAuth() will return null. But, it looks like I'm wrong.
Here is how I proved I'm wrong:
var resolve = {
auth: function($q) {
var defer = $q.defer();
var authData = rootRef.getAuth();
if (authData === null) {
...
} else {
var now = new Date() / 1000;
console.log('Authenticated!');
console.log(' Auth expiry: ' + authData.expires);
console.log(' Now: ' + now);
console.log('Is expiry in the past? ' + (authData.expires < now ? 'YES' : 'NO'));
defer.resolve();
}
return defer.promise;
}
};
and here is the output:
Authenticated!
Auth expiry: 1415276774
Now: 1415276804.45
Is expiry in the past? YES
If I refresh the page after getting the above output, getAuth() returns null as expected.
To reproduce the issue I do:
Login using email and password
Close the app (browser's tab) before the login session expires (I experimented with 1 minute sessions, but same happens with other lengths sessions)
Wait until the login session expires
Open the app (at this point the code above runs and produces the output above)
Any ideas?
As Chris mentioned in his comment, this appears to be due to differences between client and server times. The expires time specified in the authentication payload is generated by the server using the server's time, but this is likely to be at least slightly different than the one of your client. The important thing to remember is that the client is indeed expired using the TTL you specified, enforced by the server.
I created a simple example to invoke getAuth() every second, and log the difference between the expiration time and current local time upon each request. When tested across multiple iterations, each one looked as follows:
...
session time remaining: 2.23s
session time remaining: 1.23s
session time remaining: 0.23s
session time remaining: -0.76s
session time remaining: -1.77s
session expired
session expired
session expired
...
In short, the client is immediately notified by the server once the session has expired, but the client's timestamp is a few seconds different, which is why the expiration returned from getAuth() may appear to be in the past.

Using Session with WCF WS2007FederationHttpBinding (WSFederationHttpBinding)

I can't get my values stored in the WCF session when use WS2007FederationHttpBinding. I've seen this topic Session in WCF not consistent, but it didn't help. Moreover, I don't care about reliable session, I just want to store some info in the session and read it at the second request. This scheme works for me with basicHttpsBinding.
Here is my binding. After channel creation I store it to the client Session
var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = true;
binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
binding.MaxReceivedMessageSize = 4000000;
var serviceFactory = new ChannelFactory<T>(binding, new EndpointAddress(serviceUrl));
serviceFactory.Credentials.SupportInteractive = false;
var channel = serviceFactory.CreateChannelWithIssuedToken(token);
Service configuration:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
Session access in the service:
HttpContext.Current.Session["serviceSession"] = "123";
Session retrieval in the service (is always null on the second request but SessionId is the same):
if (HttpContext.Current.Session["serviceSession"] == null) ...
I keep the channel itself in the client session between two requests and reuse it taking from the session for the second request.
Session["clientSession"] = channel;
I beleive HttpContext.Current.Session will only work if you configre asp comptability mode on the service. But even then it will not be correlated with your federation setting. What worked for me is to define the service instance mode as per session:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IService
and then you can use local data members of the service class to persist data between different calls of the same session.

Downloading files from Alfresco with MuleSoft CMIS connector

I have a little problem with the MuleSoft CMIS connector. I have an application that uploads and downloads files from Alfresco. I connect to Alfresco through AtomPub and use CMIS for all actions towards the Alfresco.
The problem is this:
I used to get the object from the repository and it worked fine. In my flow I added one component that takes the object from the flow, which is of type DocumentImpl, get InputStream, cast it to an Object and return it. The browser starts the download of the file but it has no idea what the file is because it has no extension attached to it.
And finally the question: How do I attach the extension to the file being downloaded?
EDIT some code added
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage mes = eventContext.getMessage();
System.out.println("Message is :" +mes);
DocumentImpl doc = mes.getPayload(DocumentImpl.class);
HttpResponse res = new HttpResponse();
InputStream a = doc.getContentStream().getStream();
String m = doc.getContentStreamMimeType();
String n = doc.getContentStreamFileName();
res.setBody(mes);
return a;
}
Ok i solved the problem. Basically the best way to do this is to change the flow to this:
<set-payload value ="#[payload.getContentStream()]" />
<set-variable value="#[payload.getMimeType()]" variableName="mime" doc:name="Variable" />
<set-variable value="#[payload.getFileName()]" variableName="name" doc:name="Variable" />
<!-- Set Content-Type to stored mimetype -->
<set-property value="#[flowVars['mime']]" propertyName="Content-Type" />
<set-property propertyName="File-Name" value="#[flowVars['name']]"/>
<set-property value="attachment; filename=#[flowVars['name']]" propertyName="Content-Disposition" />
this should be in the Mule Flow after
This takes mime type and file name from the payload and returns it!

Basic Auth for WSO2 EI API service

I am using WSO2-EI 6.4.0. I have tried this development with link. It work for me. But I need to get user name and password from other back end service. In this example was showed the hard corded user and password. I have added that code for your reference. Please help me to get those user name and password from property file.
public boolean processSecurity(String credentials) {
String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
String usernName = decodedCredentials.split(":")[0];
String password = decodedCredentials.split(":")[1];
if ("admin".equals(username) && "admin".equals(password)) {
return true;
} else {
return false;
}
}
I have added WSO2 EI handler like following. I need to pass the value from back service or call other sequence and load.
<api context="/test">
<resource methods="POST">
<inSequence>
................
</inSequence>
<outSequence>
................
</outSequence>
</resource>
<handlers>
<handler class="rezg.ride.common.BasicAuthHandler">
<property name="cm_password" value="admin"/>
<property name="cm_userName" value="admin"/>
</handler>
</handlers>
</api>
When we run the above API, handlers are running first and then running in and out sequences. So I need to get user name and password calling Sequence or any other method before run this BasicAuthHandler.
If you need to read the property file from the class mediator it's just straight forward java property file reading. Please refer the following call sample of reading a property file. In this scenario, Just read the carbon.properties file exists in the conf directory.
public boolean mediate(MessageContext context) {
String passwordFileLocation = System.getProperty("conf.location")+"/carbon.properties";
try (FileInputStream input = new FileInputStream(passwordFileLocation)) {
Properties prop = new Properties();
// load a properties file
prop.load(input);
log.info("------org.wso2.CipherTransformation : " + prop.getProperty("org.wso2.CipherTransformation"));
} catch (IOException ex) {
ex.printStackTrace();
}
return true;
}
To get the server location and the conf locating, There are JAVA system properties are set at the time wso2 server starts. Following are some of the useful System system properties.
carbon.local.ip
carbon.home
conf.location

Resources