WebSphere Portal Server - That old subject, portlet to servlet communication

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > June 2007 > That old subject, portlet to servlet communication





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author That old subject, portlet to servlet communication

2007-06-06, 1:21 am

I am attempting to figure out some way, any way to be able to pass data from a portlet to an external servlet (i.e. The servlet is not within the portlet application. The servlet _is_ being run on the same WAS (its host is "server1" as opposed to "websph
ere_portal". Lets call it eServlet).

I have tried creating a servlet that _is_ within the portlet (call it pServlet for short) to set cookies, set attributes, set parameters, set headers, set everything I can think of, but nothing seems to reach the eServlet.

I had thought that cookies would be the answer, but when I set one from the pSErvlet, eServlet cannot see it. I can actually see them being created in the cache of my browser, but eServlet doesn't see them. I've seen various methods in various forums t
hat supposedly work but I can't get them to. MY tiny little brain is just not up to the task.

Is it simply not possible to have a portlet communicate to an external servlet?
DOes someone have any concrete examples of doing this?

Thanks in advance for any help provided.



bochs

2007-06-06, 1:23 pm

To make pServlet work, watch your scope when you add attributes to the session. To share the portlet session with the servlet session, you'll need to use APPLICATION_SCOPE like this:

session.setAttribute("attr1", attr1Value, PortletSession.APPLICATION_SCOPE );


Brian

2007-06-06, 7:22 pm

Brian

Thanks for your reply.


yeah I'd tried that with no luck. That only seems to work when the servlet is not a part of the portlet application itself (i.e. the servlet is a part of the same war as the portlet calling it). In that case, things work famously.

However the servlet I am attempting to talk to is not a part of the portlet application at all. It is running on the app server itself. Which is to say, I created the servlet, generated the war, went to the WAS admin console Applications->Enterprise Ap
plications->Install and set it up there. I am able to hit the servlet just fine in my browser, so I know its working (it has default output when hit from the browser).


The app server running this servlet is the same one that the portal is running on (i.e. websphere_portal), but it is outside the actual /wps/portal environment.


2007-06-06, 7:22 pm

whoops, typo in my previous response

this line

"That only seems to work when the servlet is not a part of the portlet application itself (i.e. the servlet is a part of the same war as the portlet calling it)"

is contradicting itself.

it should read

That only seems to work when the servlet _is_ a part of the portlet application itself (i.e. the servlet is a part of the same war as the portlet calling it)


bochs

2007-06-06, 7:22 pm

If your applications are in the same domain then cookies should work. Make sure the path is set to a high level such as '/'.

I also have used regular old querystring parameters to invoke servlets from a portlet application; not sure what your requirements are.

Brian

2007-06-07, 7:18 am

I'm trying parameters and they are still not working correctly.

from a jsp within the portlet application I have the following form

[code]
<form method="GET" action="/server2/servlet2" target="_blank" >
<input class="button" style="cursor:hand" type="submit" border="0" value='Open Servlet2'/>"
<input type="hidden" name ="borkina" value="flooglethorp">
</form>

[/code]

clicking on the button opens up the new page with the following URL

http://localhost:9081/server2/servl...na=flooglethorp

within that servlet I have the following code

[code]
PrintWriter out = response.getWriter();

Enumeration aParms = request.getParameterNames();
out.println("parms:<br>");
while (aHeaders.hasMoreElements())
{
String aName = (String) aParms.nextElement();
String aValue = request.getParameter(aName);
out.println(aName + ":" + aValue + "<br>");

}

/* just to make sure*/
String borkina=request.getParameter("borkina");
if(borkina!= null)
{
out.println("borkina:" + borkina + "<br>");
}
out.println("end parms:<br>");
[/code]
which results in the following output

parms:
end parms:

I don't get why I can't see the parameter being passed in.

I swear it seems like there must be some sort of "Work Correctly" checkbox in the admin console.

2007-06-07, 7:19 am

btw, I'm not sure what is up with all the

"0" src="images/emoticons/wink.gif" alt=";)">;

that showed up in the above post. In each case what was typed in was

");

not sure why the forum changed it thus. bizarre.
bochs

2007-06-07, 1:23 pm

I see you are looping through aHeaders, but shouldn't that be aParms instead? What happens if you access the servlet directly without using the form?

Brian

2007-06-07, 1:23 pm

Well, once again I am proven to be a moron. Thanks for finding my painfully obvious (except to me of course) mistakes.

I promise to try harder next time.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com