Java源码示例:javax.portlet.PortletSession
示例1
@Override
public void setAttribute(String name, Object value, int scope) {
if (scope == SCOPE_REQUEST) {
if (!isRequestActive()) {
throw new IllegalStateException(
"Cannot set request attribute - request is not active anymore!");
}
this.request.setAttribute(name, value);
}
else {
PortletSession session = getSession(true);
if (scope == SCOPE_GLOBAL_SESSION) {
session.setAttribute(name, value, PortletSession.APPLICATION_SCOPE);
this.globalSessionAttributesToUpdate.remove(name);
}
else {
session.setAttribute(name, value);
this.sessionAttributesToUpdate.remove(name);
}
}
}
示例2
public static void debugPrint(PortletRequest request, String line)
{
if ( line == null ) return;
line = line.replaceAll("<","<").replaceAll(">",">");
PortletSession pSession = request.getPortletSession(true);
String debugOut = null;
try {
debugOut = (String) pSession.getAttribute("debug.print");
} catch (Throwable t) {
debugOut = null;
}
if ( debugOut == null ) {
debugOut = line;
} else {
debugOut = debugOut + "\n" + line;
}
pSession.setAttribute("debug.print",debugOut);
}
示例3
public void processActionReset(String action,ActionRequest request, ActionResponse response)
throws PortletException, IOException {
// TODO: Check Role
log.debug("Removing preferences....");
clearSession(request);
PortletSession pSession = request.getPortletSession(true);
PortletPreferences prefs = request.getPreferences();
try {
prefs.reset("sakai.descriptor");
for (String element : fieldList) {
prefs.reset("imsti."+element);
prefs.reset("sakai:imsti."+element);
}
log.debug("Preference removed");
} catch (ReadOnlyException e) {
setErrorMessage(request, rb.getString("error.modify.prefs")) ;
return;
}
prefs.store();
// Go back to the main edit page
pSession.setAttribute("sakai.view", "edit");
}
示例4
protected TestResult checkRemoveAppScopedAttribute(PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Remove an application scoped session attribute "
+ "and ensure it's null.");
result.setSpecPLT("15.3");
session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE);
Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
if (value == null) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("session attribute", value, null, result);
}
return result;
}
示例5
/**
* Register web-specific scopes ("request", "session", "globalSession")
* with the given BeanFactory, as used by the Portlet ApplicationContext.
* @param bf the BeanFactory to configure
* @param pc the PortletContext that we're running within
*/
static void registerPortletApplicationScopes(ConfigurableListableBeanFactory bf, PortletContext pc) {
bf.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
bf.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
bf.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
if (pc != null) {
PortletContextScope appScope = new PortletContextScope(pc);
bf.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope);
// Register as PortletContext attribute, for ContextCleanupListener to detect it.
pc.setAttribute(PortletContextScope.class.getName(), appScope);
}
bf.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory());
bf.registerResolvableDependency(PortletResponse.class, new ResponseObjectFactory());
bf.registerResolvableDependency(PortletSession.class, new SessionObjectFactory());
bf.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory());
}
示例6
@Override
public void removeAttribute(String name, int scope) {
if (scope == SCOPE_REQUEST) {
if (isRequestActive()) {
this.request.removeAttribute(name);
removeRequestDestructionCallback(name);
}
}
else {
PortletSession session = getSession(false);
if (session != null) {
if (scope == SCOPE_GLOBAL_SESSION) {
session.removeAttribute(name, PortletSession.APPLICATION_SCOPE);
this.globalSessionAttributesToUpdate.remove(name);
}
else {
session.removeAttribute(name);
this.sessionAttributesToUpdate.remove(name);
}
}
}
}
示例7
@Override
public String[] getAttributeNames(int scope) {
if (scope == SCOPE_REQUEST) {
if (!isRequestActive()) {
throw new IllegalStateException(
"Cannot ask for request attributes - request is not active anymore!");
}
return StringUtils.toStringArray(this.request.getAttributeNames());
}
else {
PortletSession session = getSession(false);
if (session != null) {
if (scope == SCOPE_GLOBAL_SESSION) {
return StringUtils.toStringArray(session.getAttributeNames(PortletSession.APPLICATION_SCOPE));
}
else {
return StringUtils.toStringArray(session.getAttributeNames());
}
}
else {
return new String[0];
}
}
}
示例8
public static void setErrorMessage(PortletRequest request, String errorMsg, Throwable t)
{
if ( errorMsg == null ) errorMsg = "null";
PortletSession pSession = request.getPortletSession(true);
pSession.setAttribute("error.message",errorMsg);
OutputStream oStream = new ByteArrayOutputStream();
PrintStream pStream = new PrintStream(oStream);
log.error("{}", oStream);
log.error("{}", pStream);
// errorMsg = errorMsg .replaceAll("<","<").replaceAll(">",">");
StringBuffer errorOut = new StringBuffer();
errorOut.append("<p class=\"portlet-msg-error\">\n");
errorOut.append(ComponentManager.get(FormattedText.class).escapeHtmlFormattedText(errorMsg));
errorOut.append("\n</p>\n<!-- Traceback for this error\n");
errorOut.append(oStream.toString());
errorOut.append("\n-->\n");
pSession.setAttribute("error.output",errorOut.toString());
Map map = request.getParameterMap();
pSession.setAttribute("error.map",map);
}
示例9
@Override
public void handleActionRequest(ActionRequest request, ActionResponse response) throws Exception {
// Delegate to PortletContentGenerator for checking and preparing.
check(request, response);
// Execute in synchronized block if required.
if (this.synchronizeOnSession) {
PortletSession session = request.getPortletSession(false);
if (session != null) {
Object mutex = PortletUtils.getSessionMutex(session);
synchronized (mutex) {
handleActionRequestInternal(request, response);
return;
}
}
}
handleActionRequestInternal(request, response);
}
示例10
/**
* Returns the portlet session.
* <p>
* Note that since portlet request instance is created everytime the portlet
* container receives an incoming request, the portlet session instance held
* by the request instance is also re-created for each incoming request.
* </p>
*/
@Override
public PortletSession getPortletSession(boolean create) {
if (isDebug) {
LOG.debug("Retrieving portlet session (create=" + create + ")");
}
if ((cachedPortletSession == null) || cachedPortletSession.isInvalidated()) {
//
// It is critical that we don't retrieve the portlet session until the
// cross context dispatch has been completed. If we do then we risk
// having a cached version which is invalid for the context within
// which it exists.
//
if (portletConfig == null) {
throw new IllegalStateException(EXCEPTIONS.getString("error.session.illegalState"));
}
//
// We must make sure that if the session has been invalidated (perhaps
// through setMaxIntervalTimeout()) and the underlying request
// returns null that we no longer use the cached version.
// We have to check (ourselves) if the session has exceeded its max
// inactive interval. If so, we should invalidate the underlying
// HttpSession and recreate a new one (if the create flag is set to
// true) -- We just cannot depend on the implementation of
// javax.servlet.http.HttpSession!
//
HttpSession httpSession = getServletRequest().getSession(create);
if (httpSession != null) {
// HttpSession is not null does NOT mean that it is valid.
int maxInactiveInterval = httpSession.getMaxInactiveInterval();
long lastAccesstime = httpSession.getLastAccessedTime();// lastAccesstime checks added for PLUTO-436
if (maxInactiveInterval >= 0 && lastAccesstime > 0) { // < 0 => Never expires.
long maxInactiveTime = httpSession.getMaxInactiveInterval() * 1000L;
long currentInactiveTime = System.currentTimeMillis() - lastAccesstime;
if (currentInactiveTime > maxInactiveTime) {
if (isDebug) {
LOG.debug("The underlying HttpSession is expired and " + "should be invalidated.");
}
httpSession.invalidate();
httpSession = getServletRequest().getSession(create);
// Added for PLUTO-436
// a cached portletSession is no longer useable.
// a new one will be created below.
}
}
}
if (httpSession == null) {
if (isDebug) {
LOG.debug("The underlying HttpSession is not available: " + "no session will be returned.");
}
return null;
}
//
// If we reach here, we are sure that the underlying HttpSession is
// available. If we haven't created and cached a portlet session
// instance, we will create and cache one now.
//
final ContainerServices containerServices = container.getContainerServices();
final PortletEnvironmentService portletEnvironmentService = containerServices.getPortletEnvironmentService();
cachedPortletSession = new CachedPortletSessionImpl(portletEnvironmentService.createPortletSession(
portletConfig.getPortletContext(), getPortletWindow(), httpSession));
if (CachedPortletSessionUtil.INVALIDATED_SESSIONS.containsKey(httpSession.getId())) {
synchronized (httpSession) {
Enumeration<String> attributeNames = httpSession.getAttributeNames();
if (attributeNames.hasMoreElements()) {
while (attributeNames.hasMoreElements()) {
String attributeName = attributeNames.nextElement();
httpSession.removeAttribute(attributeName);
}
CachedPortletSessionUtil.INVALIDATED_SESSIONS.remove(httpSession.getId());
}
}
}
}
return cachedPortletSession;
}
示例11
/**
* FIXME: should this test reside in this class? -- ZHENG Zhong
*/
protected TestResult checkGetContextFromSession(PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Ensure that the PortletContext can be retrieved "
+ "from the portlet session.");
PortletContext context = session.getPortletContext();
if (context != null) {
result.setReturnCode(TestResult.PASSED);
} else {
result.setReturnCode(TestResult.FAILED);
result.setResultMessage("Fail to retrieve PortletContext from "
+ "PortletSession: null returned.");
}
return result;
}
示例12
public Enumeration<String> getAttributeNames(int scope) {
// Return all attribute names in the nested HttpSession object.
if (scope == PortletSession.APPLICATION_SCOPE) {
return httpSession.getAttributeNames();
}
// Return attribute names with the portlet-scoped prefix.
Vector<String> portletScopedNames = new Vector<String>();
for (Enumeration<String> en = httpSession.getAttributeNames();
en.hasMoreElements(); ) {
String name = en.nextElement();
if (isInCurrentPortletScope(name)) {
portletScopedNames.add(
PortletSessionUtil.decodeAttributeName(name));
}
}
return portletScopedNames.elements();
}
示例13
@Override
public void setAttribute(String name, Object value, int scope) {
if (scope == PortletSession.PORTLET_SCOPE) {
if (value != null) {
this.portletAttributes.put(name, value);
}
else {
this.portletAttributes.remove(name);
}
}
else if (scope == PortletSession.APPLICATION_SCOPE) {
if (value != null) {
this.applicationAttributes.put(name, value);
}
else {
this.applicationAttributes.remove(name);
}
}
}
示例14
protected TestResult checkSetAppScopedAttributeElsewhereSeenHere(
PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Ensure application scoped attributes set "
+ "elsewhere in portlet session can be seen here.");
Object value = session.getAttribute(EXT_KEY,
PortletSession.APPLICATION_SCOPE);
if (VALUE.equals(value)) {
result.setReturnCode(TestResult.PASSED);
} else {
result.setReturnCode(TestResult.WARNING);
result.setResultMessage("This test will not pass until you have "
+ "opened the external resource using the link provided below.");
}
return result;
}
示例15
@Override
public void setAttribute(String name, Object value, int scope) {
if (scope == PortletSession.PORTLET_SCOPE) {
if (value != null) {
this.portletAttributes.put(name, value);
}
else {
this.portletAttributes.remove(name);
}
}
else if (scope == PortletSession.APPLICATION_SCOPE) {
if (value != null) {
this.applicationAttributes.put(name, value);
}
else {
this.applicationAttributes.remove(name);
}
}
}
示例16
public static Object getAttribute(String name, ExternalContext externalContext) {
Object session = externalContext.getSession(false);
if (session instanceof PortletSession) {
return ((PortletSession) session).getAttribute(name, PortletSession.APPLICATION_SCOPE);
}
else if (session != null) {
return externalContext.getSessionMap().get(name);
}
else {
return null;
}
}
示例17
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
throws PortletException, IOException {
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
PrintWriter writer = portletResp.getWriter();
PortletSession ps = portletReq.getPortletSession();
String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardServletActionResponse", APPLICATION_SCOPE);
if (msg != null) {
writer.write("<p>" + msg + "</p><br/>\n");
ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardServletActionResponse", APPLICATION_SCOPE);
}
/* TestCase: V2DispatcherReqRespTests5S_SPEC2_19_ForwardServletActionResponse_sendRedirect */
/* Details: "In a target servlet of a forward in the Action phase, */
/* the method HttpServletResponse.sendRedirect must provide the same */
/* functionality as ActionResponse.sendRedirect" */
{
PortletURL aurl = portletResp.createActionURL();
aurl.setParameters(portletReq.getPrivateParameterMap());
TestButton tb = new TestButton(V2DISPATCHERREQRESPTESTS5S_SPEC2_19_FORWARDSERVLETACTIONRESPONSE_SENDREDIRECT, aurl);
tb.writeTo(writer);
}
}
示例18
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
throws PortletException, IOException {
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
PrintWriter writer = portletResp.getWriter();
PortletSession ps = portletReq.getPortletSession();
String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse", APPLICATION_SCOPE);
if (msg != null) {
writer.write("<p>" + msg + "</p><br/>\n");
ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse", APPLICATION_SCOPE);
}
/* TestCase: V2DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse_sendRedirect */
/* Details: "In a target jsp of a forward in the Action phase, the */
/* method HttpServletResponse.sendRedirect must provide the same */
/* functionality as ActionResponse.sendRedirect" */
{
PortletURL aurl = portletResp.createActionURL();
aurl.setParameters(portletReq.getPrivateParameterMap());
TestButton tb = new TestButton(V2DISPATCHERREQRESPTESTS5S_SPEC2_19_FORWARDJSPACTIONRESPONSE_SENDREDIRECT, aurl);
tb.writeTo(writer);
}
}
示例19
@Override
public void processAction(ActionRequest portletReq, ActionResponse portletResp)
throws PortletException, IOException {
JSR286ApiTestCaseDetails tcd = new JSR286ApiTestCaseDetails();
portletResp.setRenderParameters(portletReq.getParameterMap());
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
StringWriter writer = new StringWriter();
/* TestCase: V2FilterTests_FilterChain_ApiActionFilter_invokeActionFilter2 */
/* Details: "Invoking doFilter(ActionRequest, ActionResponse): causes */
/* portlet action method to be invoked" */
TestResult tr1 =
tcd.getTestResultFailed(V2FILTERTESTS_FILTERCHAIN_APIACTIONFILTER_INVOKEACTIONFILTER2);
if (FilterTests_FilterChain_ApiActionFilter_filter2.tr1_success) {
tr1.setTcSuccess(true);
}
tr1.writeTo(writer);
PortletSession ps = portletReq.getPortletSession();
String msg =
(String) ps.getAttribute(RESULT_ATTR_PREFIX + "FilterTests_FilterChain_ApiActionFilter",
APPLICATION_SCOPE);
portletReq.getPortletSession().setAttribute(
Constants.RESULT_ATTR_PREFIX + "FilterTests_FilterChain_ApiActionFilter",
msg + writer.toString(), APPLICATION_SCOPE);
}
示例20
@Override
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
PortletTracer.info(Constants.NOME_MODULO, "AdapterPortlet", "action", "Invocato");
// set into threadLocal variables the jsr 168 portlet object
PortletAccess.setPortletConfig(getPortletConfig());
PortletAccess.setPortletRequest(request);
PortletAccess.setPortletResponse(response);
PortletSession portletSession = request.getPortletSession();
portletSession.setAttribute("BrowserLocale", request.getLocale());
processService(request, response);
}
示例21
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
throws PortletException, IOException {
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
PrintWriter writer = portletResp.getWriter();
PortletSession ps = portletReq.getPortletSession();
String msg =
(String) ps.getAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
APPLICATION_SCOPE);
if (msg != null) {
writer.write("<p>" + msg + "</p><br/>\n");
ps.removeAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
APPLICATION_SCOPE);
}
/* TestCase: V2AnnotationTests_ProcessAction_ApiAction_name */
/* Details: "Method name(): On an action request, the method is */
/* executed if the parameter \"javax.portlet.action\" matches the */
/* name field" */
{
PortletURL aurl = portletResp.createActionURL();
aurl.setParameter(ActionRequest.ACTION_NAME, V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME);
TestButton tb = new TestButton(V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME, aurl);
tb.writeTo(writer);
}
}
示例22
/**
* Invokes the test method ('<code>check*</code>') by preparing method
* parameters. A test method may accept the following types of parameters:
* <ul>
* <li><code>javax.portlet.PortletConfig</code></li>
* <li><code>javax.portlet.PortletContext</code></li>
* <li><code>javax.portlet.PortletRequest</code></li>
* <li><code>javax.portlet.PortletResponse</code></li>
* <li><code>javax.portlet.PortletSession</code></li>
* </ul>
*/
private TestResult invoke(Method method,
PortletConfig config,
PortletContext context,
PortletRequest request,
PortletResponse response)
throws IllegalAccessException, InvocationTargetException {
Class<?>[] paramTypes = method.getParameterTypes();
Object[] paramValues = new Object[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
if (paramTypes[i].equals(PortletConfig.class)) {
paramValues[i] = config;
} else if (paramTypes[i].equals(PortletContext.class)) {
paramValues[i] = context;
} else if (paramTypes[i].isAssignableFrom(request.getClass())) {
paramValues[i] = request;
} else if (paramTypes[i].isAssignableFrom(response.getClass())) {
paramValues[i] = response;
} else if (paramTypes[i].equals(PortletSession.class)) {
paramValues[i] = request.getPortletSession();
}
}
TestResult result = (TestResult) method.invoke(this, paramValues);
return result;
}
示例23
/**
* Sets the portlet session bean holder in a ThreadLocal object for the given portlet session. If no bean holder
* exists in the session, a new one is created.
*
* @param ps
* The portlet session.
* @return The portlet session bean holder
*/
public static void setBeanHolder(PortletRequest req, PortletSessionScopedConfig config) {
PortletSession ps = req.getPortletSession();
String windowId = req.getWindowID();
PortletSessionScopedBeanMap map = (PortletSessionScopedBeanMap) ps.getAttribute(ATTRIBNAME,
PortletSession.APPLICATION_SCOPE);
boolean createdMap = false;
if (map == null) {
map = new PortletSessionScopedBeanMap();
ps.setAttribute(ATTRIBNAME, map, PortletSession.APPLICATION_SCOPE);
createdMap = true;
}
PortletSessionBeanHolder holder = new PortletSessionBeanHolder(map, windowId, config);
holders.set(holder);
if (isTrace) {
StringBuilder txt = new StringBuilder(80);
txt.append("Set portlet session bean holder.");
txt.append(" ThreadId: ").append(Thread.currentThread().getId());
txt.append(", PortletSession: ").append(ps.getId());
txt.append(", WindowId: ").append(windowId);
txt.append(", Added new BeanMap to session: ").append(createdMap);
LOG.debug(txt.toString());
}
}
示例24
/**
* Exposes the {@link PortletSession} that we're wrapping.
* @param allowCreate whether to allow creation of a new session if none exists yet
*/
protected final PortletSession getSession(boolean allowCreate) {
if (isRequestActive()) {
return this.request.getPortletSession(allowCreate);
}
else {
// Access through stored session reference, if any...
if (this.session == null && allowCreate) {
throw new IllegalStateException(
"No session found and request already completed - cannot create new session!");
}
return this.session;
}
}
示例25
protected TestResult checkEnumerateAttributes(PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Sets session attributes and enumerates over them.");
int count = 5;
for (int i = 0; i < count; i++) {
session.setAttribute(KEY + "." + i, VAL);
}
int found = 0;
for (Enumeration<String> en = session.getAttributeNames();
en.hasMoreElements(); ) {
String name = (String) en.nextElement();
if (name.startsWith(KEY)) {
found++;
}
}
if (count != found) {
result.setReturnCode(TestResult.FAILED);
result.setResultMessage("Expected " + count + " attributes. "
+ "Found " + found);
} else {
result.setReturnCode(TestResult.PASSED);
}
return result;
}
示例26
public void doEdit(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
response.setContentType("text/html");
log.debug("==== doEdit called ====");
PortletSession pSession = request.getPortletSession(true);
String title = getTitleString(request);
if ( title != null ) response.setTitle(title);
// Debug
String inputData = (String) pSession.getAttribute("sakai.descriptor");
if ( inputData != null ) log.debug("descriptor.length()={}", inputData.length());
String url = (String) pSession.getAttribute("sakai.url");
log.debug("sakai.url={}", url);
String view = (String) pSession.getAttribute("sakai.view");
log.debug("sakai.view={}", view);
if ( "edit.reset".equals(view) ) {
sendToJSP(request, response, "/editreset.jsp");
} else {
prepareEdit(request);
sendToJSP(request, response, "/edit.jsp");
}
clearErrorMessage(request);
log.debug("==== doEdit called ====");
}
示例27
@Override
public void handleEventRequest(
EventRequest request, EventResponse response) throws Exception {
if (!(this.portletInstance instanceof EventPortlet)) {
logger.debug("Ignoring event request for non-event target portlet: " + this.portletInstance.getClass());
return;
}
EventPortlet eventPortlet = (EventPortlet) this.portletInstance;
// Delegate to PortletContentGenerator for checking and preparing.
check(request, response);
// Execute in synchronized block if required.
if (isSynchronizeOnSession()) {
PortletSession session = request.getPortletSession(false);
if (session != null) {
Object mutex = PortletUtils.getSessionMutex(session);
synchronized (mutex) {
eventPortlet.processEvent(request, response);
return;
}
}
}
eventPortlet.processEvent(request, response);
}
示例28
@Override
public PortletSession getPortletSession(boolean create) {
String meth = "getPortletSession";
Object[] args = { create };
PortletSession ret = sess;
retVal = ret;
checkArgs(meth, args);
return ret;
}
示例29
protected TestResult checkSetAppScopedAttribute(PortletSession session) {
TestResult result = new TestResult();
result.setDescription("Set an application scoped session attribute "
+ "and ensure it's retrievable.");
result.setSpecPLT("15.3");
session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
if (VALUE.equals(value)) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("session attribute", value, VALUE, result);
}
return result;
}
示例30
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {
long tid = Thread.currentThread().getId();
portletReq.setAttribute(THREADID_ATTR, tid);
PrintWriter writer = portletResp.getWriter();
PortletSession ps = portletReq.getPortletSession();
String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardServletAction",
APPLICATION_SCOPE);
if (msg != null) {
writer.write("<p>" + msg + "</p><br/>\n");
ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardServletAction", APPLICATION_SCOPE);
}
/* TestCase: V2DispatcherTests4_SPEC2_19_ForwardServletAction_invoke3 */
/* Details: "Parameters to the forward method for a target servlet */
/* can be wrapped request and response classes from the portlet */
/* lifecyle method initiating the include" */
{
PortletURL aurl = portletResp.createActionURL();
aurl.setParameters(portletReq.getPrivateParameterMap());
TestButton tb = new TestButton(V2DISPATCHERTESTS4_SPEC2_19_FORWARDSERVLETACTION_INVOKE3, aurl);
tb.writeTo(writer);
}
}