@@ -83,16 +83,24 @@ public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse res
83
83
templateEngine .clearTemplateCache ();
84
84
}
85
85
86
+ HttpServletRequest httpServletRequest = null ;
87
+
88
+ if (request .getHttpSolrCall ().getReq () != null ) {
89
+ httpServletRequest = request .getHttpSolrCall ().getReq ();
90
+ } else if (request .getContext ().containsKey ("httpRequest" )) {
91
+ // requestDispatcher/requestParsers/@addHttpRequestToContext may be disabled
92
+ httpServletRequest = (HttpServletRequest ) request .getContext ().get ("httpRequest" );
93
+ }
94
+
86
95
// Prefill context with some defaults
87
- HttpServletRequest httpServletRequest = (HttpServletRequest ) request .getContext ().get ("httpRequest" );
88
96
WebContext context = new WebContext (
89
97
httpServletRequest ,
90
98
new FakeServletResponse (),
91
99
httpServletRequest .getServletContext (),
92
100
locale
93
101
);
94
102
context .setVariable ("request" , request );
95
- context .setVariable ("params" , toMap ( request .getParams ().toNamedList ()));
103
+ context .setVariable ("params" , request .getParams ().toNamedList (). asShallowMap ( ));
96
104
97
105
// add core properties
98
106
Properties coreProperties = request .getCore ().getResourceLoader ().getCoreProperties ();
@@ -108,23 +116,15 @@ public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse res
108
116
context .setVariable ("response" , rsp );
109
117
110
118
// let subclasses add context info (if needed)
111
- preProcess (context );
119
+ preProcess (context , request , response );
112
120
113
121
getEngine ().process (templateName , context , writer );
114
122
}
115
123
116
- protected void preProcess (WebContext context ) {
124
+ protected void preProcess (WebContext context , SolrQueryRequest request , SolrQueryResponse response ) {
117
125
// hook to customize context, noop by default
118
126
}
119
127
120
- private static Map <String , String > toMap (NamedList <Object > params ) {
121
- Map <String , String > map = new HashMap <>();
122
- for (int i = 0 ; i < params .size (); i ++) {
123
- map .put (params .getName (i ), params .getVal (i ).toString ());
124
- }
125
- return map ;
126
- }
127
-
128
128
protected TemplateEngine getEngine () {
129
129
// create engine
130
130
if (templateEngine == null ) {
0 commit comments