Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GADGETS-38: gadget web exception when using port offset.

  • Loading branch information...
commit 9a75721d3461c4a6e30cea65f724bfb5289e91a7 1 parent 955b586
@jeffyu jeffyu authored
View
4 distribution/pom.xml
@@ -26,13 +26,13 @@
<groupId>org.overlord.gadgets.server</groupId>
<artifactId>distribution</artifactId>
<packaging>pom</packaging>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
<name>Gadget Server::Distribution</name>
<parent>
<groupId>org.overlord.gadgets.server</groupId>
<artifactId>parent</artifactId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
View
2  distribution/src/main/release/build.xml
@@ -3,7 +3,7 @@
<project name="GadgetServer_Installer">
<!-- DEFAULT PROPERTY VALUES -->
- <property name="as7.home" value="/Users/jeffyu/deploy/switchyard-as7-0.6" />
+ <property name="as7.home" value="/Users/jeffyu/deploy/switchyard-as7-0.7" />
<property name="deploy.dir" value="${as7.home}/standalone/deployments" />
<property name="version" value="1.0.0-SNAPSHOT" />
<property name="database" value="h2"/>
View
2  gadget-core/pom.xml
@@ -9,7 +9,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.overlord.gadgets.server</groupId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
View
2  gadget-server/pom.xml
@@ -9,7 +9,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.overlord.gadgets.server</groupId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
View
2  gadget-web/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.overlord.gadgets.server</groupId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.overlord.gadgets.server</groupId>
<artifactId>gadget-web</artifactId>
View
13 gadget-web/src/main/java/org/overlord/gadgets/web/client/model/JSOParser.java
@@ -17,6 +17,7 @@
*/
package org.overlord.gadgets.web.client.model;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import org.overlord.gadgets.web.shared.dto.*;
@@ -92,14 +93,15 @@
JsArray<JSOModel> resultSets = model.getArray("resultSet");
List<StoreItemModel> items = new ArrayList<StoreItemModel>();
-
+ String baseUrl = getBaseUrl();
for (int i = 0; i < resultSets.length(); i++) {
StoreItemModel itemModel = new StoreItemModel();
JSOModel theItem = resultSets.get(i);
itemModel.setId(theItem.getLong("id"));
itemModel.setName(theItem.get("title"));
itemModel.setDescription(theItem.get("description"));
- itemModel.setThumbnailUrl(theItem.get("thumbnailUrl"));
+
+ itemModel.setThumbnailUrl(theItem.get("thumbnailUrl").replace("${server}", baseUrl));
itemModel.setAuthor(theItem.get("author"));
items.add(itemModel);
@@ -115,6 +117,13 @@
return response;
}
+ private static String getBaseUrl() {
+ String pageBaseUrl = GWT.getHostPageBaseURL();
+ int end = pageBaseUrl.indexOf("gadget-web");
+ //remote the end slash.
+ return pageBaseUrl.substring(0, end-1);
+ }
+
public static UserModel getUserModel(String jsonValue) {
JSOModel model = JSOModel.fromJson(jsonValue);
UserModel user = new UserModel();
View
18 gadget-web/src/main/java/org/overlord/gadgets/web/client/widgets/Portlet.java
@@ -60,6 +60,8 @@
private static PortletUiBinder uiBinder = GWT.create(PortletUiBinder.class);
+ private static String urlBase;
+
private String id;
private String widgetId;
@@ -88,6 +90,8 @@ private Portlet(final String wid, final String pid) {
this.portalId = pid;
initWidget(uiBinder.createAndBindUi(this));
getElement().setId(id);
+
+ urlBase = getGadgetServerUrlBase();
minBtn.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
@@ -117,7 +121,7 @@ public void onClick(ClickEvent event) {
gadgetSpec.setWidth("100%");
gadgetSpec.setHeight("90%");
gadgetSpec.getElement().setAttribute("scrolling", "auto");
- gadgetSpec.setUrl("http://localhost:8080/gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getCanvasView());
+ gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getCanvasView());
}
});
@@ -128,7 +132,7 @@ public void onClick(ClickEvent event) {
gadgetSpec.setWidth("100%");
gadgetSpec.setHeight("250px");
gadgetSpec.getElement().setAttribute("scrolling", "auto");
- gadgetSpec.setUrl("http://localhost:8080/gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getHomeView());
+ gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getHomeView());
}
});
@@ -152,7 +156,13 @@ public Portlet(WidgetModel model, int width, String portalId) {
gadgetSpec.getElement().setAttribute("frameborder", "0");
gadgetSpec.setWidth(width - 20 + "px");
gadgetSpec.setHeight("250px");
- gadgetSpec.setUrl("http://localhost:8080/gadget-server/gadgets/ifr?url=" + model.getSpecUrl() + "&" + getHomeView());
+ gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + model.getSpecUrl() + "&" + getHomeView());
+ }
+
+ private String getGadgetServerUrlBase() {
+ String gadgetWebUrlBase = GWT.getHostPageBaseURL();
+ int end = gadgetWebUrlBase.indexOf("gadget-web");
+ return gadgetWebUrlBase.substring(0, end);
}
@@ -251,7 +261,7 @@ public void onClick(ClickEvent event) {
RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.updatePreferenceURL(Long.valueOf(widgetId)), sbuffer.toString(), new RestfulInvoker.Response(){
public void onResponseReceived(Request request, Response response) {
hideUserPref(id);
- gadgetSpec.setUrl("http://localhost:8080/gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getHomeView());
+ gadgetSpec.setUrl(urlBase + "gadget-server/gadgets/ifr?url=" + wmodel.getSpecUrl() + "&" + getHomeView());
reloadIFrame(gadgetSpec.getElement());
}
View
28 gadget-web/src/main/java/org/overlord/gadgets/web/server/ConfigurationUtil.java
@@ -1,28 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008-11, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.overlord.gadgets.web.server;
-
-/**
- * @author: Jeff Yu
- * @date: 3/04/12
- */
-public class ConfigurationUtil {
-
- public static final String SHINDIG_RPC_URL = "http://localhost:8080/gadget-server/rpc";
-
-}
View
3  gadget-web/src/main/java/org/overlord/gadgets/web/server/GadgetMetadataService.java
@@ -18,5 +18,8 @@
public WidgetModel getGadgetMetadata(String gadgetUrl);
+ public void setGadgetServerRPCUrl(String rpcUrl);
+
+
public Gadget getGadgetData(String gadgetUrl);
}
View
13 gadget-web/src/main/java/org/overlord/gadgets/web/server/ShindigGadgetMetadataService.java
@@ -40,8 +40,16 @@
public static final String USER_PREFS = "userPrefs";
public static final String DATA_TYPE = "dataType";
+
+ //This is default one when no value was set.
+ private String rpcUrl = "http://localhost:8080/gadget-server/rpc";
-
+
+ public void setGadgetServerRPCUrl(String rpcUrl) {
+ this.rpcUrl = rpcUrl;
+
+ }
+
public WidgetModel getGadgetMetadata(String gadgetUrl) {
String responseString = getMetadata(gadgetUrl);
@@ -146,7 +154,7 @@ private String getMetadata(String gadgetUrl) {
logger.debug("requestContent: {}", postData);
}
- ClientRequest request = new ClientRequest(ConfigurationUtil.SHINDIG_RPC_URL);
+ ClientRequest request = new ClientRequest(this.rpcUrl);
request.accept("application/json").body(MediaType.APPLICATION_JSON, postData);
String responseString = null;
@@ -196,4 +204,5 @@ public static void main(String[] args) throws Exception {
//svc.getGadgetMetadata("http://sam-gadget.appspot.com/Gadget/SamGadget.gadget.xml");
//svc.getGadgetMetadata("http://localhost:8080/gadgets/rt-gadget/gadget.xml");
}
+
}
View
24 gadget-web/src/main/java/org/overlord/gadgets/web/server/UserController.java
@@ -110,10 +110,12 @@ public Response checkUsername(@PathParam("username") String username) {
@GET
@Path("user/{userId}/pages")
@Produces("application/json")
- public List<PageModel> getPageModels(@PathParam("userId") long userId) {
+ public List<PageModel> getPageModels(@PathParam("userId") long userId, @Context HttpServletRequest request) {
List<Page> pages = userManager.getPages(userId);
List<PageModel> pageModels = new ArrayList<PageModel>();
+ String serverBaseUrl = getServerBaseUrl(request);
+ metadataService.setGadgetServerRPCUrl(serverBaseUrl + "/gadget-server/rpc");
for (Page page : pages) {
PageModel pageModel = new PageModel();
@@ -121,9 +123,9 @@ public Response checkUsername(@PathParam("username") String username) {
pageModel.setOrder(page.getPageOrder());
pageModel.setColumns(page.getColumns());
pageModel.setId(page.getId());
-
+
for (Widget widget :page.getWidgets()) {
- WidgetModel widgetModel = metadataService.getGadgetMetadata(widget.getAppUrl());
+ WidgetModel widgetModel = metadataService.getGadgetMetadata(widget.getAppUrl().replace("${server}", serverBaseUrl));
widgetModel.setWidgetId(widget.getId());
widgetModel.setOrder(widget.getOrder());
@@ -137,6 +139,18 @@ public Response checkUsername(@PathParam("username") String username) {
return pageModels;
}
+
+ private String getServerBaseUrl(HttpServletRequest request) {
+ String scheme = request.getScheme();
+ String serverName = request.getServerName();
+ int serverPort = request.getServerPort();
+ StringBuilder sbuilder = new StringBuilder();
+ sbuilder.append(scheme).append("://").append(serverName);
+ if ((serverPort != 80) && (serverPort != 443)) {
+ sbuilder.append(":" + serverPort);
+ }
+ return sbuilder.toString();
+ }
private void populateWidgetsDefaultValue(Widget widget, WidgetModel widgetModel) {
if (widget.getPrefs() != null && widget.getPrefs().size() > 0) {
@@ -215,5 +229,9 @@ private Response createJsonResponse(Object wrapper) {
String json = gson.toJson(wrapper);
return Response.ok(json).type("application/json").build();
}
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("${server}/gadgets-server/test".replace("${server}", "http://localhost:8080"));
+ }
}
View
8 gadget-web/src/main/webapp/WEB-INF/classes/import.sql
@@ -3,9 +3,9 @@ INSERT INTO GS_USER(`ID`, `NAME`, `DISPLAY_NAME`, `PASSWD`, `USER_ROLE`) VALUES(
INSERT INTO GS_USER_GROUP(`USER_ID`, `GROUP_ID`) VALUES(1, 1);
-INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Response Time','Red Hat','jeffyu@overlord.com','Response Time Gadget','http://localhost:8080/gadgets/rt-gadget/thumbnail.png','http://localhost:8080/gadgets/rt-gadget/gadget.xml');
-INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Situation Gadget','Red Hat','jeffyu@overlord.com','Situation Gadget','http://localhost:8080/gadgets/situation-gadget/thumbnail.png','http://localhost:8080/gadgets/situation-gadget/gadget.xml');
-INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Call Trace Gadget','Red Hat','jeffyu@overlord.com','Call Trace Gadget','http://localhost:8080/gadgets/calltrace-gadget/thumbnail.png','http://localhost:8080/gadgets/calltrace-gadget/gadget.xml');
-INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Service Overview Gadget','Red Hat','jeffyu@overlord.com','Service Overview Gadget','http://localhost:8080/gadgets/so-gadget/thumbnail.png','http://localhost:8080/gadgets/so-gadget/gadget.xml');
+INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Response Time','Red Hat','jeffyu@overlord.com','Response Time Gadget','${server}/gadgets/rt-gadget/thumbnail.png','${server}/gadgets/rt-gadget/gadget.xml');
+INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Situation Gadget','Red Hat','jeffyu@overlord.com','Situation Gadget','${server}/gadgets/situation-gadget/thumbnail.png','${server}/gadgets/situation-gadget/gadget.xml');
+INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Call Trace Gadget','Red Hat','jeffyu@overlord.com','Call Trace Gadget','${server}/gadgets/calltrace-gadget/thumbnail.png','${server}/gadgets/calltrace-gadget/gadget.xml');
+INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Service Overview Gadget','Red Hat','jeffyu@overlord.com','Service Overview Gadget','${server}/gadgets/so-gadget/thumbnail.png','${server}/gadgets/so-gadget/gadget.xml');
INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Date & Time','Google','admin@google.com','Add a clock to your page. Click edit to change it to the color of your choice','http://gadgets.adwebmaster.net/images/gadgets/datetimemulti/thumbnail_en.jpg','http://www.gstatic.com/ig/modules/datetime_v3/datetime_v3.xml');
INSERT INTO GS_GADGET(`GADGET_TITLE`,`GADGET_AUTHOR`,`GADGET_AUTHOR_EMAIL`,`GADGET_DESCRIPTION`,`GADGET_THUMBNAIL_URL`,`GADGET_URL`) VALUES('Economic Data - ALFRED Graph','Research Department','webmaster@research.stlouisfed.org','Vintage Economic Data from the Federal Reserve Bank of St. Louis','http://research.stlouisfed.org/gadgets/images/alfredgraphgadgetthumbnail.png','http://research.stlouisfed.org/gadgets/code/alfredgraph.xml');
View
2  gadgets/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.overlord.gadgets.server</groupId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.overlord.gadgets.server</groupId>
<artifactId>gadgets</artifactId>
View
2  pom.xml
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.overlord.gadgets.server</groupId>
<artifactId>parent</artifactId>
- <version>1.0.0.20130107-M3</version>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Gadget Server</name>
<url>http://www.jboss.org/overlord</url>
Please sign in to comment.
Something went wrong with that request. Please try again.