forked from syndesisio/syndesis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added servlet registration for api-provider and webhook.
- Loading branch information
Showing
6 changed files
with
210 additions
and
28 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
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
...n/java/io/syndesis/server/controller/integration/camelk/customizer/WebhookCustomizer.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) 2016 Red Hat, Inc. | ||
* | ||
* 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.syndesis.server.controller.integration.camelk.customizer; | ||
|
||
import io.syndesis.common.model.integration.IntegrationDeployment; | ||
import io.syndesis.integration.api.IntegrationResourceManager; | ||
import io.syndesis.server.controller.integration.camelk.CamelKSupport; | ||
import io.syndesis.server.controller.integration.camelk.crd.ConfigurationSpec; | ||
import io.syndesis.server.controller.integration.camelk.crd.Integration; | ||
import io.syndesis.server.controller.integration.camelk.crd.IntegrationSpec; | ||
import io.syndesis.server.openshift.Exposure; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.EnumSet; | ||
|
||
/** | ||
* Configure OpenApi | ||
*/ | ||
@Component | ||
public class WebhookCustomizer implements CamelKIntegrationCustomizer { | ||
private final IntegrationResourceManager resourceManager; | ||
|
||
public WebhookCustomizer(IntegrationResourceManager resourceManager) { | ||
this.resourceManager = resourceManager; | ||
} | ||
|
||
@Override | ||
public Integration customize(IntegrationDeployment deployment, Integration integration, EnumSet<Exposure> exposure) { | ||
IntegrationSpec.Builder spec = new IntegrationSpec.Builder(); | ||
if (integration.getSpec() != null) { | ||
spec = spec.from(integration.getSpec()); | ||
} | ||
|
||
if (!CamelKSupport.isWebhookPresent(deployment.getSpec())) { | ||
return integration; | ||
} | ||
|
||
try { | ||
spec.addConfiguration( | ||
new ConfigurationSpec.Builder() | ||
.type("property") | ||
.value("customizer.servletregistration.enabled=true") | ||
.build() | ||
); | ||
spec.addConfiguration( | ||
new ConfigurationSpec.Builder() | ||
.type("property") | ||
.value("customizer.servletregistration.path=/webhook/*") | ||
.build() | ||
); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
|
||
integration.setSpec(spec.build()); | ||
|
||
return integration; | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...va/io/syndesis/server/controller/integration/camelk/customizer/WebhookCustomizerTest.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,94 @@ | ||
/* | ||
* Copyright (C) 2016 Red Hat, Inc. | ||
* | ||
* 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.syndesis.server.controller.integration.camelk.customizer; | ||
|
||
import io.syndesis.common.model.action.ConnectorAction; | ||
import io.syndesis.common.model.action.ConnectorDescriptor; | ||
import io.syndesis.common.model.connection.Connection; | ||
import io.syndesis.common.model.connection.Connector; | ||
import io.syndesis.common.model.integration.Integration; | ||
import io.syndesis.common.model.integration.IntegrationDeployment; | ||
import io.syndesis.common.model.integration.Step; | ||
import io.syndesis.common.model.integration.StepKind; | ||
import io.syndesis.common.util.Json; | ||
import io.syndesis.server.controller.integration.camelk.TestResourceManager; | ||
import io.syndesis.server.openshift.Exposure; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
import java.util.EnumSet; | ||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class WebhookCustomizerTest { | ||
@Test | ||
public void testOpenApiCustomizer() throws Exception { | ||
// URL location = getClass().getResource("/petstore.json"); | ||
// byte[] content = Files.readAllBytes(Paths.get(location.toURI())); | ||
|
||
TestResourceManager manager = new TestResourceManager(); | ||
// manager.put("petstore", new OpenApi.Builder().document(content).id("petstore").build()); | ||
|
||
Connector connector; | ||
ConnectorAction webhookIncomingAction; | ||
|
||
try (InputStream is = WebhookCustomizerTest.class.getResourceAsStream("/META-INF/syndesis/connector/webhook.json")) { | ||
connector = Json.readFromStream(is, Connector.class); | ||
webhookIncomingAction = connector.getActions(ConnectorAction.class).stream() | ||
.filter(a -> a.getId().get().equals("io.syndesis:webhook-incoming")) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException()); | ||
} | ||
|
||
webhookIncomingAction = webhookIncomingAction.builder().descriptor(new ConnectorDescriptor.Builder().connectorId("webhook").build()).build(); | ||
|
||
Integration integration = manager.newIntegration( | ||
new Step.Builder() | ||
.stepKind(StepKind.endpoint) | ||
.putConfiguredProperty("contextPath", "token") | ||
.action(webhookIncomingAction) | ||
.connection(new Connection.Builder() | ||
.connector(connector) | ||
.build()) | ||
.build() | ||
); | ||
|
||
IntegrationDeployment deployment = new IntegrationDeployment.Builder() | ||
.userId("user") | ||
.id("idId") | ||
.spec(integration) | ||
.build(); | ||
|
||
CamelKIntegrationCustomizer customizer = new WebhookCustomizer(manager); | ||
|
||
io.syndesis.server.controller.integration.camelk.crd.Integration i = customizer.customize( | ||
deployment, | ||
new io.syndesis.server.controller.integration.camelk.crd.Integration(), | ||
EnumSet.of(Exposure.SERVICE) | ||
); | ||
|
||
assertThat(i.getSpec().getConfiguration()).hasSize(2); | ||
assertThat(i.getSpec().getConfiguration()).anyMatch( | ||
c -> Objects.equals("customizer.servletregistration.enabled=true", c.getValue()) | ||
&& Objects.equals("property", c.getType()) | ||
); | ||
assertThat(i.getSpec().getConfiguration()).anyMatch( | ||
c -> Objects.equals("customizer.servletregistration.path=/webhook/*", c.getValue()) | ||
&& Objects.equals("property", c.getType()) | ||
); | ||
} | ||
} |