Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / resources / ServiceAccessResource.java
diff --git a/apiroute/apiroute-service/src/main/java/org/openo/msb/resources/ServiceAccessResource.java b/apiroute/apiroute-service/src/main/java/org/openo/msb/resources/ServiceAccessResource.java
new file mode 100644 (file)
index 0000000..6a2d741
--- /dev/null
@@ -0,0 +1,65 @@
+/**\r
+* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+\r
+package org.openo.msb.resources;\r
+\r
+import io.swagger.annotations.Api;\r
+import io.swagger.annotations.ApiOperation;\r
+import io.swagger.annotations.ApiParam;\r
+import io.swagger.annotations.ApiResponse;\r
+import io.swagger.annotations.ApiResponses;\r
+\r
+import java.util.List;\r
+\r
+import javax.ws.rs.DefaultValue;\r
+import javax.ws.rs.GET;\r
+import javax.ws.rs.HeaderParam;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
+import javax.ws.rs.Produces;\r
+import javax.ws.rs.QueryParam;\r
+import javax.ws.rs.core.MediaType;\r
+\r
+import org.openo.msb.api.ServiceAccessInfo;\r
+import org.openo.msb.wrapper.ServiceAccessWrapper;\r
+\r
+import com.codahale.metrics.annotation.Timed;\r
+\r
+\r
+@Path("/serviceaccess")\r
+@Api(tags = {"ServiceAccess"})\r
+@Produces(MediaType.APPLICATION_JSON)\r
+public class ServiceAccessResource {\r
+\r
+    @GET\r
+    @Path("/{serviceName}")\r
+    @ApiOperation(value = "get the msb access address of the service ", response = ServiceAccessInfo.class)\r
+    @ApiResponses(value = {@ApiResponse(code = 500, message = "get access address error ")})\r
+    @Produces(MediaType.APPLICATION_JSON)\r
+    @Timed\r
+    public List<ServiceAccessInfo> getApiRoute(\r
+            @ApiParam(value = "serviceName") @PathParam("serviceName") String serviceName,\r
+            @ApiParam(value = "service type", allowableValues = "api,iui,custom,p2p") @QueryParam("type") String serviceType,\r
+            @ApiParam(value = "version") @QueryParam("version") @DefaultValue("") String version,\r
+            @ApiParam(hidden = true) @HeaderParam("Host") String host) {\r
+        \r
+        host=host.split(":")[0];\r
+\r
+        return ServiceAccessWrapper.getInstance().getApiRouteAccessAddr(serviceType, serviceName,\r
+                version, host);\r
+\r
+    }\r
+}\r