Ktor Framework using content negotiation with framemaker - kotlin

New to Kotlin and Ktor. I generated Ktor app using both Jackson Serialization and Framemaker. I allowed sample code to be included.
Using Chrome browser and accessing the endpoint returning text worked fine. The other endpoint returning html returned json instead???
I noticed that if i remove the install of the Content Negotiation plugin, html is returned correctly.
Am i correct in assuming that i cannot mix the use of the Content Negotiation plugin and endpoints that also return html?

Related

API requires HMAC authentication JMeter

I am getting error when setting up API test in Jmeter, same is working fine in POSTMAN.
Using HMAC authentication.
I have some basic knowledge of Jmeter new to the tool.
https://developer.firstdata.com/marketplace/api/authentication.html?shell#authentication.
Postman Pre-request Script
And Postman Header details
Postman API response is working fine.
Same as been work in Jmeter but I' getting response message as {"message":"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication"}
I have added JSR223 PostProcessor and HTTP Header Manager.
and here are the details for both image attached below.
** JMeter - JSR223 PostProcessor**
JMeter HTTP Header Manager
Copying and pasting code from Postman won't work in JMeter because:
Postman is a browser extension and is capable of executing JavaScript and according to JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
If you're trying to run JavaScript code you need to choose the appropriate language from the dropdown
JMeter doesn't include CryptoJS library, you will need to download it and load before running the JavaScript
Since JMeter 3.1 it's recommended to use Groovy language for scripting as this option provides maximum performance especially when it comes to "heavy" cryptographic operations so I would recommend re-writing your code in Groovy
I see you like screenshots so I include an example implementation as a screenshot here:
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

How to consume an octet stream from protected endpoint using vue-pdf a vuejs implementation of pdfjs

I want to use the vue-pdf library that is an implementation of pdfjs for vuejs 2.x in order to do the following
Download a PDF from an oauth2 protected endpoint using axios
Render the PDF (octet-stream) using vue-pdf library
and the tricky parts are
Access protected resources
Render PDF that comes as octet stream
Currently there are no examples in the repo to show case these.
After fiddling around with the library, I managed to do achieve the rendering of a pdf from a protected endpoint using the following approach
Make an axios ajax request for the protected resource using necessary auth header and the response type as responseType: 'blob'
Magically create a URL from the downloaded blob object
Set the blob URL in a data variable that is then used by <pdf> component
I have created a Pull Request to the vue-pdf repository with a working example. In the PR replace the URL of axios request with a REST endpoint that returns an octet-stream and you should be all good.
The resulting pdf viewer shown below

how does alamofire know when there is a change in a JSON online?

im working on an app which fetches json from a website. everything is working properly and im using alamofire .
but for some reason, when i post new content on the website and the json file changes, alamofire doesnt get the new content. instead, it loads the content from the cache instead of redownloading the new content.
the only workaround to this is to clear the cache which is a way that i do not prefer since the user will have to download the content all over again at each view load.
so what im asking is, is there a way to notify the alamofire method about the new content and try to load the new content instead of having me to implement a method to clear the cache?
Alamofire uses the Foundation URL loading system, which relies on NSURLCache. The cache behavior for HTTP requests is determined by the contents of your HTTP response's Cache-Control headers. For example, you may wish to configure your server to specify must-revalidate:
Cache-Control: max-age=3600, must-revalidate
You should also make sure your server is specifying ETag and Content-Length headers to make it easy to tell when content has changed.
NSHipster's writeup on NSURLCache has a few good examples. If you're totally new to web caching, I recommend you read the very helpful section 13 of the HTTP 1.1 spec, and possibly also this caching tutorial.

W3C validator and HTTPS

I'm currently having trouble with the W3C markup validation service https://validator.w3.org and the use of HTTPS. When I type in there the website address with https I get the following response:
Sorry! This document cannot be checked.
Together with an error 500 saying that it can't connect to the site. Also, on the website page I have one link which carries the person into the validation and shows the site has been validated. When clicking the link without HTTPS everything works, but with HTTPS I get one message
Sorry! This document cannot be checked. No Referer header found!
which I believe is because the secure connection doesn't send the referer header right?
Now, how can I use HTTPS and avoid these problems with the validation?
Please always directly use https://validator.w3.org/nu/ (the current W3C HTML Checker) instead of https://validator.w3.org/ (the legacy W3C Markup Validator).
The HTML Checker is able to check documents at https URLS just fine. So If you find a https site that it doesn’t work with as expected, then that’s likely a bug I need to fix. (I maintain the checker, and recently updated it to get HTTPS support using HTTP Components HttpClient 4.4 —the latest Apache HTTP client library—including full support for HTTPS sites that use SNI.
A note about which W3C tool to use for checking HTML documents
On the W3C backend, when you use the https://validator.w3.org/ legacy Markup Validator to check documents with <!DOCTYPE html> doctypes, it just hands off the request to the same backend that directly drives the https://validator.w3.org/nu/ HTML Checker. But the HTML Checker has a UI with more features, and using it from https://validator.w3.org/nu/ is faster.
We (the W3C) plan to swap those two around eventually—that is, move the current HTML Checker to https://validator.w3.org/ and move the legacy Markup Validator to https://validator.w3.org/legacy/ or some such—but it will be a while yet before that happens. So in the mean time, as I said, I suggest always just doing all your HTML checking from the https://validator.w3.org/nu/ site.
There seems to be a bug in the W3C NU validator, so the "referer" value is not processed fully. :-/
I.e. the code for their badge <a target="_blank" href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" title="Valid XHTML 1.0 Transitional" style="height: 31px; width: 88px;" /></a>
does not validate my nested sub-page, but just the root-page of the whole web-site instead, on click on the badge, in a footer of the deep sub-page. Sad. :-/
And the same for the alternative parameterized .../check?uri=referer" URL, still the same issue. :-/

What is the path to signalr hubs when using ElmahR?

I am trying to add some custom functionality to ElmahR dashboard page and having some issues. I have started a new project, added ElmahR dashboard NuGet package. Configured all source applications and it is all working fine as expected.
Now I want to add some custom functionality to the dashboard page. As part of this I needed to add some UI to the dashboard page, a new Hub, JavaScript etc. The custom functionality is not related Error Logging. It is completely different. It is something we would like it to add to the dashboard page. I have added new Hub, JavaScript, HTML markups but it doesn't work as expected.
I ran into the following issues:
When i try to access /signalr/hubs, I get 404 Not found error. I searched online for this error and it usually happens if you haven't configured the Hub route. I tried to add RouteTable.Routes.MapHubs() in global.asax file. However it says that A route named 'signalr.hubs' is already in the route collection. Makes sense because I am using ElmahR and because it relies on SingalR, it would have already added it to the route collection. So what is the path to /singalr/hubs in ElmahR application? When using signalR in your standard asp.net application, the usual path to hubs is /signalr/hubs but what path is it when using ElmahR?
I am getting JavaScript error "Uncaught TypeError: Cannot read property 'client' of undefined" at the line where I am trying to access hub.client. I guess it is failing because it is not able to find the new hub that i added.
Everything works fine if I copy the hub, associated JavaScript and HTML to a different ASP.NET MVC project. For some reasons it does not work with the Project that uses ElmahR. I know there is nothing wrong with the code in Hub and JavaScript as it works fine with a standard ASP.NET MVC project. Basically all I want to do is to add a singalR hub to a project that uses ElmahR. Also I can't seem to figure out the URL path to Hubs in an application that uses ElmahR. Usually the path is /signalr/hubs
UPDATE:
After further investigation, I figured the path to hubs in ElmahR dashboard application. It is /signalr101/hubs. However when requesting this, it errors: "Uncaught Error: SignalR: JavaScript Hub Proxy generation has been disabled". It appears that ElmahR would have disabled JavaScript proxies, probably by setting DisableJavaScriptProxies property of the application's IConfigurationManager to true (https://github.com/SignalR/SignalR/pull/1222). I think because of that I am getting "Uncaught TypeError: Cannot read property 'client' of undefined in my JavaScript at the line where it is trying to access hub.client. If the JavaScript proxy is disabled, then is there any extra work I have to do in my JavaScript and Hub so that I don't get this JavaScript error.