Based on feedback I've received from readers (Gerald Kanapathy and abenzvi -- thanks guys!) I've made some modifications to this post.
At some point while troubleshooting a problem, every ALUI portal administrator or developer is bound to ask themselves, "What's in a gateway URL?" and, more importantly, "How can I build one?"
Gateway URL’s look like the following:
http(s)://[portal_base]/gateway/PTARGS_spaceID_userID_objectID_communityID_pageID_classID/[gatewayed_URL]
Where portal_base is the base portal URL and gatewayed_URL is the URL you are trying to reach, which has been transformed using a function in the server API which I'll provide a reasonable copy of later.
A gatewayed URL, in many cases, only needs two pieces of information.:
- Class ID of calling object
- Object ID of calling object
The calling object is either a card, portlet or web service. Class IDs can be found in the java docs, among other places, but here they are:
- Card - 18
- Portlet - 43
- Service - 47
Leaving out community and user IDs could impact user preferences being passed to the back end, as Gerald pointed out. Object IDs can be found by browsing in the portal administratively (or using the EDK, etc). If you have access to the server API and/or UI source, methods can be found to construct gateway URLs under:
com.plumtree.portaluiinfrastructure.statichelpers.GatewayHelpers
The documentation for this class proves rather insightful (I guess that is no surprise), spelling out the rest of the arguments. I have provided it below, in case you don't have a copy handy (also see abenzvi's comment):
This class provides a set of static helpers for constructing valid gateway URLs. Gateway URLs follow a well-defined format to communicate information about the request to the gateway control. This section describes the format of the gateway URLs. For simplicity portal url is assumed to be http://machinename/portal/server.pt
The gateway URLs are identified by a special substring "gateway/PTARGS_" that should follow the portal URL. So, a general gateway URL looks like:
http://machinename/portal/server.pt/gateway/PTARGS_1_2_3_4_5_6/http://remotemachine/url_to_gateway/somefile.html
where 1,2,3,4,5,6 are numeric arguments described below.
- The first argument in an integer that contains a bit mask of gateway flags and type of associated gadget content that is being requested.
- POPUPFLAG - notifies the gateway that requested page will be displayed in the popup window and therefore gateway should set the RETURN-URI to "close window" javascript.
- RETURNFLAG - notifies the gateway that return URI is requested. The gateway will check that POPUPFLAG and either redirect to the last visited community or mypage or close the window.
- REDIRECTGUEST - notifies the gateway that it should redirect guest users to the login page before displaying the request resource. (This is mostly used by Collaboration server)
- The second argument is a numeric id of the user requesting the page. This argument is not used by the gateway and is intended for PPC PTTracker tool that analyzes the logs from the webserver. If user id is not known you can set it to any value, but 0 is preferred.
- The third argument is a numeric id of the object that is being requested. For example, if you are requesting a page through gadget 201, then this argument should be set to 201.
- The fourth argument is a community id.
- The fifth argument is a page id.
- The sixth argument is a resource type id. It defines what kind of object is identified by the object id provided in the third argument. Refer to Plumtree.idl to see what are numeric values for various resource types. Gateway supports the following resource types: Gadget, WebService, Card, DataSource.
You can use the somewhat incorrect code I have below to build gateway URLs (the CreateGatewayFriendlyURL function is correct, CreateGatewayUrl makes some assumptions), or you can take a look at some of the tags in the tag framework):
package com.plumtree.poc;
import java.net.URL;
public class GatewayHelper {
public static String CreateGatewayFriendlyURL(String url) {
int position = url.indexOf('?');
String result = "";
if(-1 == position) {
result = url.replaceAll(";", "%3B");
result = result.replaceAll("\\%", "%25");
result = result.replaceAll("://", ";/");
result = result.replaceAll(":", ";");
return result;
} else {
String urlPath = url.substring(0, position);
result = urlPath.replaceAll(";", "%3B");
result = result.replaceAll("\\%", "%25");
result = result.replaceAll("://", ";/");
result = result.replaceAll(":", ";");
return result + url.substring(position);
}
}
public static String CreateGatewayUrl(URL currentUrl, int portletId, String docUrl) {
String gatewayBase = currentUrl.getProtocol() + "://"
+ currentUrl.getHost() + ((currentUrl.getPort()== 80) ? "" :
(":" + currentUrl.getPort())) + "/portal/server.pt/gateway/PTARGS_0_0_";
String gatewayEnd = "_0_0_43/";
return gatewayBase + Integer.toString(portletId) + gatewayEnd + CreateGatewayFriendlyURL(docUrl);
}
}
Happy gatewaying!
Leave a comment