@@ -47,6 +47,7 @@ public static class Builder {
47
47
private URNFactory urnFactory ;
48
48
private final Map <String , JsonMetaSchema > jsonMetaSchemas = new HashMap <String , JsonMetaSchema >();
49
49
private final Map <String , String > uriMap = new HashMap <String , String >();
50
+ private boolean forceHttps = true ;
50
51
51
52
52
53
public Builder () {
@@ -139,7 +140,10 @@ public Builder addUrnFactory(URNFactory urnFactory) {
139
140
return this ;
140
141
}
141
142
142
-
143
+ public Builder forceHttps (boolean forceHttps ) {
144
+ this .forceHttps = forceHttps ;
145
+ return this ;
146
+ }
143
147
144
148
public JsonSchemaFactory build () {
145
149
// create builtin keywords with (custom) formats.
@@ -150,7 +154,8 @@ public JsonSchemaFactory build() {
150
154
new URISchemeFetcher (uriFetcherMap ),
151
155
urnFactory ,
152
156
jsonMetaSchemas ,
153
- uriMap
157
+ uriMap ,
158
+ forceHttps
154
159
);
155
160
}
156
161
}
@@ -163,6 +168,7 @@ public JsonSchemaFactory build() {
163
168
private final Map <String , JsonMetaSchema > jsonMetaSchemas ;
164
169
private final Map <String , String > uriMap ;
165
170
private final ConcurrentMap <URI , JsonSchema > uriSchemaCache = new ConcurrentHashMap <URI , JsonSchema >();
171
+ private final boolean forceHttps ;
166
172
167
173
168
174
private JsonSchemaFactory (
@@ -172,7 +178,8 @@ private JsonSchemaFactory(
172
178
final URISchemeFetcher uriFetcher ,
173
179
final URNFactory urnFactory ,
174
180
final Map <String , JsonMetaSchema > jsonMetaSchemas ,
175
- final Map <String , String > uriMap ) {
181
+ final Map <String , String > uriMap ,
182
+ final boolean forceHttps ) {
176
183
if (mapper == null ) {
177
184
throw new IllegalArgumentException ("ObjectMapper must not be null" );
178
185
} else if (defaultMetaSchemaURI == null || defaultMetaSchemaURI .trim ().isEmpty ()) {
@@ -195,6 +202,7 @@ private JsonSchemaFactory(
195
202
this .urnFactory = urnFactory ;
196
203
this .jsonMetaSchemas = jsonMetaSchemas ;
197
204
this .uriMap = uriMap ;
205
+ this .forceHttps = forceHttps ;
198
206
}
199
207
200
208
/**
@@ -273,7 +281,7 @@ protected ValidationContext createValidationContext(final JsonNode schemaNode) {
273
281
274
282
private JsonMetaSchema findMetaSchemaForSchema (final JsonNode schemaNode ) {
275
283
final JsonNode uriNode = schemaNode .get ("$schema" );
276
- final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue ());
284
+ final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue (), forceHttps );
277
285
final JsonMetaSchema jsonMetaSchema = jsonMetaSchemas .get (uri );
278
286
if (jsonMetaSchema == null ) {
279
287
throw new JsonSchemaException ("Unknown MetaSchema: " + uri );
@@ -395,10 +403,11 @@ private boolean idMatchesSourceUri(final JsonMetaSchema metaSchema, final JsonNo
395
403
return result ;
396
404
}
397
405
398
- static protected String normalizeMetaSchemaUri (String u ) {
406
+ static protected String normalizeMetaSchemaUri (String u , boolean forceHttps ) {
399
407
try {
400
408
URI uri = new URI (u );
401
- URI newUri = new URI ("https" , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
409
+ String scheme = forceHttps ? "https" : uri .getScheme ();
410
+ URI newUri = new URI (scheme , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
402
411
return newUri .toString ();
403
412
} catch (URISyntaxException e ) {
404
413
throw new JsonSchemaException ("Wrong MetaSchema URI: " + u );
0 commit comments