Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 24 Current »

[14:30:12 CDT(-0500)] <EricDalquist> drewwills: there?

[14:45:14 CDT(-0500)] <cwaymire> EricDalquist: hey got a quick question for you.

[14:45:19 CDT(-0500)] <EricDalquist> ok

[14:46:35 CDT(-0500)] <cwaymire> i've got a portlet that I added a Spring MVC controller into. I noticed that when calls come into that controller they have neither an active HttpSession nor does the request object contain a remote username.

[14:46:49 CDT(-0500)] <EricDalquist> this is a servlet controller?

[14:46:53 CDT(-0500)] <cwaymire> in this instance its important that I be able to get the user name

[14:46:59 CDT(-0500)] <cwaymire> yeah. standard spring mvc controller

[14:47:17 CDT(-0500)] <EricDalquist> so for the session to exist you need to make sure that the tomcat instance has emptySessionPath set to true

[14:47:24 CDT(-0500)] <EricDalquist> or whatever the TC7 version of that is

[14:47:31 CDT(-0500)] <EricDalquist> there will never be a remoteUser though

[14:47:33 CDT(-0500)] <cwaymire> let me double check my setting

[14:47:43 CDT(-0500)] <EricDalquist> that servlet is being directly accessed by the client

[14:47:49 CDT(-0500)] <EricDalquist> the portal has zero control over it

[14:48:00 CDT(-0500)] <EricDalquist> so none of the portal user's "state" is available

[14:48:07 CDT(-0500)] <EricDalquist> and in fact the session will only exist

[14:48:16 CDT(-0500)] <EricDalquist> if you have previously accessed a portlet in the same webapp

[14:48:19 CDT(-0500)] <EricDalquist> and that portlet created a session

[14:48:43 CDT(-0500)] <cwaymire> which is the case. are there any tricks to getting the username of the authenticated user?

[14:49:39 CDT(-0500)] <EricDalquist> the only way

[14:49:48 CDT(-0500)] <EricDalquist> is for the user to visit the portlet first

[14:49:57 CDT(-0500)] <EricDalquist> the portlet stores the username in the application scope in the portlet session

[14:50:01 CDT(-0500)] <EricDalquist> then the servlet can see that value

[14:50:10 CDT(-0500)] <EricDalquist> if the servlet is the first point of contact though

[14:50:10 CDT(-0500)] <EricDalquist> no

[14:50:12 CDT(-0500)] <EricDalquist> there is no way

[14:51:14 CDT(-0500)] <cwaymire> The portlet (Attachments) will always be there. It will basically be a hidden div on the page. An interaction in another portlet will cause a lightbox to display allowing the user to select a file to upload via a multipart POST.

[14:51:51 CDT(-0500)] <cwaymire> but I need to know who the user was that submitted the upload.

[14:52:13 CDT(-0500)] <EricDalquist> yeah they would need to visit the portlet first

[14:52:17 CDT(-0500)] <EricDalquist> why not have them upload to the porlet

[14:52:26 CDT(-0500)] <EricDalquist> portlets can deal with uploads via action and resource urls

[14:53:49 CDT(-0500)] <cwaymire> the idea was that the Attachments portlet would basically be an invisible portlet that wasnt rendered but would expose a global javascript api that would open up a lightbox div on the page allowing you to upload a file. So any portlet that wants to use attachments can simply call the global js method and give it a callback method. When the upload is done the callback method is executed with some result data.

[14:54:28 CDT(-0500)] <EricDalquist> so you are 'uploading" to the javascript?

[14:54:55 CDT(-0500)] <EricDalquist> or is the attachment stored somewhere that other portlets could potentially reference/access?

[14:55:51 CDT(-0500)] <cwaymire> the javascript makes an ajax call to submit the file to the controller which creates some database rows and will store the file on the filesystem.

[14:56:15 CDT(-0500)] <EricDalquist> ok

[14:56:16 CDT(-0500)] <cwaymire> the idea is any portlet can upload an attachment and then later reference that attachment. right now the functionality is going to be pretty limited

[14:56:26 CDT(-0500)] <EricDalquist> so why the servlet?

[14:56:34 CDT(-0500)] <EricDalquist> the portlet could do that competely within the portlet API

[14:56:46 CDT(-0500)] <EricDalquist> the attchment portlet renders in a hidden div

[14:56:55 CDT(-0500)] <EricDalquist> the JS that is written out includes a portlet resource url

[14:57:16 CDT(-0500)] <EricDalquist> the JS "upload attachment" api POSTs the file upload to the resource url

[14:57:32 CDT(-0500)] <EricDalquist> which accepts the upload, stores it, writes to the db and returns some JSON with the DB key to the new upload

[14:57:39 CDT(-0500)] <EricDalquist> which the other portlet can then use/store/etc

[14:57:57 CDT(-0500)] <cwaymire> The part I had trouble with was getting it to work on a ResourceMapping

[14:58:36 CDT(-0500)] <cwaymire> it didnt seem to send the right parameters across to the mapping

[14:59:07 CDT(-0500)] <cwaymire> i took the working code from the mvc controller and put it under a ResourceMapping and it didnt like the params.

[14:59:12 CDT(-0500)] <EricDalquist> what do you mean?

[14:59:22 CDT(-0500)] <EricDalquist> ah, do you have an example of that?

[14:59:50 CDT(-0500)] <cwaymire> yeah. i can gist it if you want

[14:59:53 CDT(-0500)] <EricDalquist> sure

[15:01:21 CDT(-0500)] <cwaymire> https://gist.github.com/anonymous/5207946

[15:01:21 CDT(-0500)] <cwaymire> https://gist.github.com/anonymous/5207952

[15:01:24 CDT(-0500)] <cwaymire> first one is the mvc controller

[15:01:28 CDT(-0500)] <cwaymire> second is a portlet resource mapping

[15:01:54 CDT(-0500)] <cwaymire> when I attempted to use the resource mapping I got an error saying org.springframework.web.portlet.bind.MissingPortletRequestParameterException: Required MultipartFile parameter 'qqfile' is not present

[15:01:55 CDT(-0500)] <EricDalquist> ok

[15:02:18 CDT(-0500)] <EricDalquist> but it works for the action request version of that?

[15:02:45 CDT(-0500)] <cwaymire> the mvc controller using a RequestMapping works

[15:03:06 CDT(-0500)] <EricDalquist> just out of curiousity

[15:03:06 CDT(-0500)] <cwaymire> at first I tried using an ActionMapping/RenderMapping pair but I need/want to return json

[15:03:12 CDT(-0500)] <EricDalquist> can you try doing this one: https://gist.github.com/anonymous/5207946

[15:03:23 CDT(-0500)] <EricDalquist> but change the ActionReq/Res to ResourceReq/Res

[15:03:35 CDT(-0500)] <EricDalquist> and use a resourceurl instead of an actionurl to call it

[15:03:41 CDT(-0500)] <EricDalquist> just to see if that makes any difference

[15:03:42 CDT(-0500)] <EricDalquist> if not

[15:03:48 CDT(-0500)] <EricDalquist> it is a bug either in spring or in uPortal

[15:04:16 CDT(-0500)] <EricDalquist> file upload is a pita, both spring an uportal have to be super extra careful to not touch the request body before the portlet wants to look at it

[15:04:24 CDT(-0500)] <EricDalquist> or it disappears as you can only read it once

[15:04:59 CDT(-0500)] <cwaymire> I had it working fine in the mvc controller. was able to see the file contents.

[15:05:03 CDT(-0500)] <cwaymire> ok. im going to recompile,d eploy and test

[15:05:31 CDT(-0500)] <EricDalquist> thanks

[15:10:37 CDT(-0500)] <cwaymire> that time I got: org.springframework.web.portlet.NoHandlerFoundException: No handler found for portlet request: mode 'view', phase 'RESOURCE_PHASE', parameters map[[empty]]

[15:10:50 CDT(-0500)] <EricDalquist> hrm

[15:10:59 CDT(-0500)] <EricDalquist> so somehow the parameters are not getting captured

[15:11:03 CDT(-0500)] <EricDalquist> is this code sharable at all?

[15:11:07 CDT(-0500)] <EricDalquist> like could you post it somewhere

[15:11:13 CDT(-0500)] <EricDalquist> and maybe tomorrow morning I could take a look at it?

[15:11:19 CDT(-0500)] <EricDalquist> I'm just worried there is a bug in uportal somwhere

[15:11:37 CDT(-0500)] <cwaymire> yeah. I can push this up to my github repo

[15:12:28 CDT(-0500)] <cwaymire> its frustrating because I had to go through several attempts to get it working properly and now the only blocker is with the MVC controller method I can't see the username.

[15:12:39 CDT(-0500)] <EricDalquist> (smile)

[15:12:43 CDT(-0500)] <EricDalquist> right

[15:12:45 CDT(-0500)] <cwaymire> it was the ajax portion that was a bit of a pita

[15:12:46 CDT(-0500)] <EricDalquist> well servlets are just servlets

[15:12:56 CDT(-0500)] <EricDalquist> and completely outside of the scope of the portal

[15:29:31 CDT(-0500)] <cwaymire> if I do it as a ResourceMapping it tells me it can't find the request parameter i'm looking for, but if I look at the http request going out I can see it defined in the request payload as form-data. not sure whats going on there.

[15:30:00 CDT(-0500)] <EricDalquist> yeah

[15:30:05 CDT(-0500)] <EricDalquist> that sounds like either a uportal or spring bug

[16:48:26 CDT(-0500)] <cwaymire> ok I think i have a temporary solution

[16:50:48 CDT(-0500)] <EricDalquist> great (smile)

[16:50:53 CDT(-0500)] <EricDalquist> I have to run and catch the bus

[16:51:01 CDT(-0500)] <cwaymire> heh. have fun.

[16:51:05 CDT(-0500)] <EricDalquist> but I'd love to hear about it tomorrow (or via reading chat logs)

  • No labels