Skip to content

Commit e75f2a6

Browse files
committed
modified the code style to respect Vert.x code style guidelines
1 parent a644f4f commit e75f2a6

File tree

4 files changed

+129
-115
lines changed

4 files changed

+129
-115
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
trim_trailing_whitespace = true
8+
end_of_line = lf
9+
insert_final_newline = true

web-examples/src/main/java/io/vertx/example/web/cors/Server.java

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,68 +19,65 @@
1919
*/
2020
public class Server extends AbstractVerticle {
2121

22-
// Convenience method so you can run it in your IDE
23-
public static void main(String[] args) {
24-
Runner.runExample(Server.class);
25-
}
22+
// Convenience method so you can run it in your IDE
23+
public static void main(String[] args) {
24+
Runner.runExample(Server.class);
25+
}
2626

27-
@Override
28-
public void start() throws Exception {
27+
@Override
28+
public void start() throws Exception {
2929

30-
Router router = Router.router(vertx);
30+
Router router = Router.router(vertx);
3131

32-
Set<String> allowedHeaders = new HashSet<>();
33-
allowedHeaders.add("x-requested-with");
34-
allowedHeaders.add("Access-Control-Allow-Origin");
35-
allowedHeaders.add("origin");
36-
allowedHeaders.add("Content-Type");
37-
allowedHeaders.add("accept");
38-
allowedHeaders.add("X-PINGARUNER");
32+
Set<String> allowedHeaders = new HashSet<>();
33+
allowedHeaders.add("x-requested-with");
34+
allowedHeaders.add("Access-Control-Allow-Origin");
35+
allowedHeaders.add("origin");
36+
allowedHeaders.add("Content-Type");
37+
allowedHeaders.add("accept");
38+
allowedHeaders.add("X-PINGARUNER");
3939

40-
Set<HttpMethod> allowedMethods = new HashSet<>();
41-
allowedMethods.add(HttpMethod.GET);
42-
allowedMethods.add(HttpMethod.POST);
43-
allowedMethods.add(HttpMethod.OPTIONS);
44-
/*
45-
these methods aren't necessary for this sample,
46-
but you may need them for your projects
47-
*/
48-
allowedMethods.add(HttpMethod.DELETE);
49-
allowedMethods.add(HttpMethod.PATCH);
50-
allowedMethods.add(HttpMethod.PUT);
51-
40+
Set<HttpMethod> allowedMethods = new HashSet<>();
41+
allowedMethods.add(HttpMethod.GET);
42+
allowedMethods.add(HttpMethod.POST);
43+
allowedMethods.add(HttpMethod.OPTIONS);
44+
/*
45+
* these methods aren't necessary for this sample,
46+
* but you may need them for your projects
47+
*/
48+
allowedMethods.add(HttpMethod.DELETE);
49+
allowedMethods.add(HttpMethod.PATCH);
50+
allowedMethods.add(HttpMethod.PUT);
5251

53-
router.route().handler(CorsHandler.create("*")
54-
.allowedHeaders(allowedHeaders)
55-
.allowedMethods(allowedMethods));
52+
router.route().handler(CorsHandler.create("*").allowedHeaders(allowedHeaders).allowedMethods(allowedMethods));
5653

57-
router.get("/access-control-with-get").handler(ctx -> {
58-
HttpServerResponse httpServerResponse = ctx.response();
59-
httpServerResponse.setChunked(true);
60-
MultiMap headers = ctx.request().headers();
61-
for (String key : headers.names()){
62-
httpServerResponse.write(key + ": ");
63-
httpServerResponse.write(headers.get(key));
64-
httpServerResponse.write("<br>");
65-
}
66-
httpServerResponse.putHeader("Content-Type", "application/text").end("Success");
67-
});
54+
router.get("/access-control-with-get").handler(ctx -> {
55+
HttpServerResponse httpServerResponse = ctx.response();
56+
httpServerResponse.setChunked(true);
57+
MultiMap headers = ctx.request().headers();
58+
for (String key : headers.names()) {
59+
httpServerResponse.write(key + ": ");
60+
httpServerResponse.write(headers.get(key));
61+
httpServerResponse.write("<br>");
62+
}
63+
httpServerResponse.putHeader("Content-Type", "application/text").end("Success");
64+
});
6865

69-
router.post("/access-control-with-post-preflight").handler(ctx -> {
70-
HttpServerResponse httpServerResponse = ctx.response();
71-
httpServerResponse.setChunked(true);
72-
MultiMap headers = ctx.request().headers();
73-
for (String key : headers.names()) {
74-
httpServerResponse.write(key + ": ");
75-
httpServerResponse.write(headers.get(key));
76-
httpServerResponse.write("<br>");
77-
}
78-
httpServerResponse.putHeader("Content-Type", "application/text").end("Success");
79-
});
66+
router.post("/access-control-with-post-preflight").handler(ctx -> {
67+
HttpServerResponse httpServerResponse = ctx.response();
68+
httpServerResponse.setChunked(true);
69+
MultiMap headers = ctx.request().headers();
70+
for (String key : headers.names()) {
71+
httpServerResponse.write(key + ": ");
72+
httpServerResponse.write(headers.get(key));
73+
httpServerResponse.write("<br>");
74+
}
75+
httpServerResponse.putHeader("Content-Type", "application/text").end("Success");
76+
});
8077

81-
// Serve the static resources
82-
router.route().handler(StaticHandler.create());
78+
// Serve the static resources
79+
router.route().handler(StaticHandler.create());
8380

84-
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
85-
}
81+
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
82+
}
8683
}

web-examples/src/main/java/io/vertx/example/web/cors/webroot/nopreflight.html

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,41 @@
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
5-
<title>Simple use of Cross-Site XMLHttpRequest (Using Access Control)</title>
6-
<script type="text/javascript">
7-
var url = 'http://localhost:8080/access-control-with-get/';
5+
<title>Simple use of Cross-Site XMLHttpRequest (Using Access Control)</title>
6+
<script type="text/javascript">
7+
var url = 'http://localhost:8080/access-control-with-get/';
88

9-
function callOtherDomain() {
10-
var xhttp = new XMLHttpRequest();
11-
xhttp.onreadystatechange = function() {
12-
if (this.readyState == 4 && this.status == 200) {
13-
var e = document.createElement('p');
14-
e.innerHTML = xhttp.responseText;
15-
document.getElementById("textDiv").appendChild(e);
16-
} else {
17-
console.log("XMLHttpRequest readyState:" + this.readyState + " status: " + this.status);
18-
}
19-
};
20-
xhttp.open("GET", url, true);
21-
xhttp.send();
22-
}
23-
</script>
9+
function callOtherDomain() {
10+
var xhttp = new XMLHttpRequest();
11+
xhttp.onreadystatechange = function() {
12+
if (this.readyState == 4 && this.status == 200) {
13+
var e = document.createElement('p');
14+
e.innerHTML = xhttp.responseText;
15+
document.getElementById("textDiv").appendChild(e);
16+
} else {
17+
console.log("XMLHttpRequest readyState:" + this.readyState
18+
+ " status: " + this.status);
19+
}
20+
};
21+
xhttp.open("GET", url, true);
22+
xhttp.send();
23+
}
24+
</script>
2425
</head>
2526
<body>
26-
<form id="controlsToInvoke" action="">
27-
<p>
28-
<input type="button" value="Click to Invoke Another Site" onclick="callOtherDomain()" />
29-
</p>
30-
</form>
31-
<p id="intro">
32-
This page basically makes invocations to another domain using cross-site XMLHttpRequest mitigated by Access Control. This is the simple scenario that is <em>NOT</em> preflighted, and the invocation to a resource on another domain takes place using a simple HTTP GET.
33-
</p>
34-
<div id="textDiv">
35-
This XHTML document invokes another resource using cross-site XHR.
36-
</div>
27+
<form id="controlsToInvoke" action="">
28+
<p>
29+
<input type="button" value="Click to Invoke Another Site"
30+
onclick="callOtherDomain()" />
31+
</p>
32+
</form>
33+
<p id="intro">
34+
This page basically makes invocations to another domain using
35+
cross-site XMLHttpRequest mitigated by Access Control. This is the
36+
simple scenario that is <em>NOT</em> preflighted, and the invocation
37+
to a resource on another domain takes place using a simple HTTP GET.
38+
</p>
39+
<div id="textDiv">This XHTML document invokes another resource
40+
using cross-site XHR.</div>
3741
</body>
3842
</html>

web-examples/src/main/java/io/vertx/example/web/cors/webroot/preflight.html

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,43 @@
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
5-
<title>Simple use of Cross-Site XMLHttpRequest (Using Access Control)</title>
6-
<script type="text/javascript">
7-
var url = 'http://localhost:8080/access-control-with-post-preflight/';
5+
<title>Simple use of Cross-Site XMLHttpRequest (Using Access Control)</title>
6+
<script type="text/javascript">
7+
var url = 'http://localhost:8080/access-control-with-post-preflight/';
88

9-
function callOtherDomain() {
10-
var xhttp = new XMLHttpRequest();
11-
xhttp.onreadystatechange = function() {
12-
if (this.readyState == 4 && this.status == 200) {
13-
var e = document.createElement('p');
14-
e.innerHTML = xhttp.responseText;
15-
document.getElementById("textDiv").appendChild(e);
16-
} else {
17-
console.log("XMLHttpRequest readyState:" + this.readyState + " status: " + this.status);
18-
}
19-
};
20-
xhttp.open("POST", url, true);
21-
xhttp.setRequestHeader('X-PINGARUNER', 'pingpong');
22-
xhttp.setRequestHeader('Content-Type', 'application/text');
23-
xhttp.send();
24-
}
25-
</script>
9+
function callOtherDomain() {
10+
var xhttp = new XMLHttpRequest();
11+
xhttp.onreadystatechange = function() {
12+
if (this.readyState == 4 && this.status == 200) {
13+
var e = document.createElement('p');
14+
e.innerHTML = xhttp.responseText;
15+
document.getElementById("textDiv").appendChild(e);
16+
} else {
17+
console.log("XMLHttpRequest readyState:" + this.readyState
18+
+ " status: " + this.status);
19+
}
20+
};
21+
xhttp.open("POST", url, true);
22+
xhttp.setRequestHeader('X-PINGARUNER', 'pingpong');
23+
xhttp.setRequestHeader('Content-Type', 'application/text');
24+
xhttp.send();
25+
}
26+
</script>
2627
</head>
2728
<body>
28-
<form id="controlsToInvoke" action="">
29-
<p>
30-
<input type="button" value="Click to Invoke Another Site" onclick="callOtherDomain()" />
31-
</p>
32-
</form>
33-
<p id="intro">
34-
This page POSTs XML data to another domain using cross-site XMLHttpRequest mitigated by Access Control. This is the preflight scenario and the invocation to a resource on another domain takes place using first an OPTIONS request, then an actual POST request.
35-
</p>
36-
<div id="textDiv">
37-
This XHTML document POSTs to another resource using cross-site XHR. If you get a response back, the content of that response should reflect what you POSTed.
38-
</div>
29+
<form id="controlsToInvoke" action="">
30+
<p>
31+
<input type="button" value="Click to Invoke Another Site"
32+
onclick="callOtherDomain()" />
33+
</p>
34+
</form>
35+
<p id="intro">This page POSTs XML data to another domain using
36+
cross-site XMLHttpRequest mitigated by Access Control. This is the
37+
preflight scenario and the invocation to a resource on another domain
38+
takes place using first an OPTIONS request, then an actual POST
39+
request.</p>
40+
<div id="textDiv">This XHTML document POSTs to another resource
41+
using cross-site XHR. If you get a response back, the content of that
42+
response should reflect what you POSTed.</div>
3943
</body>
4044
</html>

0 commit comments

Comments
 (0)