[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1123: [SCB-1188] View convert download schemas

2019-03-11 Thread GitBox
liubao68 commented on a change in pull request #1123: [SCB-1188] View convert 
download schemas
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1123#discussion_r264115426
 
 

 ##
 File path: 
inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
 ##
 @@ -0,0 +1,201 @@
+/*
+ * 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.servicecomb.inspector.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.servlet.http.Part;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
+
+import 
org.apache.servicecomb.common.rest.resource.ClassPathStaticResourceHandler;
+import org.apache.servicecomb.common.rest.resource.StaticResourceHandler;
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+import org.apache.servicecomb.inspector.internal.swagger.AppendStyleProcessor;
+import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.swagger.SwaggerUtils;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.asciidoctor.Asciidoctor;
+import org.asciidoctor.Asciidoctor.Factory;
+import org.asciidoctor.Attributes;
+import org.asciidoctor.AttributesBuilder;
+import org.asciidoctor.OptionsBuilder;
+import org.asciidoctor.SafeMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Ordering;
+
+import io.github.swagger2markup.Swagger2MarkupConfig;
+import io.github.swagger2markup.Swagger2MarkupConverter;
+import io.github.swagger2markup.Swagger2MarkupConverter.Builder;
+import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.models.parameters.Parameter;
+
+@Path("/inspector")
+public class InspectorImpl {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(InspectorImpl.class);
+
+  private InspectorConfig inspectorConfig;
+
+  private Map schemas;
+
+  private volatile Asciidoctor asciidoctor;
+
+  private StaticResourceHandler resourceHandler = new 
ClassPathStaticResourceHandler();
+
+  public InspectorImpl(InspectorConfig inspectorConfig, Map 
schemas) {
+this.inspectorConfig = inspectorConfig;
+this.schemas = schemas;
+  }
+
+  @Path("/schemas")
+  @GET
+  public Collection getSchemaIds() {
+return schemas.keySet();
+  }
+
+  @Path("/download/schemas")
+  @GET
+  @ApiResponse(code = 200, message = "", response = File.class)
+  public Response downloadSchemas(@QueryParam("format") SchemaFormat format) 
throws IOException {
+if (format == null) {
+  format = SchemaFormat.SWAGGER;
+}
+
+// normally, schema will not be too big, just save them in memory 
temporarily
+ByteArrayOutputStream os = new ByteArrayOutputStream();
+ZipOutputStream zos = new ZipOutputStream(os);
 
 Review comment:
   It's better to use try with resouce clause to make resource properly closed. 
And not throw IOException in REST definition.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1123: [SCB-1188] View convert download schemas

2019-03-11 Thread GitBox
liubao68 commented on a change in pull request #1123: [SCB-1188] View convert 
download schemas
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1123#discussion_r264110340
 
 

 ##
 File path: 
common/common-rest/src/main/java/org/apache/servicecomb/common/rest/resource/ClassPathStaticResourceHandler.java
 ##
 @@ -0,0 +1,35 @@
+/*
+ * 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.servicecomb.common.rest.resource;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.http.Part;
+
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+
+public class ClassPathStaticResourceHandler extends StaticResourceHandler {
+  protected Part findResource(String path) throws IOException {
+URL url = this.getClass().getClassLoader().getResource(path);
 
 Review comment:
   ok, is it better to rename webroot to static? So that we can migrate from 
spring boot. Or we can add a configuration for webroot.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1123: [SCB-1188] View convert download schemas

2019-03-11 Thread GitBox
liubao68 commented on a change in pull request #1123: [SCB-1188] View convert 
download schemas
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1123#discussion_r264106882
 
 

 ##
 File path: 
common/common-rest/src/main/java/org/apache/servicecomb/common/rest/resource/ClassPathStaticResourceHandler.java
 ##
 @@ -0,0 +1,35 @@
+/*
+ * 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.servicecomb.common.rest.resource;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.http.Part;
+
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+
+public class ClassPathStaticResourceHandler extends StaticResourceHandler {
+  protected Part findResource(String path) throws IOException {
+URL url = this.getClass().getClassLoader().getResource(path);
 
 Review comment:
   Is it better to constraint the static contents are located in $jar/static ? 
(just like spring boot did) Or we need to check the file suffix to make sure 
not download unexpected files. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1123: [SCB-1188] View convert download schemas

2019-03-11 Thread GitBox
liubao68 commented on a change in pull request #1123: [SCB-1188] View convert 
download schemas
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1123#discussion_r264106882
 
 

 ##
 File path: 
common/common-rest/src/main/java/org/apache/servicecomb/common/rest/resource/ClassPathStaticResourceHandler.java
 ##
 @@ -0,0 +1,35 @@
+/*
+ * 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.servicecomb.common.rest.resource;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.http.Part;
+
+import org.apache.servicecomb.foundation.common.part.InputStreamPart;
+
+public class ClassPathStaticResourceHandler extends StaticResourceHandler {
+  protected Part findResource(String path) throws IOException {
+URL url = this.getClass().getClassLoader().getResource(path);
 
 Review comment:
   Is it better to constraint the static contents are located in $jar/webapp ? 
Or we need to check the file suffix to make sure not download unexpected files. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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