I am currently using Iron Router. In my Template file I am retrieving the url through
var url = Router.current().url
or
var url = Router.current().originalUrl
These returns the current path without the protocol and hostname.
/your/current/path
However, when you refresh the page (browser refresh), the same methods return the whole url (protocol, hostname and path).
http://localhost:3000/your/current/path
How do I retrieve the whole url or route path reliably?
You can use Iron.Location object for that here are few property that you can use
Iron.Location.get().rootUrl --> 'http://localhost:3000'
Iron.Location.get().path --> '/your/current/path'
Iron.Location.get().port --> 3000
Iron.Location.get().protocol --> 'http:'
Iron.Location.get().queryObject ---> return query object
Iron.Location.get().hostname --> 'localhost'
Iron.Location.get().host --> 'localhost:3000'
Meteor.absoluteUrl() will give the root url as well.
Related
there. Am using GWT(2.8) in a production env and we have a requirement to add(vendor service-DOMO reprots) url as an Iframe . I used the below code and its giving me "refused to connect" error in browser, but loading it a new window works fine . Iframe fails due to SOP issue.
protected Widget createWidget() {
final Frame frame = new Frame();
frame.setUrl(domoURL);
VerticalPanel panel = new VerticalPanel();
panel.setWidth("100%");
panel.add(frame);
DOM.setStyleAttribute(panel.getElement(), "backgroundColor", "white");
return panel;
}
I understand that there is a CSP policy issue and GWT/browser is refusing to load the other domain as an Iframe. How do i handle this case ?
How do i whitelist the domain (url) am trying to use it anywhere in GWT ?
I tried the below solutions but it did not help
Added linkers in module.xml
<inherits name="com.google.gwt.core.Core" />
<add-linker name="xsiframe" />
<add-linker name="direct_install" />```
2. Tried overriding the setUrl funtion of iframe.
3.Added csp directives as mentioned in (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-src) the http filters.
4.Added meta tag with CSP directives
5.Added CORS policies in tomcat web servers to allow external domains
I want to configure my proxy in the following fashion.
All requests by default get passed through to http://main.api.com
Any request that has has a URI path that start /admin gets routed to http://admin.api.com
<RouteRule name="mocker">
<Condition>(proxy.pathsuffix JavaRegex "^/admin/?.*$")</Condition>
<TargetEndpoint>MockTarget</TargetEndpoint>
</RouteRule>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
This partially works in that it does indeed route to a different host. However, it maintains the path; so requesting /admin/foo/bar gets redirected to http://admin.api.com/admin/foo/bar, but I wanted it to go to http://admin.api.com/foo/bar
How can I achieve that?
You will have to set target.copy.pathsuffix to false in the Target PreFlow. This will ensure that the path from Proxy is not copied to the Target.
You can easily do this by adding a Javascript policy on the Target Preflow with the code
context.setVariable("target.copy.pathsuffix", false);
i'm working with Pentaho Data Integration and i need a step which gives me a response header of a http request. What i would really need is an implementatione of the HEAD Method of a http call because i have to see the last-modified field of a resorce on internet. I tried using the REST Client step but it doesn't work. So i would like to write a script that makes everything i need.
I actually created a Modified Java Script Value and i put this code inside:
var req = new XMLHttpRequest();
req.open('GET', 'URL', false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
When i run it it doesn't gives me any error but there's anything in "headers".
Any suggestions? I would appreciate a different solution to
If the URL you're requesting is on a different domain then I can tell you that the server is not sending the correct headers to allow cross-domain resource sharing.
Access-Control-Allow-Origin: *
Without the server sending that header the only way to access any of the response (including headers) is if your script is running on the same domain (and protocol) or if you setup a proxy on your own server to get the data from the remote server.
If I open up the JS console on this page and run:
var req = new XMLHttpRequest();
req.open('GET', 'http://dati.toscana.it/it/storage/f/2012-07-26T160139/intoscana-arte-e-cultura.csv', false);
req.send(null);
console.log(req.getAllResponseHeaders());
I get the following output:
XMLHttpRequest cannot load http://dati.toscana.it/it/storage/f/2012-07-26T160139/intoscana-arte-e-cultura.csv. Origin http://stackoverflow.com is not allowed by Access-Control-Allow-Origin.
NetworkError: A network error occurred.
But if i put an alert in the end:
var req = new XMLHttpRequest();
req.open('GET', 'http://dati.toscana.it/it/storage/f/2012-07-26T160139/intoscana-arte-e-cultura.csv', false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);
it gives me the response.
It gives me this too:
Error: Failure
req.send(null);
I'm using Firebug.
I had a similar problem. In my case was to detect a redirection, something that could happens in services that uses third part storage (like Amazon S3). First time I tried with XMLHttpRequest but apparently that is not implemented in the JavaScript available in Kettle, just in browsers. To workaround this, I follow the instructions from http://type-exit.org/adventures-with-open-source-bi/2010/06/using-java-in-pentaho-kettle/ to reference another Java Class, mentioned in http://www.mkyong.com/java/how-to-get-http-response-header-in-java/, inside a Modified Javascript Value Step. The limitation is that you need to do a primary request to get the header, it is not a "just one request" solution.
//Get the location of a link that has a 301 permanent redirection
var pathurl=documentourl; //URL to lookup. It must be a valid address, otherwise will give error
var location; //final location in case of redirect
//fake import of the Java Classes
var HTTPRequest=javax.servlet.http.HttpServletRequest;
var url=java.net.URL;
//open a url connection
var conn= new url(pathurl).openConnection();
//if you yant to watch all the headers uncomment the following lines
//var headerobj= conn.getHeaderFields();
var status=conn.getResponseCode(); //get status code
if (status == 301){ //ie: permanent redirection
location=conn.getHeaderField("Location");
}
else{
//return the same url
location=pathurl;
}
I hope it helps to anyone with this problem!
Using ASP.Net is it possible to rewrite to a different domain using HttpContext.Current.RewritePath? Eg.
HttpContext.Current.RewritePath("http://www.otherdomain.com");
When I try this I get the following exception:
'http://www.otherdomain.com' is not a valid virtual path
HttpContext.Current.RewritePath is rewriting of the url on the server side.
It means that if you request the url /products you can tell to asp.net to rednder /Products.aspx by using:
if( HttpContext.Current.Request.RawUrl == "/products")
HttpContext.Current.RewritePath("/Products.aspx");
if you want to send the user to another domain you need to do:
HttpContext.Current.Response.Redirect("http://www.otherdomain.com/page");
I am new to asp.net and c#. I have set a query string to pass the value to one page to another along with the url path. But once go to this page I will not be able to redirect to any other page.
Here is my code:
Uri url = System.Web.HttpContext.Current.Request.Url;
string urlString = "http://" + url.Authority + "/Projects/SearchResult.aspx/?Keywords=" + TxtSearch.Text;
Response.Redirect(urlString);
Here is the error:
The resource cannot be found. Description: HTTP 404. The resource you
are looking for (or one of its dependencies) could have been removed,
had its name changed, or is temporarily unavailable. Please review
the following URL and make sure that it is spelled correctly.
Requested URL: /Projects/Description.aspx/NewPost.aspx
The error is simply indicating the your URL in wrong - the reported url /Projects/Description.aspx/NewPost.aspx anyway appears to be wrong - it should be either /Projects/Description.aspx or /Projects/NewPost.aspx.
As your code is redirecting to completely different page (/Projects/SearchResult.aspx), you should check that page code for above redirect/transfer.
On side note, there are couple of issues in ho you are forming the url:
Query-string is not passed correctly - you have used trailing slash before question-mark i.e. /?Keywords - you should be using /Projects/SearchResult.aspx?Keywords=
Typically, for passing to url within application, you should use ~ as application root - that way, you don't have to worry about host name & root virtual directory (if any). For example, you can write
Response.Redirect("~/Projects/SearchResult.aspx?Keywords=" + TxtSearch.Text);