2
2
3
3
import com .fasterxml .jackson .core .JsonProcessingException ;
4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
+ import java .io .IOException ;
6
+ import java .io .InputStream ;
7
+ import java .nio .charset .Charset ;
8
+ import java .util .HashMap ;
9
+ import java .util .Map ;
10
+ import java .util .Properties ;
5
11
import lombok .extern .slf4j .Slf4j ;
6
12
import org .apache .commons .lang3 .StringUtils ;
7
- import org .apache .commons .lang3 . text .StrSubstitutor ;
13
+ import org .apache .commons .text .StringSubstitutor ;
8
14
import org .springframework .beans .factory .annotation .Autowired ;
9
15
import org .springframework .core .env .Environment ;
10
16
import org .springframework .core .io .ClassPathResource ;
11
- import org .springframework .http .MediaType ;
12
17
import org .springframework .security .web .csrf .CsrfToken ;
13
18
import org .springframework .util .StreamUtils ;
14
19
import org .springframework .web .bind .annotation .PathVariable ;
15
20
import org .springframework .web .bind .annotation .RequestParam ;
16
21
17
- import java .io .IOException ;
18
- import java .io .InputStream ;
19
- import java .nio .charset .Charset ;
20
- import java .util .HashMap ;
21
- import java .util .Map ;
22
- import java .util .Properties ;
23
-
24
22
/**
25
23
* @author Andrew Potter
26
24
*/
@@ -61,17 +59,10 @@ private void loadProps() throws IOException {
61
59
private void loadHeaders () {
62
60
PropertyGroupReader propertyReader = new PropertyGroupReader (environment , "graphiql.headers." );
63
61
headerProperties = propertyReader .load ();
64
- addIfAbsent (headerProperties , "Accept" );
65
- addIfAbsent (headerProperties , "Content-Type" );
66
62
}
67
63
68
- private void addIfAbsent (Properties headerProperties , String header ) {
69
- if (!headerProperties .containsKey (header )) {
70
- headerProperties .setProperty (header , MediaType .APPLICATION_JSON_VALUE );
71
- }
72
- }
73
-
74
- public byte [] graphiql (String contextPath , @ PathVariable Map <String , String > params , Object csrf ) {
64
+ public byte [] graphiql (String contextPath , @ PathVariable Map <String , String > params ,
65
+ Object csrf ) {
75
66
if (csrf != null ) {
76
67
CsrfToken csrfToken = (CsrfToken ) csrf ;
77
68
headerProperties .setProperty (csrfToken .getHeaderName (), csrfToken .getToken ());
@@ -83,7 +74,7 @@ public byte[] graphiql(String contextPath, @PathVariable Map<String, String> par
83
74
contextPath + graphiQLProperties .getSTATIC ().getBasePath ()
84
75
);
85
76
86
- String populatedTemplate = StrSubstitutor .replace (template , replacements );
77
+ String populatedTemplate = StringSubstitutor .replace (template , replacements );
87
78
return populatedTemplate .getBytes (Charset .defaultCharset ());
88
79
}
89
80
@@ -97,7 +88,8 @@ private Map<String, String> getReplacements(
97
88
replacements .put ("subscriptionsEndpoint" , subscriptionsEndpoint );
98
89
replacements .put ("staticBasePath" , staticBasePath );
99
90
replacements .put ("pageTitle" , graphiQLProperties .getPageTitle ());
100
- replacements .put ("pageFavicon" , getResourceUrl (staticBasePath , "favicon.ico" , FAVICON_GRAPHQL_ORG ));
91
+ replacements
92
+ .put ("pageFavicon" , getResourceUrl (staticBasePath , "favicon.ico" , FAVICON_GRAPHQL_ORG ));
101
93
replacements .put ("es6PromiseJsUrl" , getResourceUrl (staticBasePath , "es6-promise.auto.min.js" ,
102
94
joinCdnjsPath ("es6-promise" , "4.1.1" , "es6-promise.auto.min.js" )));
103
95
replacements .put ("fetchJsUrl" , getResourceUrl (staticBasePath , "fetch.min.js" ,
@@ -123,9 +115,11 @@ private Map<String, String> getReplacements(
123
115
log .error ("Cannot serialize headers" , e );
124
116
}
125
117
replacements
126
- .put ("subscriptionClientTimeout" , String .valueOf (graphiQLProperties .getSubscriptions ().getTimeout () * 1000 ));
118
+ .put ("subscriptionClientTimeout" ,
119
+ String .valueOf (graphiQLProperties .getSubscriptions ().getTimeout () * 1000 ));
127
120
replacements
128
- .put ("subscriptionClientReconnect" , String .valueOf (graphiQLProperties .getSubscriptions ().isReconnect ()));
121
+ .put ("subscriptionClientReconnect" ,
122
+ String .valueOf (graphiQLProperties .getSubscriptions ().isReconnect ()));
129
123
replacements .put ("editorThemeCss" , getEditorThemeCssURL ());
130
124
return replacements ;
131
125
}
@@ -161,7 +155,8 @@ private String joinJsDelivrPath(String library, String cdnVersion, String cdnFil
161
155
return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName ;
162
156
}
163
157
164
- private String constructGraphQlEndpoint (String contextPath , @ RequestParam Map <String , String > params ) {
158
+ private String constructGraphQlEndpoint (String contextPath ,
159
+ @ RequestParam Map <String , String > params ) {
165
160
String endpoint = graphiQLProperties .getEndpoint ().getGraphql ();
166
161
for (Map .Entry <String , String > param : params .entrySet ()) {
167
162
endpoint = endpoint .replaceAll ("\\ {" + param .getKey () + "}" , param .getValue ());
0 commit comments