Get parameters from URL under portal enviroment on WPS7 - websphere-7

I want to get parameter from a URL under portlet environment.
The URL i am using to open a portlet is http://localhost:10039/wps/myportal/myPortlet?recId=100
When the portlet opens the URL changes and looks like
*http://localhost:10039/wps/myportal/myPortlet/!ut/p/b1/dY7LcoIwAAC_hQ9wElQSckwJ8lLEgjxyYbDTBAQMgkXHr7ft9Nq97cweFnBQmEhfGUtMdJADfqnmRla3Rl2q7sc5Kt_I0d1RxCCOyAZ6EQl8a29CSA3gAy47dfpOU1aoB1NUMsrEerIUz7lu0vma1pY9hNTZRbXZx8jYP8-SBSv_OibxLD66fnwvknYom9xPMzkK9awT_3Ru6i8Wt5SLA7GDTXtPt5OdGYMkd2wnDorD6UHKm8SqrwpRCb6YD5oGMsB_ly2Humu8hdA0TB161D1iFLMlpKu_AP4DhSB0Vf8Jeu4Qb0G1F8FgaxU!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/?recId=100*
The actuall thing is I want to get recID=100 parameter. The code i am using to get parameter is given below
PortletRequest portletRequest = (PortletRequest) webAppAccess.getHttpServletRequest().getAttribute( Constants.PORTLET_REQUEST);
HttpServletRequest httpRequest = PortletUtils.getInternalRequest(portletRequest).getHttpServletRequest();
httpRequest.getParameter("recId");
but it returns null
Can anyone help me how can i get the parameter under the given situation?
Note :
I am using WebSphere Portal Server 7.

Well, its not that easy.
You have to generate specific urls. WebSphere Portal Advanced Url Generation and How to create a link to a portlet and pass parameters.

I had this scenario before, and someone suggested me to use Portlet utilities, you can find this class in "com.ibm.ws.portletcontainer.portlet" pakcage, there are a lot of constructors(RenderRequest, ActionRequest, PortletRequest, ...), this is the method(PortletUtils.getHttpServletRequest(YOUR NEEDED OBJECT)) you can find your needs.

Related

Liferay Spring Rest services

Is there a way to expose a Java rest web service in Liferay but not in a portlet, that can receive JSON request and store the data in Journal Article?
Therefore when a user logs into Liferay they will be see web content
Yes there is : JSONWebServiceActionsManagerUtil.registerJSONWebServiceAction
For instance :
Class<?> serviceImplClass;
Method serviceMethod;
Object serviceImpl;
String path = jsonWebServiceMappingResolver.resolvePath(serviceImplClass, serviceMethod);
String method = jsonWebServiceMappingResolver.resolveHttpMethod(serviceMethod);
JSONWebServiceActionsManagerUtil.registerJSONWebServiceAction("/yourwspath", serviceImpl, serviceImplClass, serviceMethod, path, method);
You should then be able to see the new web service in http://SERVER/api/jsonws
Well yes, Liferay has a full API (even JSON-based, SOAP optional, no classic REST though) that you can use. A simple Stackoverflow answer is not the right place to give a full introduction on how to work with Liferay's API, but you might want to look up Servicebuilder (which is used to create Liferay's API) and then look at JournalArticleService and related services: The Web Content Management API is called "Journal" in Liferay (for historical reasons)

Where would I get the base URI In my ServiceStack markdown page?

I am looking to serve an image from my root path test.com/some.png but this markdown page may be displayed on [Post]test.com/Item or [Put]test.com/Item/123 So I am looking for a way to get the base URI to form the image link.
You can use the literal text ~/ inside a Markdown page gets converted to a virtual path.
This literal is registered on start-up from the global EndpointHostConfig.MarkdownReplaceTokens property which is assigned the appHost.Config.WebHostUrl property:
this.MarkdownReplaceTokens["~/"] = appHost.Config.WebHostUrl.WithTrailingSlash();
Since it's difficult for an ASP.NET framework to determine the url its hosted at (i.e. without a request) you need to specify the preferred url you wan to use in your config. Here's an example from the servicestack.net/docs/ - ServiceStack's markdown Docs project:
SetConfig(new EndpointHostConfig {
WebHostUrl = baseUrl, //replaces ~/ with Url
MarkdownBaseType = typeof(CustomMarkdownPage),
});
Otherwise inside your service you can use base.Request or base.RequestContext.Get<IHttpRequest>() to get information about the incoming Request as well as (HttpRequest)base.Request.OriginalRequest to get the underlying ASP.NET Request object.

Render mobile version of login in Secure class Play! Framework

Is it possible to somehow override the login method of the Secure.java class of the Secure-Module in Play! Framework, so that another version of the login form is displayed?
In my case, i want to display a mobile version of the login-form if a mobile browser is detected.
I know i should not change the Secure.java class itself, but i don't really see any other solution to this problem.
As discussed in other posts you have the request in your Play! controller. So in this request you could ask which agent is trying to view your website:
String agentInfo = request.headers.get("user-agent");
The you can determine which template will be rendered for this agent:
if (agentType.isWhatEverHeIs) {
renderTemplate("Application\mobileTemplateForBadPractise.html");
} else {
render();
}
But what I would encourage you to do is responsive webdevelopment. Create your templates as smart as possible, let the template and css and javascript do this and keep your business logic in your controller.
You could use the Twitter Bootstrap to achieve this, but there are many more! Like Skeleton.
You even got the request object inside your templates so that you can optionally render things in your template (or not) based on the agent.
Even simpler, simply create/override the secure/login.html template and use responsive design : media queries. No need to change the controller or check agent or whatever.

Problem opening context SPSite from SPItemEventProperties

In the following code,
// class overrides SPItemEventreceiver
public override void ItemAdding(SPItemEventProperties properties)
{
using (var site = new SPSite(properties.SiteId)) //SiteId is GUID <<corrected
{
...
}
}
The following exception is thrown:
System.IO.FileNotFoundException: The Web application at http://URL could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
One way to work around this is to hard-code (or configure) the URL specified in Alternate Access Mappings. Putting the correct URL in Alternate Access Mappings is ultimately the correct solution, but if possible, I need a work-around that doesn't require configuration.
SiteId should not be an integer - SPSite ctor only accepts URLs or Guids. Given that it is an GUID, I don't see how AAM plays a part here. An alternate approach might be to use:
properties.OpenWeb().Site
Also, since you are in a synchronous event handler you should have access to SPContext.Current.Site (unless you're trapping events in a document library - a long standing sharepoint bug means there is no context in sync events for doclibs - shitty)
-Oisin

Sharepoint web application creation using the object model

I am using the webapplicationbuilder class to create a new web application and have found many articles that help with this, none however seem to specify how you designate the URL or the application, i just get "sharepoint - 123" where 123 is the port specified and "servername/:123" as the url, whereas i need "http://myserver/.
Thanks
Assuming you mean the SPWebApplicationBuilder class.
Have you tried to set the HostHeader property of your SPWebApplicationBuilder object?

Resources