We are using #aspnet/signalR library in our angular application. Is there a way to set the query string property so that querystring sent with all the signalR requests ? Similar to how we can do in jquery using $.connection.hub.qs.
You should be able to add the querystring as part of the connection url and it will persist across requests.
let connection = new HubConnectionBuilder()
.withUrl("http://app/hubroute?customQS=1")
.build();
Related
Could you please help me with the code snippet which will help to determine whether netflix zuul is redirecting request to appropriate service.
I am using spring boot & zuul 1.x.
RequestContext.getCurrentContext().getRequest().getRequestURI().toString(); gives me the url which is initiated by browser client, however I am not able to figure out how to make sure zuul is redirecting this request internally to proper service.Which will help in testing without running the actual service.
Thanks,
Shekhar
try looking at the source code of pre-decoration filter, basically what it does is determines where and how to route based on the supplied. Also sets various proxy related headers for downstream requests
context = RequestContext.getCurrentContext();
request = context.getRequest();
call the getRouteHost method on context object it will give you all the route related information like protocol, host, port etc..
RequestContext.getCurrentContext().getRouteHost();
to get the uri call getRequestURI on request object
request.getRequestURI()
NOTE: the problem you might be having was the order of your filter, since preDecorationFilter has order of 5
#Override
public int filterOrder() {
return PRE_DECORATION_FILTER_ORDER;
}
which is actually 5 (as far as i remember), make sure your filter order is greater than 5, i tried with filter order 7 and everything is working as expected, put your intelligence code in the run method()
A product I've inherited is using WebClient to read HTML from a MVC based site. Each page is a different type of e-mail, so in order to compose and send an e-mail they use WebClient to request a URL and download the string.
var outputHtml = string.Empty;
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
outputHtml = client.DownloadString(emailURL);
}
return outputHtml;
Is there a way to remove the need to host this email based site but retain most of this code. I guess what I need to do is pass my request to the controller and retrieve the output after the razor engine has passed the view model through the cshtml page.
Is that possible?
There are many ways you could render a Razor view to a string. One possibility is to use RazorEngine. Another possibility is to use some specifically designed framework for this purpose such as Postal.
I'm developing an api that post a simple class to a database and i'm using asp.net web api and Ninject. Clients of this api, are making this api a request with headers
username: xx and password: yy
So every in every method i have to check if username and password is correct. I know this is not true way to do that i can use BasicAuth. OAuth exc. but i have to in that way.
My question is, it is possible that i can inject the logic of reading request header to a gloabl variable so i can stop repating myself.
The simple logic that i'm using:
[HttpPost]
public HttpResponseMessage Post(Sale saleRecord)
{
var request = HttpContext.Current.Request;
var username = request.Headers["username"];
var password = request.Headers["password"];
if(username=="xx" && password=="yy")
{//Logic here}
}
In Mvc we can override OnActionExecuting() method and check those headers but in web api i cant override it.
What is the best practice for this?
You can do Action Filters like in MVC in web api too and solve reading common and header info from the request.
https://damienbod.wordpress.com/2014/01/04/web-api-2-using-actionfilterattribute-overrideactionfiltersattribute-and-ioc-injection/
I am not very familiar with Ninject but in the above article it does show how to do IoC for Action filters , I use Structuremaps and I do through property injection in case of Action Filters/Attributes.
MVC4 provides a very simple way to return serialized objects from HTTP requests. What's the best way to call a REST or other JSON/XML API from an MVC4 application? I could construct an HTTP request, send it, then deserialize the result, but I was hoping for something simpler. My application runs on multiple servers and one server needs to talk to the other via the web API. So, both servers have the same class definitions. I'm hoping there is some fairly transparent way to get MVC to deserialize as cleanly as it serializes content.
This is an example of how I call an MVC4 WebAPI from a WPF application. You should be able to adjust according to your needs. Hope this helps...
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://192.200.1.3:9594/");
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("EmployeeTest/TestApi");
if (response.IsSuccessStatusCode) {
var employee = response.Content.ReadAsAsync<Employee>().Result;
tbName.Text = employee.Name;
tbPhone.Text = employee.Phone;
}
after many days of search and many unsuccessful tries, I hope that the community knows a way to achieve my task:
I want to use grails as a kind of a proxy to my solr backend. By this, I want to ensure that only authorized requests are handled by solr. Grails checks the provided collection and the requested action and validated the request with predefined user based rules. Therefore, I extended my grails URL mapping to
"/documents/$collection/$query" {
controller = "documents"
action = action = [GET: "proxy_get", POST: "proxy_post"]
}
The proxy_get method works fine even when the client is using solrJ. All I have to to is to forward the URL request to solr and to reply with the solr response.
However, in the proxy_post method, I need to get the raw body data of the request to forward it to solr. SolrJ is using javabin for that and I was not able so far to get the raw binary request. The most promising approach was this:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(solrUrl);
InputStream requestStream = request.getInputStream();
ContentType contentType = ContentType.create(request.getContentType());
httpPost.setEntity(new ByteArrayEntity(IOUtils.toByteArray(requestStream), contentType));
httpPost.setHeader("Content-Type", request.getContentType())
HttpResponse solrResponse = httpClient.execute(httpPost);
However, the transferred content is empty in case of javabin (e.g. when I add a document using solrJ).
So my question is, whether there is any possibility to get to the raw binary post content so that I can forward the request to solr.
Mathias
try using Groovy HttpBuilder. It has a powerful low-level API, while providing groovyness