Some minor optimizations after performance profiling.
- DefaultConversionService no longer uses addDefaultAlias since that's quite expensive because of all the string manipulations. - The external context implementations now hold on to their attribute and parameter maps iso creating new ones every time.
This commit is contained in:
@@ -46,18 +46,20 @@ public class DefaultConversionService extends GenericConversionService {
|
||||
addConverter(new TextToNumber(new SimpleFormatterFactory()));
|
||||
addConverter(new TextToBoolean());
|
||||
addConverter(new TextToLabeledEnum());
|
||||
addDefaultAlias(String.class);
|
||||
addDefaultAlias(Short.class);
|
||||
addDefaultAlias(Integer.class);
|
||||
|
||||
// we're not using addDefaultAlias here for efficieny reasons
|
||||
addAlias("string", String.class);
|
||||
addAlias("short", Short.class);
|
||||
addAlias("integer", Integer.class);
|
||||
addAlias("int", Integer.class);
|
||||
addDefaultAlias(Byte.class);
|
||||
addDefaultAlias(Long.class);
|
||||
addDefaultAlias(Float.class);
|
||||
addDefaultAlias(Double.class);
|
||||
addDefaultAlias(BigInteger.class);
|
||||
addDefaultAlias(BigDecimal.class);
|
||||
addDefaultAlias(Boolean.class);
|
||||
addDefaultAlias(Class.class);
|
||||
addDefaultAlias(LabeledEnum.class);
|
||||
addAlias("byte", Byte.class);
|
||||
addAlias("long", Long.class);
|
||||
addAlias("float", Float.class);
|
||||
addAlias("double", Double.class);
|
||||
addAlias("bigInteger", BigInteger.class);
|
||||
addAlias("bigDecimal", BigDecimal.class);
|
||||
addAlias("boolean", Boolean.class);
|
||||
addAlias("class", Class.class);
|
||||
addAlias("labeledEnum", LabeledEnum.class);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,13 @@ public class PortletExternalContext implements ExternalContext {
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
private ParameterMap requestParameterMap;
|
||||
private MutableAttributeMap requestMap;
|
||||
private SharedAttributeMap sessionMap;
|
||||
private SharedAttributeMap globalSessionMap;
|
||||
private SharedAttributeMap applicationMap;
|
||||
private MutableAttributeMap userInfoMap;
|
||||
|
||||
/**
|
||||
* Create an external context wrapping given Portlet context, request and response.
|
||||
@@ -64,6 +71,14 @@ public class PortletExternalContext implements ExternalContext {
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
|
||||
this.requestParameterMap = new LocalParameterMap(new PortletRequestParameterMap(request));
|
||||
this.requestMap = new LocalAttributeMap(new PortletRequestMap(request));
|
||||
this.sessionMap = new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.PORTLET_SCOPE));
|
||||
this.globalSessionMap = new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.APPLICATION_SCOPE));
|
||||
this.applicationMap = new LocalSharedAttributeMap(new PortletContextMap(context));
|
||||
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
|
||||
this.userInfoMap = userInfo != null ? new LocalAttributeMap(userInfo) : null;
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
@@ -79,23 +94,23 @@ public class PortletExternalContext implements ExternalContext {
|
||||
}
|
||||
|
||||
public ParameterMap getRequestParameterMap() {
|
||||
return new LocalParameterMap(new PortletRequestParameterMap(request));
|
||||
return requestParameterMap;
|
||||
}
|
||||
|
||||
public MutableAttributeMap getRequestMap() {
|
||||
return new LocalAttributeMap(new PortletRequestMap(request));
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getSessionMap() {
|
||||
return new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.PORTLET_SCOPE));
|
||||
return sessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getGlobalSessionMap() {
|
||||
return new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.APPLICATION_SCOPE));
|
||||
return globalSessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getApplicationMap() {
|
||||
return new LocalSharedAttributeMap(new PortletContextMap(context));
|
||||
return applicationMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,12 +118,7 @@ public class PortletExternalContext implements ExternalContext {
|
||||
* @return the Portlet user info
|
||||
*/
|
||||
public MutableAttributeMap getUserInfoMap() {
|
||||
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
|
||||
if (userInfo != null) {
|
||||
return new LocalAttributeMap(userInfo);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return userInfoMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,6 +51,11 @@ public class ServletExternalContext implements ExternalContext {
|
||||
* The response.
|
||||
*/
|
||||
private HttpServletResponse response;
|
||||
|
||||
private ParameterMap requestParameterMap;
|
||||
private MutableAttributeMap requestMap;
|
||||
private SharedAttributeMap sessionMap;
|
||||
private SharedAttributeMap applicationMap;
|
||||
|
||||
/**
|
||||
* Create a new external context wrapping given servlet HTTP request and
|
||||
@@ -63,6 +68,11 @@ public class ServletExternalContext implements ExternalContext {
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
|
||||
this.requestParameterMap = new LocalParameterMap(new HttpServletRequestParameterMap(request));
|
||||
this.requestMap = new LocalAttributeMap(new HttpServletRequestMap(request));
|
||||
this.sessionMap = new LocalSharedAttributeMap(new HttpSessionMap(request));
|
||||
this.applicationMap = new LocalSharedAttributeMap(new HttpServletContextMap(context));
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
@@ -78,15 +88,15 @@ public class ServletExternalContext implements ExternalContext {
|
||||
}
|
||||
|
||||
public ParameterMap getRequestParameterMap() {
|
||||
return new LocalParameterMap(new HttpServletRequestParameterMap(request));
|
||||
return requestParameterMap;
|
||||
}
|
||||
|
||||
public MutableAttributeMap getRequestMap() {
|
||||
return new LocalAttributeMap(new HttpServletRequestMap(request));
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getSessionMap() {
|
||||
return new LocalSharedAttributeMap(new HttpSessionMap(request));
|
||||
return sessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getGlobalSessionMap() {
|
||||
@@ -94,7 +104,7 @@ public class ServletExternalContext implements ExternalContext {
|
||||
}
|
||||
|
||||
public SharedAttributeMap getApplicationMap() {
|
||||
return new LocalSharedAttributeMap(new HttpServletContextMap(context));
|
||||
return applicationMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,6 +58,11 @@ public class JsfExternalContext implements ExternalContext {
|
||||
this.facesContext = facesContext;
|
||||
}
|
||||
|
||||
private ParameterMap requestParameterMap;
|
||||
private MutableAttributeMap requestMap;
|
||||
private SharedAttributeMap sessionMap;
|
||||
private SharedAttributeMap applicationMap;
|
||||
|
||||
/**
|
||||
* Creates a JSF External Context.
|
||||
* @param facesContext the JSF faces context.
|
||||
@@ -68,6 +73,11 @@ public class JsfExternalContext implements ExternalContext {
|
||||
this.facesContext = facesContext;
|
||||
this.actionId = actionId;
|
||||
this.outcome = outcome;
|
||||
|
||||
this.requestParameterMap = new LocalParameterMap(facesContext.getExternalContext().getRequestParameterMap());
|
||||
this.requestMap = new LocalAttributeMap(facesContext.getExternalContext().getRequestMap());
|
||||
this.sessionMap = new LocalSharedAttributeMap(new SessionSharedMap(facesContext));
|
||||
this.applicationMap = new LocalSharedAttributeMap(new ApplicationSharedMap(facesContext));
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
@@ -83,15 +93,15 @@ public class JsfExternalContext implements ExternalContext {
|
||||
}
|
||||
|
||||
public ParameterMap getRequestParameterMap() {
|
||||
return new LocalParameterMap(facesContext.getExternalContext().getRequestParameterMap());
|
||||
return requestParameterMap;
|
||||
}
|
||||
|
||||
public MutableAttributeMap getRequestMap() {
|
||||
return new LocalAttributeMap(facesContext.getExternalContext().getRequestMap());
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getSessionMap() {
|
||||
return new LocalSharedAttributeMap(new SessionSharedMap(facesContext));
|
||||
return sessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getGlobalSessionMap() {
|
||||
@@ -99,7 +109,7 @@ public class JsfExternalContext implements ExternalContext {
|
||||
}
|
||||
|
||||
public SharedAttributeMap getApplicationMap() {
|
||||
return new LocalSharedAttributeMap(new ApplicationSharedMap(facesContext));
|
||||
return applicationMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,10 @@ import javax.portlet.PortletMode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockActionRequest;
|
||||
import org.springframework.mock.web.portlet.MockActionResponse;
|
||||
import org.springframework.mock.web.portlet.MockPortletContext;
|
||||
import org.springframework.mock.web.portlet.MockRenderRequest;
|
||||
import org.springframework.mock.web.portlet.MockRenderResponse;
|
||||
import org.springframework.webflow.context.portlet.PortletExternalContext;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
@@ -46,7 +49,8 @@ public class SetPortletModeActionTests extends TestCase {
|
||||
|
||||
public void testDoExecute() throws Exception {
|
||||
MockActionResponse mockActionResponse = new MockActionResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(null, null, mockActionResponse);
|
||||
PortletExternalContext externalContext = new PortletExternalContext(
|
||||
new MockPortletContext(), new MockActionRequest(), mockActionResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
|
||||
@@ -59,7 +63,8 @@ public class SetPortletModeActionTests extends TestCase {
|
||||
|
||||
public void testDoExecuteWithPortletModeAsAttribute() throws Exception {
|
||||
MockActionResponse mockActionResponse = new MockActionResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(null, null, mockActionResponse);
|
||||
PortletExternalContext externalContext = new PortletExternalContext(
|
||||
new MockPortletContext(), new MockActionRequest(), mockActionResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
mockRequestContext.setAttribute(SetPortletModeAction.PORTLET_MODE_ATTRIBUTE, PortletMode.HELP);
|
||||
@@ -73,7 +78,8 @@ public class SetPortletModeActionTests extends TestCase {
|
||||
|
||||
public void testDoExecuteWithWrongResponseClass() throws Exception {
|
||||
MockRenderResponse mockRenderResponse = new MockRenderResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(null, null, mockRenderResponse);
|
||||
PortletExternalContext externalContext = new PortletExternalContext(
|
||||
new MockPortletContext(), new MockRenderRequest(), mockRenderResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
mockRequestContext.setAttribute(SetPortletModeAction.PORTLET_MODE_ATTRIBUTE, PortletMode.HELP);
|
||||
|
||||
@@ -21,16 +21,25 @@ import org.springframework.webflow.executor.support.FlowExecutorArgumentExtracti
|
||||
|
||||
public class FlowNavigationHandlerArgumentExtractorTests extends TestCase {
|
||||
|
||||
private FlowNavigationHandlerArgumentExtractor extractor = new FlowNavigationHandlerArgumentExtractor();
|
||||
private FlowNavigationHandlerArgumentExtractor extractor;
|
||||
|
||||
private MockFacesContext facesContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
extractor = new FlowNavigationHandlerArgumentExtractor();
|
||||
|
||||
facesContext = new MockFacesContext();
|
||||
facesContext.setExternalContext(new MockJsfExternalContext());
|
||||
}
|
||||
|
||||
public void testExtractFlowId() {
|
||||
JsfExternalContext context = new JsfExternalContext(new MockFacesContext(), "action", "flowId:foo");
|
||||
JsfExternalContext context = new JsfExternalContext(facesContext, "action", "flowId:foo");
|
||||
String flowId = extractor.extractFlowId(context);
|
||||
assertEquals("Wrong flow id", "foo", flowId);
|
||||
}
|
||||
|
||||
public void testExtractFlowIdWrongFormat() {
|
||||
JsfExternalContext context = new JsfExternalContext(new MockFacesContext(), "action", "flow:foo");
|
||||
JsfExternalContext context = new JsfExternalContext(facesContext, "action", "flow:foo");
|
||||
try {
|
||||
extractor.extractFlowId(context);
|
||||
fail();
|
||||
@@ -41,7 +50,7 @@ public class FlowNavigationHandlerArgumentExtractorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExtractEventId() {
|
||||
JsfExternalContext context = new JsfExternalContext(new MockFacesContext(), "action", "submit");
|
||||
JsfExternalContext context = new JsfExternalContext(facesContext, "action", "submit");
|
||||
String eventId = extractor.extractEventId(context);
|
||||
assertEquals("Wrong event id", "submit", eventId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user