Skip to content

Commit

Permalink
GEODE-2014: Upgrade Swagger libraries
Browse files Browse the repository at this point in the history
* this closes apache#265
  • Loading branch information
Kevin Duling authored and jinmeiliao committed Oct 24, 2016
1 parent 24a7204 commit 892d6d3
Show file tree
Hide file tree
Showing 40 changed files with 264 additions and 11,194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

package org.apache.geode.rest.internal.web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
Expand All @@ -46,6 +39,13 @@
import org.json.JSONTokener;
import org.junit.Assert;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;

public class GeodeRestClient {

public final static String PROTOCOL = "http";
Expand Down Expand Up @@ -86,10 +86,12 @@ public HttpResponse doGet(String uri, String username, String password)
return doRequest(getRequest, username, password);
}

public HttpResponse doGet(String uri) throws MalformedURLException {
return doGet(uri, null, null);
public HttpResponse doGetRequest(String url) throws MalformedURLException {
HttpGet getRequest = new HttpGet(url);
return doRequest(getRequest, null, null);
}


public HttpResponse doDelete(String uri, String username, String password)
throws MalformedURLException {
HttpDelete httpDelete = new HttpDelete(CONTEXT + uri);
Expand Down Expand Up @@ -123,7 +125,7 @@ public static JSONTokener getResponseBody(HttpResponse response) throws IOExcept
return new JSONTokener(str.toString());
}

private HttpResponse doRequest(HttpRequestBase request, String username, String password)
public HttpResponse doRequest(HttpRequestBase request, String username, String password)
throws MalformedURLException {
HttpHost targetHost = new HttpHost(HOSTNAME, restPort, PROTOCOL);
CloseableHttpClient httpclient = HttpClients.custom().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
*/
package org.apache.geode.rest.internal.web;

import static org.apache.geode.distributed.ConfigurationProperties.*;
import static org.junit.Assert.*;

import java.util.Properties;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.security.templates.SampleSecurityManager;
import org.apache.geode.test.dunit.rules.ServerStarter;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.SecurityTest;
import org.apache.http.HttpResponse;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -28,12 +37,7 @@
import org.junit.experimental.categories.Category;
import org.springframework.http.MediaType;

import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.security.templates.SampleSecurityManager;
import org.apache.geode.test.dunit.rules.ServerStarter;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.SecurityTest;
import java.util.Properties;


@Category({IntegrationTest.class, SecurityTest.class})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.geode.rest.internal.web;


import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.i18n.LocalizedStrings;
import org.apache.geode.test.dunit.rules.ServerStarter;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.http.HttpResponse;
import org.json.JSONObject;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.Properties;

@Category(IntegrationTest.class)

public class SwaggerVerificationTest {

private static int restPort = AvailablePortHelper.getRandomAvailableTCPPort();
static Properties properties = new Properties() {
{
setProperty(START_DEV_REST_API, "true");
setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
setProperty(HTTP_SERVICE_PORT, restPort + "");
}
};

@ClassRule
public static ServerStarter serverStarter = new ServerStarter(properties);
private final GeodeRestClient restClient = new GeodeRestClient(restPort);

@BeforeClass
public static void before() throws Exception {
serverStarter.startServer();
}

@Test
public void isSwaggerRunning() throws Exception {
// Check the UI
HttpResponse response = restClient.doGetRequest("/geode/swagger-ui.html");
assertThat(GeodeRestClient.getCode(response), is(200));

// Check the JSON
response = restClient.doGetRequest("/geode/v2/api-docs");
assertThat(GeodeRestClient.getCode(response), is(200));
JSONObject json = new JSONObject(GeodeRestClient.getResponseBody(response));
assertThat(json.get("swagger"), is("2.0"));

JSONObject info = json.getJSONObject("info");
assertThat(info.getString("description"),
is(LocalizedStrings.SwaggerConfig_DESCRIPTOR.toLocalizedString()));
assertThat(info.getString("title"),
is(LocalizedStrings.SwaggerConfig_VENDOR_PRODUCT_LINE.toLocalizedString()));

JSONObject license = info.getJSONObject("license");
assertThat(license.getString("name"), is("Apache License, version 2.0"));
assertThat(license.getString("url"), is("http://www.apache.org/licenses/"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7579,12 +7579,12 @@ public class LocalizedStrings {
"Developer REST API and interface to Geode''s distributed, in-memory data grid and cache.");
public static final StringId SwaggerConfig_EULA_LINK =
new StringId(6619, "http://www.apache.org/licenses/");
public static final StringId SwaggerConfig_SUPPORT_LINK =
new StringId(6620, "user@geode.incubator.apache.org");
public static final StringId SwaggerConfig_DEVELOPER_EMAIL =
new StringId(6620, "dev@geode.incubator.apache.org");
public static final StringId SwaggerConfig_DOC_TITLE =
new StringId(6621, "Apache Geode Documentation");
public static final StringId SwaggerConfig_DOC_LINK =
new StringId(6622, "http://geode.incubator.apache.org/docs/");
public static final StringId SwaggerConfig_PRODUCT_LINK =
new StringId(6622, "http://geode.apache.org");

public static final StringId LuceneXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_ANALYZER =
new StringId(6623, "Class {0} is not an instance of Analyzer.");
Expand Down
31 changes: 8 additions & 23 deletions geode-web-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apply plugin: 'war'
dependencies {

compile 'commons-lang:commons-lang:' + project.'commons-lang.version'
compile ('commons-fileupload:commons-fileupload:' + project.'commons-fileupload.version') {
compile('commons-fileupload:commons-fileupload:' + project.'commons-fileupload.version') {
exclude module: 'commons-io'
}
compile 'com.fasterxml:classmate:' + project.'classmate.version'
Expand All @@ -29,27 +29,12 @@ dependencies {
compile 'com.fasterxml.jackson.core:jackson-databind:' + project.'jackson.version'
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:' + project.'jackson-module-scala_2.10.version'
compile 'com.google.guava:guava:' + project.'guava.version'
compile ('com.mangofactory:swagger-springmvc:' + project.'swagger-springmvc.version') {
exclude module: 'aopalliance'
exclude module: 'asm'
exclude module: 'cglib'
exclude module: 'commons-logging'
exclude module: 'jackson-jaxrs-json-provider'
exclude module: 'jackson-jaxrs-json-provider'
exclude module: 'jackson-module-jsonSchema'
exclude module: 'joda-convert'
exclude module: 'joda-time'
exclude module: 'scalap'
compile('io.springfox:springfox-swagger2:' + project.'springfox.version') {
exclude module: 'slf4j-api'
}
compile('io.springfox:springfox-swagger-ui:' + project.'springfox.version') {
exclude module: 'slf4j-api'
exclude module: 'spring-aop'
exclude module: 'spring-beans'
exclude module: 'spring-context'
exclude module: 'spring-core'
exclude module: 'spring-expression'
exclude module: 'spring-webmvc'
exclude module: 'spring-web'
}
compile 'com.wordnik:swagger-annotations:' + project.'swagger.version'
compile 'org.json4s:json4s-ast_2.10:' + project.'json4s.version'
compile 'org.scala-lang:scala-library:' + project.'scala.version'
compile 'org.scala-lang:scala-reflect:' + project.'scala.version'
Expand All @@ -58,18 +43,18 @@ dependencies {
compile 'org.springframework.security:spring-security-web:' + project.'spring-security.version'
compile 'org.springframework.security:spring-security-config:' + project.'spring-security.version'
compile 'org.springframework:spring-webmvc:' + project.'springframework.version'
compile ('org.springframework.hateoas:spring-hateoas:' + project.'spring-hateoas.version') {
compile('org.springframework.hateoas:spring-hateoas:' + project.'spring-hateoas.version') {
exclude module: 'aopalliance'
exclude module: 'commons-logging'
exclude module: 'objenesis'
exclude module: 'slf4j-api'
exclude module: 'spring-core'
}
compile ('org.springframework:spring-aspects:' + project.'springframework.version') {
compile('org.springframework:spring-aspects:' + project.'springframework.version') {
exclude module: 'aopalliance'
exclude module: 'aspectjweaver'
}
compile ('org.springframework:spring-oxm:' + project.'springframework.version') {
compile('org.springframework:spring-oxm:' + project.'springframework.version') {
exclude module: 'commons-logging'
exclude module: 'spring-core'
exclude module: 'spring-beans'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,10 @@

package org.apache.geode.rest.internal.web.controllers;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import javax.annotation.PostConstruct;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import org.apache.geode.SerializationException;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheLoaderException;
Expand Down Expand Up @@ -82,6 +49,37 @@
import org.apache.geode.rest.internal.web.util.JSONUtils;
import org.apache.geode.rest.internal.web.util.NumberUtils;
import org.apache.geode.rest.internal.web.util.ValidationUtils;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.PostConstruct;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

package org.apache.geode.rest.internal.web.controllers;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.geode.internal.logging.LogService;
import org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException;
import org.apache.geode.rest.internal.web.exception.GemfireRestException;
import org.apache.geode.rest.internal.web.exception.MalformedJsonException;
import org.apache.geode.rest.internal.web.exception.RegionNotFoundException;
import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
import org.apache.geode.security.NotAuthorizedException;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -27,13 +31,8 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import org.apache.geode.internal.logging.LogService;
import org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException;
import org.apache.geode.rest.internal.web.exception.GemfireRestException;
import org.apache.geode.rest.internal.web.exception.MalformedJsonException;
import org.apache.geode.rest.internal.web.exception.RegionNotFoundException;
import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
import org.apache.geode.security.NotAuthorizedException;
import java.io.PrintWriter;
import java.io.StringWriter;


/**
Expand Down
Loading

0 comments on commit 892d6d3

Please sign in to comment.