[
https://issues.apache.org/jira/browse/KAFKA-7759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16726271#comment-16726271
]
ASF GitHub Bot commented on KAFKA-7759:
---------------------------------------
hachikuji closed pull request #6051: KAFKA-7759: Disable WADL output on OPTIONS
method in Connect REST.
URL: https://github.com/apache/kafka/pull/6051
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java
index 15386430bc5..c0d83f29103 100644
---
a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java
+++
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java
@@ -45,6 +45,7 @@
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.servlet.ServletContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -171,6 +172,7 @@ public void start(Herder herder) {
resourceConfig.register(new ConnectorPluginsResource(herder));
resourceConfig.register(ConnectExceptionMapper.class);
+ resourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true);
registerRestExtensions(herder, resourceConfig);
diff --git
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java
index c66ce36d8b0..a0fb685aff1 100644
---
a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java
+++
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java
@@ -25,7 +25,6 @@
import org.apache.kafka.connect.util.Callback;
import org.easymock.Capture;
import org.easymock.EasyMock;
-import org.easymock.IAnswer;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
@@ -41,11 +40,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;
@@ -158,6 +157,33 @@ public void testAdvertisedUri() {
Assert.assertEquals("http://my-hostname:8080/",
server.advertisedUrl().toString());
}
+ @Test
+ public void testOptionsDoesNotIncludeWadlOutput() {
+ Map<String, String> configMap = new HashMap<>(baseWorkerProps());
+ DistributedConfig workerConfig = new DistributedConfig(configMap);
+
+ EasyMock.expect(herder.plugins()).andStubReturn(plugins);
+ EasyMock.expect(plugins.newPlugins(Collections.emptyList(),
+ workerConfig,
+ ConnectRestExtension.class))
+ .andStubReturn(Collections.emptyList());
+ PowerMock.replayAll();
+
+ server = new RestServer(workerConfig);
+ server.start(herder);
+
+ Response response = request("/connectors")
+ .accept(MediaType.WILDCARD)
+ .options();
+ Assert.assertEquals(MediaType.TEXT_PLAIN_TYPE,
response.getMediaType());
+ Assert.assertArrayEquals(
+ response.getAllowedMethods().toArray(new String[0]),
+ response.readEntity(String.class).split(", ")
+ );
+
+ PowerMock.verifyAll();
+ }
+
public void checkCORSRequest(String corsDomain, String origin, String
expectedHeader, String method) {
// To be able to set the Origin, we need to toggle this flag
@@ -175,12 +201,9 @@ public void checkCORSRequest(String corsDomain, String
origin, String expectedHe
final Capture<Callback<Collection<String>>> connectorsCallback =
EasyMock.newCapture();
herder.connectors(EasyMock.capture(connectorsCallback));
- PowerMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- @Override
- public Object answer() throws Throwable {
- connectorsCallback.getValue().onCompletion(null,
Arrays.asList("a", "b"));
- return null;
- }
+ PowerMock.expectLastCall().andAnswer(() -> {
+ connectorsCallback.getValue().onCompletion(null,
Arrays.asList("a", "b"));
+ return null;
});
PowerMock.replayAll();
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Disable WADL output on OPTIONS method in Connect REST
> -----------------------------------------------------
>
> Key: KAFKA-7759
> URL: https://issues.apache.org/jira/browse/KAFKA-7759
> Project: Kafka
> Issue Type: Bug
> Affects Versions: 2.1.0
> Reporter: Oleksandr Diachenko
> Assignee: Oleksandr Diachenko
> Priority: Major
> Fix For: 2.2.0
>
>
> Currently, Connect REST API exposes WADL output on OPTIONS method:
> {code:java}
> curl -i -X OPTIONS http://localhost:8083/connectors
> HTTP/1.1 200 OK
> Date: Fri, 07 Dec 2018 22:51:53 GMT
> Content-Type: application/vnd.sun.wadl+xml
> Allow: HEAD,POST,GET,OPTIONS
> Last-Modified: Fri, 07 Dec 2018 14:51:53 PST
> Content-Length: 1331
> Server: Jetty(9.4.12.v20180830)
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <application xmlns="http://wadl.dev.java.net/2009/02">
> <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.27
> 2018-04-10 07:34:57"/>
> <grammars>
> <include href="http://localhost:8083/application.wadl/xsd0.xsd">
> <doc title="Generated" xml:lang="en"/>
> </include>
> </grammars>
> <resources base="http://localhost:8083/">
> <resource path="connectors">
> <method id="createConnector" name="POST">
> <request>
> <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="forward"
> style="query" type="xs:boolean"/>
> <representation mediaType="application/json"/>
> </request>
> <response>
> <representation mediaType="application/json"/>
> </response>
> </method>
> <method id="listConnectors" name="GET">
> <request>
> <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="forward"
> style="query" type="xs:boolean"/>
> </request>
> <response>
> <representation mediaType="application/json"/>
> </response>
> </method>
> </resource>
> </resources>
> </application>
> {code}
> It was never documented, so in order to remove unintended behavior, WADL
> output should be disabled.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)