I am trying to use GWT to download the source code of web pages, but i do not know where to start, can anyone gives me some key word that i can search on google, or gives me some links from tutorials.
Thanks!!
In JavaScript, this is typically done with an XMLHttpRequest. GWT's analog to XMLHttpRequest is RequestBuilder, which can be used like so:
new RequestBuilder("GET", "http://example.com/page.html").sendRequest("", new RequestCallback() {
#Override
public void onResponseReceived(Request request, Response response) {
String src = response.getText();
// do things with the source
}
#Override
public void onError(Request request, Throwable throwable) {
// handle the error
}
});
Some GWT manual about cross-site scripting
https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite
And here some discussion about using RequestBuilder and JSNI
GWT RequestBuilder - Cross Site Requests
As alternative you can do a page download on the server-side...
Related
I am exploring/learning Spring security modules by implementing it through REST API.
To test the impact, we are using Postman native application as a rest client.
#RestController
#RequestMapping("/auth")
public class Employee {
#GetMapping("/status")
public ResponseEntity<String> getStatus()
{
ResponseEntity<String> responseEntity = new ResponseEntity<>("Resource is fetched", HttpStatus.OK);
return responseEntity;
}
}
above is a piece of resource for sake of consumption.
and below is the code snippet to configure Authentication and authorization
#EnableWebSecurity
public class AppSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("ashish").password("{noop}admin").roles("USER")
.and().withUser("foo").password("{noop}foo").roles("ADMIN");
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/auth/status").hasRole("ADMIN").and()
.formLogin()
;
}
#Bean
public PasswordEncoder getPasswordEncoder()
{
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
now above authorization code is working fine when tried in browser - it uses its default spring login page.
however i am not quite able to understand how to execute/test the same through postman.
in method protected void configure(HttpSecurity http) , i tried removing formLogin() it did not work.
i added httpBasic - it also did not worked.
in postman, basic authentication is used by me.
while searching on internet, i came across some really good articles but almost all of them uses some sort of UI technology like angular or thymleaf to demonstrate the concept which i am finding hard to grasp.
I am referring below video tutorials to learn spring security.
https://www.youtube.com/watch?v=payxWrmF_0k&list=PLqq-6Pq4lTTYTEooakHchTGglSvkZAjnE&index=6&t=0s
Thanks in advance!
Ashish Parab
Do a GET request http://localhost:8080/login via postman and it will return you an html. Extract the _csrf token from the response. It will look like
<input name="_csrf" type="hidden"
value="1c470a6c-dff3-43aa-9d08-d308545dc880" />
Do a POST request as follows to http://localhost:8080/login, copying the _csrf token, username and password as form params
Take note of the JESSIONID Cookie value in the response from step two. And that is the session Id of the authenticated session.
As long as you sent the JESSIONID in subsequent requests as a cookie, spring security knows who you are. Postman will add that Cookie automatically to subsequent requests.
you can add it manually as header with that cookie header or update the postman settings to always send JESSIONID cookie
You will have to implement JWT token for the same and add it to the request header 'Authorization' in Postman. You can take a look at Java Brains Spring security videos on youtube.
What do we need : How to execute a external POST request on any page?
Why do we need : We are developing a secured intranet portal using Adobe CQ for our client. Any request for any page of Adobe CQ of intranet portal redirects to client's interface. This is an external system which generates a TOKEN and sends this token to CQ as an request parameter via HTTP request with POST method.
We set our cookies based on this token which needs to be part of every page. ( We are using page component inhertiance and setting them on root level)
Need suggestions on how this can be achieved. Let me know if more details are needed.
You can defined what method your servlet accepts, so the GET can be handled with a JSP and the POST with a SlingAllMethodsServlet.
#Component(metatype = false)
#SlingServlet(resourceTypes = "cq:Page", methods = "POST", generateComponent = false)
public class MyPOSTServlet extends SlingAllMethodsServlet {
#Override
protected void doPost(final SlingHttpServletRequest request,
final SlingHttpServletResponse response) throws ServletException,
IOException {
//your logic here
}
}
This should get triggered for all pages.
Regarding your comment below your question, never have a servlet path with /content. Either a fixed virtual path like /bin/myservlet or a resourceType.
Check the documentation from Sling: https://sling.apache.org/documentation/the-sling-engine/servlets.html
I'm trying to implement a browser auto-complete feature for my application Login view. However it seems that the only solution is through FormPanel. The problem with this is that it is intended to be used with standard servlet; in this case I will need to rewrite my "login" code, since what I have is Login RPC. Is there a way to do browser login form auto-complete with using GWT RPC for the Login service?
EDIT:
I tried this code:
FormPanel form = FormPanel.wrap(Document.get().getElementById("login-input"), true);
form.setAction("javascript:;");
form.addFormPanel(new FormPanel() { // EDIT: method undefined?
public void onSubmit(FormSubmitEvent event) {
// do some validation before submitting (non-empty fields)
// and call event.setCancelled(true) if needed.
// get the fields values and do your GWT-RPC call or
// RequestBuilder thing here.
}
public void onSubmitComplete(FormSubmitCompleteEvent event) {
// will never be called.
}
});
However, form.addFormPanel method is undefined.
It's possible with GWT-RPC too (but you still need the FormPanel for similar <form>): https://groups.google.com/d/msg/google-web-toolkit/KyzgtqqoJGE/5bqvG8pBSRYJ
According to GWT FormPanel Javadoc :
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/FormPanel.html
replace form.addFormPanel with :
the deprecated method form.addFormHandler
which is now replaced with
form.addSubmitCompleteHandler and form.addSubmitHandler
I'm having trouble with making HTTP Requests using GWT 2.4 (and JQueryMobile jquery.mobile-1.0rc1.min.js, but not for anything related with the calls) on Phonegap 1.1.0. What I want to do is to use the POST method on another server in order to receive content and display it.
On the desktop it's working fine (thanks to a reverse proxy configuration). On Phonegap, I read that "the cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply.". However, it seems that the request is never made on the phone, as the response is empty and the status code 0 - a similar behavior that I experienced before I solved the cross domain issue on the desktop.
I'm using the regular RequestBuilder on GWT to send my requests. Any ideas on why this is happening? All the permissions on Phonegap are active.
edit: Here is my Java code that sends the request, from which I omitted my soap envelope:
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,url);
rb.setHeader("SOAPAction", "assertIdentityWithSimpleAuthentication");
rb.setHeader("Content-type", "application/x-www-form-urlencoded");
String envelope = "etc"; //this is my soap envelope,
try{
rb.sendRequest(envelope, new RequestCallback() {
public void onError(Request request, Throwable exception) {
requestFailed(exception);
}
public void onResponseReceived(Request request, Response response) {
if(response.getStatusCode() == 200){
String aid = Tools.parseMessage(response.getText(),"assertionId"); //this just parses the response in order to get the string I need
Window.alert("Sucess: "+ aid);
sendAssertionID(aid); //and sends it to another function
}
else setError(response);
}
});
}
catch (RequestException ex) {
requestFailed(ex);
}
Check your url. Your code works fine on my android devices, but fails with an invalid url with code 0.
It needs to start with http:// or https://
I want to navigate away from my GWT app using a POST request. If it was a GET I could just use Window.Location and if I didn't need it to be dynamic I could hardcode a Form and submit it. The FormPanel seems to be the answer for creating and submitting forms, but it does it asynchronously, and I want the user's browser to follow the form submit, navigating away from my app, rather than just displaying the results.
Anybody know how to do this in Google Web Toolkit?
Ok, got it!
Passing null to the String constructor of the FormPanel effectively says "replace the current page":
new FormPanel((String)null);
This forum thread was useful:
http://www.coderanch.com/t/120264/GWT/GWT-HTTP-post-requests
Havn't done this myself but I think you should be able to create a FormPanel and then cast its element to FormElement and call submit on the FormElement.
FormPanel formPanel = new ...
FormElement form = FormElement.as(formPanel.getElement());
form.submit();
I thought your FormElement idea would work, but unfortunately it still sends it async. Both the following successfully send a request and get a response, but alas, the page doesn't change.
_tmp.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event_)
{
doPost();
}
public native void doPost() /*-{
var form = document.createElement("form");
form.setAttribute("method", "GET");
form.setAttribute("action", "http://www.google.com");
document.body.appendChild(form);
form.submit();
}-*/;
});
and
public void onClick(ClickEvent event_)
{
final FormPanel form = new FormPanel();
form.setAction("http://www.google.com");
form.setMethod(FormPanel.METHOD_GET);
RootPanel.get("main").add(form);
FormElement formElement = FormElement.as(form.getElement());
formElement.submit();
}
I realize that I've used GET methods in my examples above. This is purely because Google only accepts GET. I had the same result trying POST on my own servlets.
There must be a way of doing this.