22
33import com .fasterxml .jackson .core .JsonProcessingException ;
44import 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 ;
511import lombok .extern .slf4j .Slf4j ;
612import org .apache .commons .lang3 .StringUtils ;
7- import org .apache .commons .lang3 . text .StrSubstitutor ;
13+ import org .apache .commons .text .StringSubstitutor ;
814import org .springframework .beans .factory .annotation .Autowired ;
915import org .springframework .core .env .Environment ;
1016import org .springframework .core .io .ClassPathResource ;
11- import org .springframework .http .MediaType ;
1217import org .springframework .security .web .csrf .CsrfToken ;
1318import org .springframework .util .StreamUtils ;
1419import org .springframework .web .bind .annotation .PathVariable ;
1520import org .springframework .web .bind .annotation .RequestParam ;
1621
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-
2422/**
2523 * @author Andrew Potter
2624 */
@@ -61,17 +59,10 @@ private void loadProps() throws IOException {
6159 private void loadHeaders () {
6260 PropertyGroupReader propertyReader = new PropertyGroupReader (environment , "graphiql.headers." );
6361 headerProperties = propertyReader .load ();
64- addIfAbsent (headerProperties , "Accept" );
65- addIfAbsent (headerProperties , "Content-Type" );
6662 }
6763
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 ) {
7566 if (csrf != null ) {
7667 CsrfToken csrfToken = (CsrfToken ) csrf ;
7768 headerProperties .setProperty (csrfToken .getHeaderName (), csrfToken .getToken ());
@@ -83,7 +74,7 @@ public byte[] graphiql(String contextPath, @PathVariable Map<String, String> par
8374 contextPath + graphiQLProperties .getSTATIC ().getBasePath ()
8475 );
8576
86- String populatedTemplate = StrSubstitutor .replace (template , replacements );
77+ String populatedTemplate = StringSubstitutor .replace (template , replacements );
8778 return populatedTemplate .getBytes (Charset .defaultCharset ());
8879 }
8980
@@ -97,7 +88,8 @@ private Map<String, String> getReplacements(
9788 replacements .put ("subscriptionsEndpoint" , subscriptionsEndpoint );
9889 replacements .put ("staticBasePath" , staticBasePath );
9990 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 ));
10193 replacements .put ("es6PromiseJsUrl" , getResourceUrl (staticBasePath , "es6-promise.auto.min.js" ,
10294 joinCdnjsPath ("es6-promise" , "4.1.1" , "es6-promise.auto.min.js" )));
10395 replacements .put ("fetchJsUrl" , getResourceUrl (staticBasePath , "fetch.min.js" ,
@@ -123,9 +115,11 @@ private Map<String, String> getReplacements(
123115 log .error ("Cannot serialize headers" , e );
124116 }
125117 replacements
126- .put ("subscriptionClientTimeout" , String .valueOf (graphiQLProperties .getSubscriptions ().getTimeout () * 1000 ));
118+ .put ("subscriptionClientTimeout" ,
119+ String .valueOf (graphiQLProperties .getSubscriptions ().getTimeout () * 1000 ));
127120 replacements
128- .put ("subscriptionClientReconnect" , String .valueOf (graphiQLProperties .getSubscriptions ().isReconnect ()));
121+ .put ("subscriptionClientReconnect" ,
122+ String .valueOf (graphiQLProperties .getSubscriptions ().isReconnect ()));
129123 replacements .put ("editorThemeCss" , getEditorThemeCssURL ());
130124 return replacements ;
131125 }
@@ -161,7 +155,8 @@ private String joinJsDelivrPath(String library, String cdnVersion, String cdnFil
161155 return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName ;
162156 }
163157
164- private String constructGraphQlEndpoint (String contextPath , @ RequestParam Map <String , String > params ) {
158+ private String constructGraphQlEndpoint (String contextPath ,
159+ @ RequestParam Map <String , String > params ) {
165160 String endpoint = graphiQLProperties .getEndpoint ().getGraphql ();
166161 for (Map .Entry <String , String > param : params .entrySet ()) {
167162 endpoint = endpoint .replaceAll ("\\ {" + param .getKey () + "}" , param .getValue ());
0 commit comments