Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce669a8

Browse files
author
Dave Johnson
committed
Expose some config properties to JavaScript via JSP
1 parent 51a26fe commit ce669a8

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed

src/main/java/snoopware/api/UserGridProxyServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public void init(ServletConfig servletConfig) throws ServletException {
6464
log.info("Ignoring app.usergridUri because it is invalid.");
6565
}
6666

67-
applicationName = (String) properties.get("app.applicationName");
68-
String organizationId = (String) properties.get("app.organizationId");
69-
String applicationId = (String) properties.get("app.applicationId");
67+
applicationName = (String) properties.get("app.name");
68+
String organizationId = (String) properties.get("org.id");
69+
String applicationId = (String) properties.get("app.id");
7070
userGridClient = new Client(organizationId, applicationId);
7171

72-
String clientId = (String) properties.get("app.clientId");
73-
String clientSecret = (String) properties.get("app.clientSecret");
72+
String clientId = (String) properties.get("org.clientId");
73+
String clientSecret = (String) properties.get("org.clientSecret");
7474
userGridClient.authorizeAppClient(clientId, clientSecret);
7575

7676
} catch (IOException ex) {
@@ -94,7 +94,7 @@ protected void copyRequestHeaders(HttpServletRequest req, HttpRequest proxyReq)
9494

9595
String header = "Bearer " + userGridClient.getAccessToken();
9696
proxyReq.setHeader("Authorization", header);
97-
log.info("Added header = {0}", header);
97+
log.info("added header {} to URL {}", header, req.getRequestURL().toString());
9898
}
9999
}
100100
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# you should define an app.properties file and set these values:
22

3-
app.usergridUri=
3+
app.rootUri=http://localhost:8080/angular-usergrid
4+
app.apiPath=/api
45

5-
app.organizationId=
6+
app.usergridUri=https://api.usergrid.com
67

7-
app.applicationName=
8-
app.applicationId=
8+
app.name=
9+
app.id=
910

10-
app.clientId=
11-
app.clientSecret=
11+
org.id=
12+
org.nane=
13+
14+
org.clientId=
15+
org.clientSecret=

src/main/webapp/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="js/libs/usergrid-0.10.4.js"></script>
99
<script src="js/libs/ui-bootstrap-tpls-0.5.0.min.js"></script>
1010
<link href="css/bootstrap-combined.min.css" rel="stylesheet" />
11+
<script src="js/config.jsp"></script>
1112
<script src="js/controllers.js"></script>
1213
<link href="css/styles.css" rel="stylesheet" />
1314
</head>

src/main/webapp/js/config.jsp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%@page contentType="application/json" pageEncoding="UTF-8"%>
2+
<%
3+
/*
4+
* Copyright 2013 David M. Johnson ([email protected]).
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
java.util.Properties props = new java.util.Properties();
19+
props.load(this.getClass().getResourceAsStream("/app.properties"));
20+
%>
21+
var config = {
22+
rootUri: "<%= props.getProperty("app.rootUri") %>",
23+
rootPath: "<%= props.getProperty("app.rootPath") %>",
24+
apiPath: "<%= props.getProperty("app.apiPath") %>",
25+
usergridUri: "<%= props.getProperty("app.usergridUri") %>",
26+
appName: "<%= props.getProperty("app.name") %>",
27+
orgName: "<%= props.getProperty("org.name") %>"
28+
};

src/main/webapp/js/controllers.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
var rootPath = "/angular-usergrid";
1+
/*
2+
* Copyright 2013 David M. Johnson ([email protected]).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
var rootPath = config.rootPath;
217
client = new Usergrid.Client({
3-
orgName: "snoopdave",
4-
appName: "volda",
18+
orgName: config.orgName,
19+
appName: config.appName,
20+
URI: config.rootUri + config.rootPath + config.apiPath,
521
logging: true,
6-
buildCurl: true,
7-
URI: "http://localhost:8080" + rootPath + "/api"
22+
buildCurl: true
823
});
924

1025
var appModule = angular.module("appModule", ["ui.bootstrap"]);

src/main/webapp/js/libs/usergrid-0.10.4.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ Usergrid.Client.prototype.createEntity = function (options, callback) {
295295
entity.set(options.data); //add the data again just in case
296296
entity.save(function(err, data) {
297297
if (typeof(callback) === 'function') {
298-
entity.error = data.error; // DMJ
298+
entity.error = data.error; // DMJ
299299
callback(err, entity);
300300
}
301301
});
302302
} else {
303303
if (typeof(callback) === 'function') {
304-
entity.error = data.error; // DMJ
304+
entity.error = data.error; // DMJ
305305
callback(err, entity);
306306
}
307307
}
@@ -350,9 +350,9 @@ Usergrid.Client.prototype.getEntity = function (options, callback) {
350350
var entity = new Usergrid.Entity(options);
351351
entity.fetch(function(err, data) {
352352
if (typeof(callback) === 'function') {
353-
if (err) { // DMJ
354-
entity.error = data.error;
355-
}
353+
if (err) { // DMJ
354+
entity.error = data.error;
355+
}
356356
callback(err, entity);
357357
}
358358
});

0 commit comments

Comments
 (0)