This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gateway): Add Virtual-Host support
Closes gravitee-io/issues#1594
- Loading branch information
Showing
21 changed files
with
688 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
.../main/java/io/gravitee/definition/jackson/datatype/api/deser/VirtualHostDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.definition.jackson.datatype.api.deser; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; | ||
import io.gravitee.definition.model.VirtualHost; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author David BRASSELY (david.brassely at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public class VirtualHostDeserializer extends StdScalarDeserializer<VirtualHost> { | ||
|
||
public VirtualHostDeserializer(Class<VirtualHost> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public VirtualHost deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
|
||
VirtualHost vhost = new VirtualHost(); | ||
|
||
JsonNode hostNode = node.get("host"); | ||
if (hostNode != null) { | ||
vhost.setHost(hostNode.asText()); | ||
} | ||
|
||
JsonNode pathNode = node.get("path"); | ||
if (pathNode != null) { | ||
vhost.setPath(formatContextPath(pathNode.asText())); | ||
} else { | ||
vhost.setPath("/"); | ||
} | ||
|
||
vhost.setOverrideEntrypoint(node.path("override_entrypoint").asBoolean(false)); | ||
|
||
return vhost; | ||
} | ||
|
||
private String formatContextPath(String contextPath) { | ||
String [] parts = contextPath.split("/"); | ||
StringBuilder finalPath = new StringBuilder("/"); | ||
|
||
for(String part : parts) { | ||
if (! part.isEmpty()) { | ||
finalPath.append(part).append('/'); | ||
} | ||
} | ||
|
||
return finalPath.deleteCharAt(finalPath.length() - 1).toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../src/main/java/io/gravitee/definition/jackson/datatype/api/ser/VirtualHostSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.definition.jackson.datatype.api.ser; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; | ||
import io.gravitee.definition.model.VirtualHost; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author David BRASSELY (david.brassely at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public class VirtualHostSerializer extends StdScalarSerializer<VirtualHost> { | ||
|
||
public VirtualHostSerializer(Class<VirtualHost> t) { | ||
super(t); | ||
} | ||
|
||
@Override | ||
public void serialize(VirtualHost vhost, JsonGenerator jgen, SerializerProvider provider) throws IOException { | ||
jgen.writeStartObject(); | ||
|
||
if (vhost.getHost() != null && ! vhost.getHost().isEmpty()) { | ||
jgen.writeStringField("host", vhost.getHost()); | ||
} | ||
|
||
if (vhost.getPath() != null && ! vhost.getPath().isEmpty()) { | ||
jgen.writeStringField("path", vhost.getPath()); | ||
} | ||
|
||
if (vhost.isOverrideEntrypoint()) { | ||
jgen.writeBooleanField("override_entrypoint", vhost.isOverrideEntrypoint()); | ||
} | ||
|
||
jgen.writeEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.