merlimat commented on a change in pull request #1137: Schema registry
URL: https://github.com/apache/incubator-pulsar/pull/1137#discussion_r170830884
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/SchemasResource.java
 ##########
 @@ -0,0 +1,274 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.pulsar.broker.admin;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.Objects.isNull;
+import static org.apache.pulsar.common.util.Codec.decode;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.swagger.annotations.ApiOperation;
+import java.time.Clock;
+import java.util.Map;
+import java.util.Objects;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.broker.web.RestException;
+import org.apache.pulsar.common.naming.DestinationName;
+import org.apache.pulsar.common.schema.Schema;
+import org.apache.pulsar.common.schema.SchemaType;
+import org.apache.pulsar.common.schema.SchemaVersion;
+
+@Path("/schemas")
+public class SchemasResource extends AdminResource {
+
+    private final Clock clock;
+
+    @VisibleForTesting
+    SchemasResource(Clock clock) {
+        super();
+        this.clock = clock;
+    }
+
+    public SchemasResource() {
+        this(Clock.systemUTC());
+    }
+
+    @GET @Path("/{property}/{cluster}/{namespace}/{topic}/schema")
+    @Produces(MediaType.APPLICATION_JSON)
+    @ApiOperation(value = "Get topic schema")
+    public void getSchema(
+        @PathParam("property") String property,
+        @PathParam("cluster") String cluster,
+        @PathParam("namespace") String namespace,
+        @PathParam("topic") String topic,
+        @Suspended final AsyncResponse response
+    ) {
+        validateDestinationAndAdminOperation(property, cluster, namespace, 
topic);
+
+        String schemaId = buildSchemaId(property, cluster, namespace, topic);
+        pulsar().getSchemaRegistryService().getSchema(schemaId)
 
 Review comment:
   In general, it's preferrable to use the 
   
   ```java
   pulsar().getSchemaRegistryService().getSchema(schemaId).thenAccept(schema -> 
{
     // ....
   }).exceptionally(ex -> {
    /// ..
   return null;
   });
   ```
   
   because it would automatically catch unchecked exception in the success path 
and pass them to the failure path.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to