You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/09/21 00:03:40 UTC
[04/31] usergrid git commit: Switch to Jersey 2,
fix all compilation errors. TODO: new MeteringFilter,
new JSON-HTMP swap logic and correct use of dependency management.
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
index 87b85ac..08de618 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
@@ -17,12 +17,13 @@
package org.apache.usergrid.rest.security.shiro.filters;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.message.types.ParameterStyle;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.subject.Subject;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
@@ -35,22 +36,16 @@ import org.apache.usergrid.security.tokens.TokenInfo;
import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
import org.apache.usergrid.security.tokens.exceptions.ExpiredTokenException;
import org.apache.usergrid.security.tokens.exceptions.InvalidTokenException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.apache.amber.oauth2.common.exception.OAuthSystemException;
-import org.apache.amber.oauth2.common.message.types.ParameterStyle;
-import org.apache.amber.oauth2.common.utils.OAuthUtils;
-import org.apache.amber.oauth2.rs.request.OAuthAccessResourceRequest;
-import org.apache.shiro.subject.Subject;
-
-import com.sun.jersey.api.container.MappableContainerException;
-import com.sun.jersey.spi.container.ContainerRequest;
-import org.apache.commons.lang.StringUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Context;
+import java.io.IOException;
-import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.BAD_ACCESS_TOKEN_ERROR;
-import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.EXPIRED_ACCESS_TOKEN_ERROR;
-import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.INVALID_AUTH_ERROR;
-import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.UNVERIFIED_OAUTH_ERROR;
+import static org.apache.usergrid.rest.exceptions.AuthErrorInfo.*;
import static org.apache.usergrid.rest.exceptions.SecurityException.mappableSecurityException;
@@ -72,47 +67,42 @@ public class OAuth2AccessTokenSecurityFilter extends SecurityFilter {
@Override
- public ContainerRequest filter( ContainerRequest request ) {
+ public void filter(ContainerRequestContext request) throws IOException {
try {
try {
- String accessToken = request.getQueryParameters().getFirst( "access_token" );
+ String accessToken = httpServletRequest.getParameter( "access_token" );
- if ( StringUtils.isEmpty(accessToken) ) {
+ if (StringUtils.isEmpty( accessToken )) {
// Make the OAuth Request out of this request
OAuthAccessResourceRequest oauthRequest =
- new OAuthAccessResourceRequest( httpServletRequest, ParameterStyle.HEADER );
+ new OAuthAccessResourceRequest( httpServletRequest, ParameterStyle.HEADER );
// Get the access token
accessToken = oauthRequest.getAccessToken();
}
- if ( StringUtils.isEmpty(accessToken) ) {
- return request;
+ if (StringUtils.isEmpty( accessToken )) {
+ return;
}
AuthPrincipalInfo principal = null;
try {
TokenInfo tokenInfo = tokens.getTokenInfo( accessToken );
principal = tokenInfo.getPrincipal();
- }
- catch ( BadTokenException e1 ) {
+ } catch (BadTokenException e1) {
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
- }
- catch ( ExpiredTokenException ete ) {
+ } catch (ExpiredTokenException ete) {
throw mappableSecurityException( EXPIRED_ACCESS_TOKEN_ERROR );
- }
- catch ( InvalidTokenException ite ) {
+ } catch (InvalidTokenException ite) {
throw mappableSecurityException( INVALID_AUTH_ERROR );
- }
- catch ( IndexOutOfBoundsException ioobe ) {
+ } catch (IndexOutOfBoundsException ioobe) {
// token is just some rubbish string
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
- }
- catch ( Exception e ) {
- if ( LOG.isDebugEnabled() ) {
+ } catch (Exception e) {
+ if (LOG.isDebugEnabled()) {
LOG.debug( "Unable to verify OAuth token: " + accessToken, e );
} else {
LOG.warn( "Unable to verify OAuth token" );
@@ -120,81 +110,70 @@ public class OAuth2AccessTokenSecurityFilter extends SecurityFilter {
throw mappableSecurityException( UNVERIFIED_OAUTH_ERROR );
}
- if ( principal == null ) {
- return request;
+ if (principal == null) {
+ return;
}
PrincipalCredentialsToken token = null;
- if ( AuthPrincipalType.ADMIN_USER.equals( principal.getType() ) ) {
+ if (AuthPrincipalType.ADMIN_USER.equals( principal.getType() )) {
UserInfo user = null;
try {
user = management.getAdminUserInfoFromAccessToken( accessToken );
- }
- catch ( ManagementException e ) {
- throw new MappableContainerException( e );
- }
- catch ( Exception e ) {
+ } catch (ManagementException e) {
+ throw mappableSecurityException( e, BAD_ACCESS_TOKEN_ERROR );
+ } catch (Exception e) {
LOG.error( "failed to get admin user info from access token", e );
}
- if ( user == null ) {
+ if (user == null) {
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
}
token = PrincipalCredentialsToken.getFromAdminUserInfoAndAccessToken(
- user, accessToken, emf.getManagementAppId() );
- }
- else if ( AuthPrincipalType.APPLICATION_USER.equals( principal.getType() ) ) {
+ user, accessToken, emf.getManagementAppId() );
+ } else if (AuthPrincipalType.APPLICATION_USER.equals( principal.getType() )) {
UserInfo user = null;
try {
user = management.getAppUserFromAccessToken( accessToken );
- }
- catch ( ManagementException e ) {
- throw new MappableContainerException( e );
- }
- catch ( Exception e ) {
+ } catch (ManagementException e) {
+ throw mappableSecurityException( e, BAD_ACCESS_TOKEN_ERROR );
+ } catch (Exception e) {
LOG.error( "failed to get app user from access token", e );
}
- if ( user == null ) {
+ if (user == null) {
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
}
token = PrincipalCredentialsToken.getFromAppUserInfoAndAccessToken( user, accessToken );
- }
- else if ( AuthPrincipalType.ORGANIZATION.equals( principal.getType() ) ) {
+ } else if (AuthPrincipalType.ORGANIZATION.equals( principal.getType() )) {
OrganizationInfo organization = null;
try {
organization = management.getOrganizationInfoFromAccessToken( accessToken );
- }
- catch ( ManagementException e ) {
- throw new MappableContainerException( e );
- }
- catch ( Exception e ) {
+ } catch (ManagementException e) {
+ throw mappableSecurityException( e, BAD_ACCESS_TOKEN_ERROR );
+ } catch (Exception e) {
LOG.error( "failed to get organization info from access token", e );
}
- if ( organization == null ) {
+ if (organization == null) {
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
}
token = PrincipalCredentialsToken
- .getFromOrganizationInfoAndAccessToken( organization, accessToken );
- }
- else if ( AuthPrincipalType.APPLICATION.equals( principal.getType() ) ) {
+ .getFromOrganizationInfoAndAccessToken( organization, accessToken );
+ } else if (AuthPrincipalType.APPLICATION.equals( principal.getType() )) {
ApplicationInfo application = null;
try {
application = management.getApplicationInfoFromAccessToken( accessToken );
- }
- catch ( ManagementException e ) {
- throw new MappableContainerException( e );
- }
- catch ( Exception e ) {
+ } catch (ManagementException e) {
+ throw mappableSecurityException( e, BAD_ACCESS_TOKEN_ERROR );
+ } catch (Exception e) {
LOG.error( "failed to get application info from access token", e );
}
- if ( application == null ) {
+ if (application == null) {
throw mappableSecurityException( BAD_ACCESS_TOKEN_ERROR );
}
@@ -203,22 +182,22 @@ public class OAuth2AccessTokenSecurityFilter extends SecurityFilter {
Subject subject = SubjectUtils.getSubject();
subject.login( token );
- }
- catch ( OAuthProblemException e ) {
+
+ } catch (OAuthProblemException e) {
// Check if the error code has been set
String errorCode = e.getError();
- if ( OAuthUtils.isEmpty( errorCode ) ) {
-
- return request;
+ if (OAuthUtils.isEmpty( errorCode )) {
+ return;
}
- throw new MappableContainerException( e );
+ throw mappableSecurityException( errorCode, e.getMessage(), null );
}
- }
- catch ( OAuthSystemException ose ) {
- throw new MappableContainerException( ose );
+
+ } catch (OAuthSystemException ose) {
+ throw mappableSecurityException( ose, null );
}
- return request;
}
+
}
+
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/SecurityFilter.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/SecurityFilter.java b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/SecurityFilter.java
index 53f9354..625d352 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/SecurityFilter.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/SecurityFilter.java
@@ -21,10 +21,14 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriInfo;
+import javax.xml.ws.spi.http.HttpContext;
+import org.glassfish.jersey.server.ContainerRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -35,9 +39,6 @@ import org.apache.usergrid.services.ServiceManagerFactory;
import org.apache.commons.lang.StringUtils;
-import com.sun.jersey.api.core.HttpContext;
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
import static org.apache.usergrid.utils.StringUtils.stringOrSubstringAfterFirst;
import static org.apache.usergrid.utils.StringUtils.stringOrSubstringBeforeFirst;
@@ -118,8 +119,8 @@ public abstract class SecurityFilter implements ContainerRequestFilter {
}
- public static Map<String, String> getAuthTypes( ContainerRequest request ) {
- String auth_header = request.getHeaderValue( HttpHeaders.AUTHORIZATION );
+ public static Map<String, String> getAuthTypes( ContainerRequestContext request ) {
+ String auth_header = request.getHeaderString( HttpHeaders.AUTHORIZATION );
if ( auth_header == null ) {
return null;
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CORSUtils.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CORSUtils.java b/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CORSUtils.java
index a082573..daaf5ab 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CORSUtils.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CORSUtils.java
@@ -17,13 +17,15 @@
package org.apache.usergrid.rest.utils;
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.ContainerResponse;
+
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerResponse;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
/* Note: At one point there was a special case in this code that would
@@ -96,27 +98,27 @@ public class CORSUtils {
}
- public static ContainerResponse allowAllOrigins( ContainerRequest request, ContainerResponse response ) {
+ public static ContainerResponseContext allowAllOrigins( ContainerRequestContext request, ContainerResponseContext response ) {
- if ( request.getRequestHeaders().containsKey( ACCESS_CONTROL_REQUEST_METHOD ) ) {
+ if ( request.getHeaders().containsKey( ACCESS_CONTROL_REQUEST_METHOD ) ) {
- for ( String value : request.getRequestHeaders().get( ACCESS_CONTROL_REQUEST_METHOD ) ) {
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_METHODS, value );
+ for ( String value : request.getHeaders().get( ACCESS_CONTROL_REQUEST_METHOD ) ) {
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_METHODS, value );
}
}
- if ( request.getRequestHeaders().containsKey( ACCESS_CONTROL_REQUEST_HEADERS ) ) {
- for ( String value : request.getRequestHeaders().get( ACCESS_CONTROL_REQUEST_HEADERS ) ) {
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_HEADERS, value );
+ if ( request.getHeaders().containsKey( ACCESS_CONTROL_REQUEST_HEADERS ) ) {
+ for ( String value : request.getHeaders().get( ACCESS_CONTROL_REQUEST_HEADERS ) ) {
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_HEADERS, value );
}
}
boolean origin_sent = false;
- if ( request.getRequestHeaders().containsKey( ORIGIN_HEADER ) ) {
- for ( String value : request.getRequestHeaders().get( ORIGIN_HEADER ) ) {
+ if ( request.getHeaders().containsKey( ORIGIN_HEADER ) ) {
+ for ( String value : request.getHeaders().get( ORIGIN_HEADER ) ) {
if ( value != null ) {
origin_sent = true;
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, value );
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, value );
}
}
}
@@ -124,15 +126,15 @@ public class CORSUtils {
if ( !origin_sent ) {
String origin = getOrigin( request );
if ( origin != null ) {
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_CREDENTIALS, "true" );
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, origin );
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_CREDENTIALS, "true" );
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, origin );
}
else {
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, "*" );
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_ORIGIN, "*" );
}
}
else {
- response.getHttpHeaders().add( ACCESS_CONTROL_ALLOW_CREDENTIALS, "true" );
+ response.getHeaders().add( ACCESS_CONTROL_ALLOW_CREDENTIALS, "true" );
}
return response;
@@ -166,9 +168,9 @@ public class CORSUtils {
}
- public static String getOrigin( ContainerRequest request ) {
- String origin = request.getRequestHeaders().getFirst( ORIGIN_HEADER );
- String referer = request.getRequestHeaders().getFirst( REFERER_HEADER );
+ public static String getOrigin( ContainerRequestContext request ) {
+ String origin = request.getHeaders().getFirst( ORIGIN_HEADER );
+ String referer = request.getHeaders().getFirst( REFERER_HEADER );
return getOrigin( origin, referer );
}
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
index fc20147..edda5e5 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/BasicIT.java
@@ -17,23 +17,15 @@
package org.apache.usergrid.rest;
-import java.io.IOException;
-
-import javax.ws.rs.core.MediaType;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.usergrid.persistence.index.utils.UUIDUtils;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
-import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-
-import org.junit.Ignore;
+import javax.ws.rs.client.ResponseProcessingException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -82,8 +74,9 @@ public class BasicIT extends AbstractRestIT {
try {
clientSetup.getRestClient().pathResource( getOrgAppPath( "users/JOE" ) ).get( ApiResponse.class );
fail("A get on a nonexistant object should fail");
- }catch ( UniformInterfaceException e ) {
- assertEquals( "Guests should not be able to get a 404", 404, e.getResponse().getStatus() );
+ } catch ( ResponseProcessingException e ) {
+ assertEquals( "Guests should not be able to get a 404", 404,
+ e.getResponse().getStatusInfo().getStatusCode());
}
}
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
index a84f91c..065cd10 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
@@ -20,25 +20,22 @@
package org.apache.usergrid.rest;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.QueryParameters;
import org.apache.usergrid.rest.test.resource.model.Token;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
/**
@@ -81,16 +78,20 @@ public class IndexResourceIT extends AbstractRestIT {
result = clientSetup.getRestClient()
.pathResource( "system/index/rebuild/"+clientSetup.getAppUuid()+"/storelatlons" )
.post( false, ApiResponse.class,null,queryParameters,true);
+ String status = result.getProperties().get("jobId").toString();
assertNotNull( result );
- WebResource res = clientSetup.getRestClient()
- .pathResource( "system/index/rebuild/"+result.getProperties().get("jobId").toString() ).getResource();
- String status = result.getProperties().get("jobId").toString();
- //added httpBasicauth filter to all setup calls because they all do verification this way.
- HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( clientSetup.getSuperuserName(),clientSetup.getSuperuserPassword() );
- res.addFilter( httpBasicAuthFilter );
- result = res.get(ApiResponse.class);
+ WebTarget res = clientSetup.getRestClient()
+ .pathResource( "system/index/rebuild/" + result.getProperties()
+ .get( "jobId" ).toString() )
+ .getTarget();
+
+ result = res.request()
+ .property( HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME, "superuser")
+ .property( HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD, "superpassword" )
+ .get(ApiResponse.class);
+
assertNotNull( result );
assertEquals(status,result.getProperties().get("jobId").toString());
@@ -113,14 +114,14 @@ public class IndexResourceIT extends AbstractRestIT {
org.apache.usergrid.rest.test.resource.model.ApiResponse node = null;
try {
- WebResource resource = this.clientSetup.getRestClient().pathResource("/system/index/" + appId).getResource();
-
- //added httpBasicauth filter to all setup calls because they all do verification this way.
- HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( clientSetup.getSuperuserName(),clientSetup.getSuperuserPassword() );
- resource.addFilter( httpBasicAuthFilter );
+ WebTarget resource = this.clientSetup.getRestClient().pathResource("/system/index/" + appId).getTarget();
- node = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
+ node = resource.request()
+ .property( HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME, "superuser")
+ .property( HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD, "superpassword" )
+ .accept( MediaType.APPLICATION_JSON )
.get( org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+
} catch (Exception e) {
LOG.error("failed", e);
fail(e.toString());
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
index 97a02fd..109c76d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
@@ -17,7 +17,6 @@
package org.apache.usergrid.rest;
-import com.sun.jersey.api.client.UniformInterfaceException;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.utils.MapUtils;
@@ -25,6 +24,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.client.ResponseProcessingException;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -77,8 +77,8 @@ public class PartialUpdateTest extends AbstractRestIT {
try {
// PUT the updates to the user and ensure they were saved
userNode = this.app().collection("users").entity(userNode).put(updateProps);
- } catch (UniformInterfaceException uie) {
- fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
+ } catch (ResponseProcessingException uie) {
+ fail("Update failed due to: " + uie.getResponse().readEntity(String.class));
}
refreshIndex();
@@ -118,8 +118,8 @@ public class PartialUpdateTest extends AbstractRestIT {
try { // PUT /users/fred put /users/uuid
userNode = this.app().collection("users").entity(props.get("username").toString()).put(updateProps);
- } catch (UniformInterfaceException uie) {
- fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
+ } catch (ResponseProcessingException uie) {
+ fail("Update failed due to: " + uie.getResponse().readEntity(String.class));
}
refreshIndex();
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
index 7f09fa5..354589c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/SystemResourceIT.java
@@ -17,15 +17,10 @@
package org.apache.usergrid.rest;
-import org.junit.Test;
-
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.QueryParameters;
-import org.apache.usergrid.rest.test.resource.model.Token;
-
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import org.junit.Test;
import static org.junit.Assert.assertNotNull;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatRuntime.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatRuntime.java b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatRuntime.java
index 498068a..4c09565 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatRuntime.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatRuntime.java
@@ -31,8 +31,10 @@ import org.apache.usergrid.cassandra.AvailablePortFinder;
import org.apache.usergrid.setup.ConcurrentProcessSingleton;
import com.google.common.io.Files;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
/**
@@ -173,9 +175,9 @@ public class TomcatRuntime extends ExternalResource {
while ( count++ < 30 ) {
try {
Thread.sleep( 1000 );
- Client c = Client.create();
- WebResource wr = c.resource( url );
- wr.get( String.class );
+ Client c = ClientBuilder.newClient();
+ WebTarget wr = c.target( url );
+ wr.request().get( String.class );
log.info( "Tomcat is started." );
started = true;
break;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
index d2ad7ba..cfcc91d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
@@ -108,15 +108,15 @@ public class ApplicationCreateIT extends AbstractRestIT {
final String entityName = "entity" + i;
Entity entity = new Entity();
- entity.setProperties(new HashMap<String, Object>() {{
- put("name", entityName );
- }});
+ entity.setProperties( new HashMap<String, Object>() {{
+ put( "name", entityName );
+ }} );
ApiResponse createResponse = clientSetup.getRestClient()
- .org(orgName).app( appName ).collection("things").getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
- .post( ApiResponse.class, entity );
+ .org( orgName ).app( appName ).collection( "things" ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .request()
+ .post( javax.ws.rs.client.Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE ), ApiResponse.class);
entities.add( createResponse.getEntities().get(0) );
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
index cad0a37..b863a8e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
@@ -18,27 +18,24 @@
package org.apache.usergrid.rest.applications;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.UUID;
-
-import javax.ws.rs.core.MediaType;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import com.fasterxml.jackson.databind.JsonNode;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.endpoints.mgmt.ManagementResponse;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Application;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.Token;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.client.ResponseProcessingException;
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
import static org.junit.Assert.fail;
@@ -77,52 +74,54 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
clientSetup.getRestClient() .management().orgs()
- .org(orgName).apps().app(appToDeleteId.toString()).getResource()
+ .org(orgName).apps().app(appToDeleteId.toString()).getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken())
+ .request()
.delete();
fail("Delete must fail without app_delete_confirm parameter");
- } catch ( UniformInterfaceException expected ) {
+ } catch ( ResponseProcessingException expected ) {
Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ));
Assert.assertEquals("Cannot delete application without app_delete_confirm parameter", node.get("error_description").textValue());
}
clientSetup.getRestClient().management().orgs()
- .org(orgName).apps().app(appToDeleteId.toString() ).getResource()
+ .org(orgName).apps().app(appToDeleteId.toString() ).getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken() )
.queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+ .request()
.delete();
// test that we can no longer get the app
try {
clientSetup.getRestClient().management().orgs()
- .org(orgName).apps().app(appToDeleteName).getResource()
+ .org(orgName).apps().app(appToDeleteName).getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
+ .request()
.get(ApiResponse.class);
fail("Must not be able to get deleted app");
- } catch ( UniformInterfaceException expected ) {
+ } catch ( ResponseProcessingException expected ) {
Assert.assertEquals("Error must be 404", 404, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ));
Assert.assertEquals("entity_not_found", node.get("error").textValue());
}
try {
- clientSetup.getRestClient().org( orgName ).app( appToDeleteName ).getResource()
- .queryParam( "access_token", orgAdminToken.getAccessToken() ).type( MediaType.APPLICATION_JSON )
+ clientSetup.getRestClient().org( orgName ).app( appToDeleteName ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() ).request()
.get( ApiResponse.class );
fail( "Must not be able to get deleted app" );
}
- catch ( UniformInterfaceException expected ) {
+ catch ( ResponseProcessingException expected ) {
Assert.assertEquals( "Error must be 404", 404, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ) );
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ) );
Assert.assertEquals( "organization_application_not_found", node.get( "error" ).textValue() );
}
@@ -131,16 +130,16 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
clientSetup.getRestClient()
- .org(orgName).app(appToDeleteName).collection("things").getResource()
+ .org(orgName).app(appToDeleteName).collection("things").getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken() )
- .type(MediaType.APPLICATION_JSON )
- .get(ApiResponse.class);
+ .request()
+ .get( ApiResponse.class );
fail("Must not be able to get deleted app's collection");
- } catch ( UniformInterfaceException expected ) {
+ } catch ( ResponseProcessingException expected ) {
Assert.assertEquals("Error must be 400", 404, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ));
Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
}
@@ -149,17 +148,17 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
UUID entityId = entities.get(0).getUuid();
clientSetup.getRestClient()
- .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
+ .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getTarget()
.queryParam( "access_token", orgAdminToken.getAccessToken())
- .type( MediaType.APPLICATION_JSON)
- .get(ApiResponse.class);
+ .request()
+ .get( ApiResponse.class );
fail("Must not be able to get deleted app entity");
- } catch ( UniformInterfaceException expected ) {
+ } catch ( ResponseProcessingException expected ) {
// TODO: why not a 404?
Assert.assertEquals("Error must be 400", 404, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ));
Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
}
@@ -181,24 +180,26 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
clientSetup.getRestClient().management().orgs().org( orgName ).apps().app( appToDeleteId.toString() )
- .getResource().queryParam( "access_token", orgAdminToken.getAccessToken() )
- .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" ).delete();
+ .getTarget().queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
+ .request()
+ .delete();
fail("Can't delete a non existent app twice");
}
- catch ( UniformInterfaceException expected ) {
+ catch ( ResponseProcessingException expected ) {
Assert.assertEquals( "Error must be 404", 404, expected.getResponse().getStatus() );
- JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ) );
+ JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class ) );
Assert.assertEquals( "entity_not_found", node.get( "error" ).textValue() );
}
// test that we can create a new application with the same name
ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
- .management().orgs().org( orgName ).app().getResource()
+ .management().orgs().org( orgName ).app().getTarget()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
- .type( MediaType.APPLICATION_JSON )
- .post( ApiResponse.class, new Application( appToDeleteName ) );
+ .request()
+ .post( javax.ws.rs.client.Entity.json( new Application( appToDeleteName ) ), ApiResponse.class );
Assert.assertEquals("Must be able to create app with same name as deleted app",
(orgName + "/" + appToDeleteName).toLowerCase(),
@@ -230,12 +231,13 @@ public class ApplicationDeleteIT extends AbstractRestIT {
// delete the app
- logger.debug("\n\nDeleting app\n");
+ logger.debug( "\n\nDeleting app\n" );
clientSetup.getRestClient().management().orgs()
- .org(orgName).apps().app( appToDeleteName ).getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken() )
+ .org( orgName ).apps().app( appToDeleteName ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
.queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+ .request()
.delete();
refreshIndex();
@@ -246,9 +248,10 @@ public class ApplicationDeleteIT extends AbstractRestIT {
logger.debug("\n\nRestoring app\n");
clientSetup.getRestClient().management().orgs()
- .org(orgName).apps().app( appToDeleteId.toString() ).getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken() )
- .put();
+ .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .request()
+ .put( javax.ws.rs.client.Entity.json( null ));
refreshIndex();
@@ -275,18 +278,18 @@ public class ApplicationDeleteIT extends AbstractRestIT {
UUID entityId = entities.get(0).getUuid();
ApiResponse entityResponse = clientSetup.getRestClient()
- .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
- .get(ApiResponse.class);
+ .org( orgName ).app( appToDeleteName ).collection( "things" ).entity( entityId ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .request()
+ .get( ApiResponse.class );
Assert.assertEquals( entityId, entityResponse.getEntities().get(0).getUuid() );
// test that we can get deleted app's collection
ApiResponse collectionReponse = clientSetup.getRestClient()
- .org(orgName).app(appToDeleteName).collection("things").getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
+ .org( orgName ).app( appToDeleteName ).collection( "things" ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .request()
.get(ApiResponse.class);
Assert.assertEquals( entities.size(), collectionReponse.getEntityCount() );
}
@@ -311,9 +314,10 @@ public class ApplicationDeleteIT extends AbstractRestIT {
// delete the app
clientSetup.getRestClient().management().orgs()
- .org( orgName ).apps().app(appToDeleteId.toString() ).getResource()
+ .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
.queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+ .request()
.delete();
// create new app with same name
@@ -325,13 +329,14 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
clientSetup.getRestClient() .management().orgs()
- .org(orgName).apps().app(appToDeleteId.toString()).getResource()
+ .org(orgName).apps().app(appToDeleteId.toString()).getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken())
- .put();
+ .request()
+ .put( javax.ws.rs.client.Entity.json(null) );
fail("Must fail to restore app with same name as existing app");
- } catch ( UniformInterfaceException e ) {
+ } catch ( ResponseProcessingException e ) {
Assert.assertEquals(409, e.getResponse().getStatus());
}
}
@@ -356,9 +361,10 @@ public class ApplicationDeleteIT extends AbstractRestIT {
// delete the app
- clientSetup.getRestClient().management().orgs().org( orgName ).apps().app( appToDeleteId.toString() ).getResource()
+ clientSetup.getRestClient().management().orgs().org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
.queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
+ .request()
.delete();
// create new app with same name
@@ -369,14 +375,15 @@ public class ApplicationDeleteIT extends AbstractRestIT {
try {
- clientSetup.getRestClient().management().orgs().org( orgName ).apps().app( newAppId.toString() ).getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken())
+ clientSetup.getRestClient().management().orgs().org( orgName ).apps().app( newAppId.toString() ).getTarget()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
.queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
+ .request()
.delete();
fail("Must fail to delete app with same name as deleted app");
- } catch ( UniformInterfaceException e ) {
+ } catch ( ResponseProcessingException e ) {
Assert.assertEquals( 409, e.getResponse().getStatus() );
}
}
@@ -386,10 +393,10 @@ public class ApplicationDeleteIT extends AbstractRestIT {
String orgName, String appName, Token orgAdminToken, List<Entity> entities) {
ApiResponse appCreateResponse = clientSetup.getRestClient()
- .management().orgs().org( orgName ).app().getResource()
+ .management().orgs().org( orgName ).app().getTarget()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
- .type( MediaType.APPLICATION_JSON )
- .post( ApiResponse.class, new Application( appName ) );
+ .request()
+ .post( javax.ws.rs.client.Entity.json(new Application( appName )), ApiResponse.class );
UUID appId = appCreateResponse.getEntities().get(0).getUuid();
try { Thread.sleep(INDEXING_WAIT); } catch (InterruptedException ignored ) { }
@@ -398,15 +405,15 @@ public class ApplicationDeleteIT extends AbstractRestIT {
final String entityName = "entity" + i;
Entity entity = new Entity();
- entity.setProperties(new HashMap<String, Object>() {{
- put("name", entityName );
- }});
+ entity.setProperties( new HashMap<String, Object>() {{
+ put( "name", entityName );
+ }} );
ApiResponse createResponse = clientSetup.getRestClient()
- .org(orgName).app( appName ).collection("things").getResource()
+ .org(orgName).app( appName ).collection("things").getTarget()
.queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
- .post( ApiResponse.class, entity );
+ .request()
+ .post( javax.ws.rs.client.Entity.json(entity), ApiResponse.class );
entities.add( createResponse.getEntities().get(0) );
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
index ec858f7..f071b5e 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
@@ -17,10 +17,6 @@
package org.apache.usergrid.rest.applications;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.ClientResponse.Status;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.representation.Form;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.shiro.codec.Base64;
import org.apache.usergrid.cassandra.SpringResource;
@@ -30,12 +26,17 @@ import org.apache.usergrid.rest.test.resource.endpoints.mgmt.OrganizationResourc
import org.apache.usergrid.rest.test.resource.model.*;
import org.apache.usergrid.setup.ConcurrentProcessSingleton;
import org.apache.usergrid.utils.MapUtils;
+import org.glassfish.jersey.client.ClientProperties;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.ResponseProcessingException;
+import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -60,12 +61,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
Credentials orgCredentials = getOrgCredentials();
//retrieve the app using only the org credentials
- ApiResponse apiResponse = this.org().app(clientSetup.getAppName()).getResource(false)
+ ApiResponse apiResponse = this.org().app( clientSetup.getAppName() ).getTarget( false )
.queryParam("grant_type", "client_credentials")
.queryParam("client_id", orgCredentials.getClientId())
- .queryParam("client_secret", orgCredentials.getClientSecret())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ .queryParam( "client_secret", orgCredentials.getClientSecret() )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(ApiResponse.class);
//assert that a valid response is returned without error
assertNotNull(apiResponse);
@@ -82,12 +83,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
Credentials appCredentials = getAppCredentials();
//retrieve the app using only the org credentials
- ApiResponse apiResponse = this.app().getResource(false)
+ ApiResponse apiResponse = this.app().getTarget( false )
.queryParam("grant_type", "client_credentials")
.queryParam("client_id", appCredentials.getClientId())
.queryParam("client_secret", appCredentials.getClientSecret())
+ .request()
.accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
.get(ApiResponse.class);
//assert that a valid response is returned without error
assertNotNull(apiResponse);
@@ -104,13 +105,13 @@ public class ApplicationResourceIT extends AbstractRestIT {
Credentials appCredentials = getAppCredentials();
//retrieve the app using only the org credentials
- ApiResponse apiResponse = this.app().collection( "roles" ).getResource( false )
- .queryParam( "grant_type", "client_credentials" )
- .queryParam("client_id", appCredentials.getClientId())
- .queryParam("client_secret", appCredentials.getClientSecret())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .get(ApiResponse.class);
+ ApiResponse apiResponse = this.app().collection( "roles" ).getTarget( false )
+ .queryParam( "grant_type", "client_credentials" )
+ .queryParam("client_id", appCredentials.getClientId())
+ .queryParam("client_secret", appCredentials.getClientSecret())
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .get(ApiResponse.class);
//assert that a valid response is returned without error
assertNotNull(apiResponse);
assertNull(apiResponse.getError());
@@ -207,12 +208,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
Credentials orgCredentials = getOrgCredentials();
//retrieve the users collection without setting the "Accept" header
- WebResource.Builder builder = this.app().collection("users").getResource(false)
+ Invocation.Builder builder = this.app().collection( "users" ).getTarget( false )
//Add the org credentials to the query
- .queryParam("grant_type", "client_credentials")
- .queryParam("client_id", orgCredentials.getClientId())
- .queryParam("client_secret", orgCredentials.getClientSecret())
- .type(MediaType.APPLICATION_JSON_TYPE);
+ .queryParam( "grant_type", "client_credentials" )
+ .queryParam("client_id", orgCredentials.getClientId() )
+ .queryParam( "client_secret", orgCredentials.getClientSecret() )
+ .request();
ApiResponse apiResponse = builder.get(ApiResponse.class);
Collection users = new Collection(apiResponse);
@@ -239,15 +240,17 @@ public class ApplicationResourceIT extends AbstractRestIT {
String clientSecret = orgCredentials.getClientSecret();
//retrieve the users collection, setting the "Accept" header to text/html
- WebResource.Builder builder = this.app().collection("users").getResource(false)
+ Invocation.Builder builder = this.app().collection( "users" ).getTarget()
//Add the org credentials to the query
- .queryParam("grant_type", "client_credentials")
- .queryParam("client_id", clientId)
- .queryParam("client_secret", clientSecret)
+ .queryParam( "grant_type", "client_credentials" )
+ .queryParam( "client_id", clientId )
+ .queryParam( "client_secret", clientSecret )
+ .request();
+
+ ApiResponse apiResponse = builder
.accept(MediaType.TEXT_HTML)
- .type(MediaType.APPLICATION_JSON_TYPE);
+ .get(ApiResponse.class);
- ApiResponse apiResponse = builder.get(ApiResponse.class);
Collection users = new Collection(apiResponse);
//make sure that a valid response is returned without error
assertNotNull(users);
@@ -299,12 +302,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
//retrieve the credentials
Credentials orgCredentials = getOrgCredentials();
- ApiResponse apiResponse = this.app().getResource(false)
- .queryParam("grant_type", "client_credentials")
+ ApiResponse apiResponse = this.app().getTarget( false )
+ .queryParam( "grant_type", "client_credentials" )
.queryParam("client_id", orgCredentials.getClientId())
- .queryParam("client_secret", orgCredentials.getClientSecret())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ .queryParam( "client_secret", orgCredentials.getClientSecret() )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(ApiResponse.class);
// assert that the response returns the correct URI
@@ -317,12 +320,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
assertEquals(String.format("%s/%s", orgName, appName), application.get("name"));
//retrieve the application's roles collection
- apiResponse = this.app().collection("roles").getResource(false)
- .queryParam("grant_type", "client_credentials")
+ apiResponse = this.app().collection( "roles" ).getTarget( false )
+ .queryParam( "grant_type", "client_credentials" )
.queryParam("client_id", orgCredentials.getClientId())
- .queryParam("client_secret", orgCredentials.getClientSecret())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ .queryParam( "client_secret", orgCredentials.getClientSecret() )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(ApiResponse.class);
Collection roles = new Collection(apiResponse);
//assert that we have the correct number of default roles
@@ -372,11 +375,11 @@ public class ApplicationResourceIT extends AbstractRestIT {
String orgName = clientSetup.getOrganizationName().toLowerCase();
String appName = clientSetup.getAppName().toLowerCase();
- ApiResponse apiResponse = resource().path(String.format("/%s/%s", orgName, appName))
- .queryParam("access_token", this.getAdminToken().getAccessToken())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .delete(ApiResponse.class);
+ ApiResponse apiResponse = target().path( String.format( "/%s/%s", orgName, appName ) )
+ .queryParam( "access_token", this.getAdminToken().getAccessToken() )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
+ .delete( ApiResponse.class );
assertNotNull(apiResponse.getError());
}
@@ -406,14 +409,14 @@ public class ApplicationResourceIT extends AbstractRestIT {
try {
//POST the updated TTL, anticipating an exception
- resource().path(String.format("/%s/%s/token", orgName, appName))
+ target().path(String.format("/%s/%s/token", orgName, appName))
+ .request()
.accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .post(ApiResponse.class, entity);
+ .post( javax.ws.rs.client.Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE ), ApiResponse.class);
fail("This should cause an exception");
- } catch (UniformInterfaceException uie) {
+ } catch (ResponseProcessingException uie) {
assertEquals(
- String.valueOf(Status.BAD_REQUEST.getStatusCode()),
+ String.valueOf( Response.Status.BAD_REQUEST.getStatusCode()),
String.valueOf(uie.getResponse().getStatus()));
}
}
@@ -440,13 +443,13 @@ public class ApplicationResourceIT extends AbstractRestIT {
refreshIndex();
//Retrieve an authentication token for the user, setting the TTL
- Token apiResponse = resource().path(String.format("/%s/%s/token", orgName, appName))
+ Token apiResponse = target().path( String.format( "/%s/%s/token", orgName, appName ) )
.queryParam("grant_type", "password")
.queryParam("username", username)
.queryParam("password", "password")
- .queryParam("ttl", String.valueOf(ttl))
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ .queryParam( "ttl", String.valueOf( ttl ) )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(Token.class);
//Set a start time so we can calculate then the token should expire
@@ -477,8 +480,8 @@ public class ApplicationResourceIT extends AbstractRestIT {
this.app().collection("users").entity(entity).get(
new QueryParameters().addParam("access_token", token), false);
fail("The expired token should cause an exception");
- } catch (UniformInterfaceException uie) {
- assertEquals(Status.UNAUTHORIZED.getStatusCode(), uie.getResponse().getStatus());
+ } catch (ResponseProcessingException uie) {
+ assertEquals( Response.Status.UNAUTHORIZED.getStatusCode(), uie.getResponse().getStatus());
}
}
@@ -506,20 +509,20 @@ public class ApplicationResourceIT extends AbstractRestIT {
try {
//Retrieve a token for the new user, setting the TTL to an invalid value
- resource().path(String.format("/%s/%s/token", orgName, appName))
- .queryParam("grant_type", "password")
+ target().path( String.format( "/%s/%s/token", orgName, appName ) )
+ .queryParam( "grant_type", "password" )
.queryParam("username", username)
.queryParam("password", "password")
.queryParam("ttl", "derp")
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .get(ApiResponse.class);
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
+ .get( ApiResponse.class );
fail("The invalid TTL should cause an exception");
- } catch (UniformInterfaceException uie) {
+ } catch (ResponseProcessingException uie) {
//TODO should this be handled and returned as a Status.BAD_REQUEST?
//Status.INTERNAL_SERVER_ERROR is thrown because Jersey throws a NumberFormatException
- assertEquals(Status.INTERNAL_SERVER_ERROR, uie.getResponse().getClientResponseStatus());
+ assertEquals( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), uie.getResponse().getStatus());
}
}
@@ -543,12 +546,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
assertNotNull(entity);
refreshIndex();
//Retrieve an authentication token for the user
- Token tokenResponse = this.app().getResource(false).path("token")
- .queryParam("grant_type", "password")
- .queryParam("username", username)
+ Token tokenResponse = this.app().getTarget( false ).path( "token" )
+ .queryParam( "grant_type", "password" )
+ .queryParam( "username", username )
.queryParam("password", "password")
+ .request()
.accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_JSON_TYPE )
.get( Token.class );
String token = tokenResponse.getAccessToken();
@@ -559,19 +562,21 @@ public class ApplicationResourceIT extends AbstractRestIT {
assertEquals(604800, expires_in);
//Set the default TTL of the application to a date far in the future
- this.app().getResource(false)
- .queryParam("access_token", token)
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .put(Token.class, new MapUtils.HashMapBuilder<String, String>().map("accesstokenttl", "31536000000"));
+ final MapUtils.HashMapBuilder<String, String> map =
+ new MapUtils.HashMapBuilder<String, String>().map( "accesstokenttl", "31536000000" );
+ this.app().getTarget( false )
+ .queryParam( "access_token", token )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
+ .put( javax.ws.rs.client.Entity.entity( map, MediaType.APPLICATION_JSON_TYPE ), Token.class );
//Create a new token for the user
- tokenResponse = this.app().token().getResource(false)
+ tokenResponse = this.app().token().getTarget( false )
.queryParam("grant_type", "password")
.queryParam("username", username)
- .queryParam("password", "password")
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ .queryParam( "password", "password" )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(Token.class);
//assert that the new token has the new default TTL
@@ -587,15 +592,17 @@ public class ApplicationResourceIT extends AbstractRestIT {
public void authorizationCodeWithWrongCredentials() throws Exception {
//Create form input with bogus credentials
Form payload = new Form();
- payload.add("username", "wrong_user");
- payload.add("password", "wrong_password");
- payload.add("response_type", "code");
- payload.add("scope", "none");
- payload.add("redirect_uri", "http://www.my_test.com");
+ payload.param( "username", "wrong_user" );
+ payload.param( "password", "wrong_password" );
+ payload.param( "response_type", "code" );
+ payload.param( "scope", "none" );
+ payload.param( "redirect_uri", "http://www.my_test.com" );
//POST the form to the authorization endpoint
- String apiResponse = clientSetup.getRestClient().management().authorize().getResource()
- .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).accept(MediaType.TEXT_HTML).post(String.class, payload);
+ String apiResponse = clientSetup.getRestClient().management().authorize().getTarget()
+ .request()
+ .accept( MediaType.TEXT_HTML )
+ .post( javax.ws.rs.client.Entity.form( payload ), String.class );
//Assert that an appropriate error message is returned
assertTrue(apiResponse.contains("Username or password do not match"));
@@ -609,11 +616,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
//we have authorize response only with username/password - client_id/secret not considered
public void authorizeWithInvalidClientIdRaisesError() throws Exception {
//GET the application authorization endpoint using bogus client credentials
- String apiResponse = clientSetup.getRestClient().management().authorize().getResource(true)
- .queryParam("response_type", "code")
+ String apiResponse = clientSetup.getRestClient().management().authorize().getTarget( true )
+ .queryParam( "response_type", "code" )
.queryParam("client_id", "invalid_client_id")
.queryParam("redirect_uri", "http://www.my_test.com")
- .accept(MediaType.TEXT_HTML)
+ .request()
+ .accept( MediaType.TEXT_HTML )
.get(String.class);
//Assert that an appropriate error message is returned
//assertTrue(apiResponse.contains("Unable to authenticate (OAuth). Invalid client_id."));
@@ -630,22 +638,25 @@ public class ApplicationResourceIT extends AbstractRestIT {
//Create form input with valid credentials
Form payload = new Form();
- payload.add("response_type", "code");
- payload.add("grant_type", "client_credentials");
- payload.add("client_id", orgCredentials.getClientId());
- payload.add("client_secret", orgCredentials.getClientSecret());
- payload.add("scope", "none");
- payload.add("redirect_uri", "http://www.my_test.com");
+ payload.param( "response_type", "code" );
+ payload.param( "grant_type", "client_credentials" );
+ payload.param( "client_id", orgCredentials.getClientId() );
+ payload.param( "client_secret", orgCredentials.getClientSecret() );
+ payload.param( "scope", "none" );
+ payload.param( "redirect_uri", "http://www.my_test.com" );
//Set the client to not follow the initial redirect returned by the stack
- client().setFollowRedirects(false);
try {
//POST the form to the authorization endpoint
clientSetup.getRestClient().management().authorize()
- .getResource().accept(MediaType.TEXT_HTML).post(String.class, payload);
- } catch (UniformInterfaceException uie) {
- assertEquals(String.valueOf(Status.TEMPORARY_REDIRECT.getStatusCode()), uie.getResponse().getStatus());
+ .getTarget()
+ .property( ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE )
+ .request()
+ .accept( MediaType.TEXT_HTML )
+ .post( javax.ws.rs.client.Entity.form( payload ), String.class );
+ } catch (ResponseProcessingException uie) {
+ assertEquals(String.valueOf( Response.Status.TEMPORARY_REDIRECT.getStatusCode()), uie.getResponse().getStatus());
}
}
@@ -667,12 +678,12 @@ public class ApplicationResourceIT extends AbstractRestIT {
Map<String, String> map = new HashMap<>(1);
map.put("grant_type", "client_credentials");
//GET the token endpoint, adding the basic auth header
- Token apiResponse = clientSetup.getRestClient().management().token().getResource(false)
+ Token apiResponse = clientSetup.getRestClient().management().token().getTarget( false )
//add the auth header
- .header("Authorization", "Basic " + token)
+ .request()
+ .header( "Authorization", "Basic " + token )
.accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .post(Token.class, map);
+ .post( javax.ws.rs.client.Entity.entity(map, MediaType.APPLICATION_JSON_TYPE), Token.class );
//Assert that a valid token with a valid TTL is returned
assertNotNull("A valid response was returned.", apiResponse);
@@ -697,12 +708,13 @@ public class ApplicationResourceIT extends AbstractRestIT {
.post(Token.class,new Token("client_credentials", clientId, clientSecret));
//GET the token endpoint, adding authorization header
- Token apiResponse = this.app().token().getResource(false)
+ Token apiResponse = this.app().token().getTarget( false )
//add the auth header
- .header("Authorization", "Bearer " + token.getAccessToken())
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .post(Token.class, hashMap("grant_type", "client_credentials"));
+ .request()
+ .header( "Authorization", "Bearer " + token.getAccessToken() )
+ .accept( MediaType.APPLICATION_JSON )
+ .post(javax.ws.rs.client.Entity.entity(
+ hashMap( "grant_type", "client_credentials" ), MediaType.APPLICATION_JSON_TYPE ), Token.class );
//Assert that a valid token with a valid TTL is returned
assertNotNull("A valid response was returned.", apiResponse);
@@ -723,15 +735,14 @@ public class ApplicationResourceIT extends AbstractRestIT {
//Create form input
Form payload = new Form();
- payload.add("grant_type", "client_credentials");
- payload.add("client_id", clientId);
- payload.add("client_secret", clientSecret);
+ payload.param( "grant_type", "client_credentials" );
+ payload.param( "client_id", clientId );
+ payload.param("client_secret", clientSecret);
//POST the form to the application token endpoint
- Token apiResponse = this.app().token().getResource(false)
+ Token apiResponse = this.app().token().getTarget( false).request()
.accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
- .post(Token.class, payload);
+ .post( javax.ws.rs.client.Entity.form(payload), Token.class);
//Assert that a valid token with a valid TTL is returned
assertNotNull("It has access_token.", apiResponse.getAccessToken());
@@ -754,11 +765,11 @@ public class ApplicationResourceIT extends AbstractRestIT {
String token = Base64.encodeToString(clientCredentials.getBytes());
//POST the form to the application token endpoint along with the payload
- Token apiResponse = this.app().token().getResource(false)
- .header("Authorization", "Basic " + token)
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .post(Token.class, hashMap("grant_type", "client_credentials"));
+ Token apiResponse = this.app().token().getTarget( false ).request()
+ .header( "Authorization", "Basic " + token )
+ .accept( MediaType.APPLICATION_JSON )
+ .post(javax.ws.rs.client.Entity.entity(
+ hashMap("grant_type", "client_credentials"), MediaType.APPLICATION_JSON_TYPE), Token.class);
//Assert that a valid token with a valid TTL is returned
assertNotNull("It has access_token.", apiResponse.getAccessToken());
@@ -775,18 +786,18 @@ public class ApplicationResourceIT extends AbstractRestIT {
try {
//GET the APM endpoint
- String response = resource().path(String.format("/%s/%s/apm/apigeeMobileConfig", orgName, appName))
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON_TYPE)
+ String response = target().path( String.format( "/%s/%s/apm/apigeeMobileConfig", orgName, appName ) )
+ .request()
+ .accept( MediaType.APPLICATION_JSON )
.get(String.class);
//Parse the response
JsonNode node = mapper.readTree(response);
//if things are kosher then JSON should have value for instaOpsApplicationId
assertTrue("it's valid json for APM", node.has("instaOpsApplicationId"));
- } catch (UniformInterfaceException uie) {
+ } catch (ResponseProcessingException uie) {
//Validate that APM config exists
- assertNotEquals("APM Config API exists", Status.NOT_FOUND,
+ assertNotEquals("APM Config API exists", Response.Status.NOT_FOUND,
uie.getResponse().getStatus()); //i.e It should not be "Not Found"
}
}
@@ -813,7 +824,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
assertEquals(604800, ttl);
//retrieve the users collection for the application using the new token
- ApiResponse response = this.app().collection("users").getResource(true, token).get(ApiResponse.class);
+ ApiResponse response = this.app().collection("users").getTarget(true, token ).request().get(ApiResponse.class);
//assert that we did not receive an error
assertNull(response.getError());
}
@@ -840,7 +851,7 @@ public class ApplicationResourceIT extends AbstractRestIT {
assertEquals(604800, ttl);
//retrieve the users collection for the application using the new token
- ApiResponse response = this.app().collection("users").getResource(true, token).get(ApiResponse.class);
+ ApiResponse response = this.app().collection("users").getTarget( true, token ).request().get( ApiResponse.class);
//assert that we did not receive an error
assertNull(response.getError());
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
index 79a6957..92705b2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
@@ -17,19 +17,16 @@
package org.apache.usergrid.rest.applications.assets;
-import com.sun.jersey.multipart.FormDataMultiPart;
+import net.jcip.annotations.NotThreadSafe;
import org.apache.commons.io.IOUtils;
-
-import org.apache.usergrid.rest.applications.ServiceResource;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.services.assets.data.AssetUtils;
-
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,8 +38,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import net.jcip.annotations.NotThreadSafe;
-
import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_USERGRID_BINARY_UPLOADER;
import static org.apache.usergrid.utils.MapUtils.hashMap;
import static org.junit.Assert.*;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AwsAssetResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AwsAssetResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AwsAssetResourceIT.java
index 9cf719b..72d45de 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AwsAssetResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AwsAssetResourceIT.java
@@ -17,51 +17,30 @@
package org.apache.usergrid.rest.applications.assets;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.blobstore.BlobStoreContext;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-
-
+import com.amazonaws.SDKGlobalConfiguration;
+import net.jcip.annotations.NotThreadSafe;
import org.apache.commons.io.IOUtils;
-
-import org.apache.usergrid.cassandra.SpringResource;
-import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.rest.applications.assets.aws.NoAWSCredsRule;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.services.assets.data.AssetUtils;
-import org.apache.usergrid.services.assets.data.BinaryStore;
import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
-import org.apache.usergrid.setup.ConcurrentProcessSingleton;
-
-import com.amazonaws.SDKGlobalConfiguration;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.junit.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import net.jcip.annotations.NotThreadSafe;
+import javax.ws.rs.client.ResponseProcessingException;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.UUID;
import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_USERGRID_BINARY_UPLOADER;
import static org.apache.usergrid.utils.MapUtils.hashMap;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
@NotThreadSafe
@@ -116,7 +95,7 @@ public class AwsAssetResourceIT extends AbstractRestIT {
}catch ( AwsPropertiesNotFoundException e ){
fail("Shouldn't interrupt runtime if access key isnt found.");
}
- catch( UniformInterfaceException uie){
+ catch( ResponseProcessingException uie){
assertEquals(500,uie.getResponse().getStatus());
}
finally{
@@ -150,7 +129,7 @@ public class AwsAssetResourceIT extends AbstractRestIT {
}catch ( AwsPropertiesNotFoundException e ){
fail("Shouldn't interrupt runtime if access key isnt found.");
}
- catch( UniformInterfaceException uie){
+ catch( ResponseProcessingException uie){
assertEquals( 500, uie.getResponse().getStatus() );
}
finally{
@@ -192,7 +171,7 @@ public class AwsAssetResourceIT extends AbstractRestIT {
}catch ( AwsPropertiesNotFoundException e ){
fail("Shouldn't interrupt runtime if access key isnt found.");
}
- catch( UniformInterfaceException uie){
+ catch( ResponseProcessingException uie){
assertEquals( 500, uie.getResponse().getStatus() );
}
finally{
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
index 5f7779e..1dd00ff 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/aws/NoAWSCredsRule.java
@@ -20,9 +20,10 @@
package org.apache.usergrid.rest.applications.assets.aws;
-import java.util.Map;
-import java.util.Properties;
-
+import com.amazonaws.AmazonClientException;
+import com.amazonaws.SDKGlobalConfiguration;
+import org.apache.usergrid.rest.test.resource.AbstractRestIT;
+import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
import org.junit.Assume;
import org.junit.internal.runners.model.MultipleFailureException;
import org.junit.rules.TestRule;
@@ -30,12 +31,8 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.beans.factory.annotation.Autowired;
-import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
-import org.apache.usergrid.rest.test.resource.AbstractRestIT;
-
-import com.amazonaws.AmazonClientException;
-import com.amazonaws.SDKGlobalConfiguration;
-import com.sun.jersey.api.client.UniformInterfaceException;
+import java.util.Map;
+import java.util.Properties;
/**
http://git-wip-us.apache.org/repos/asf/usergrid/blob/0578d987/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 3dadc5b..b2bab35 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -17,24 +17,20 @@
package org.apache.usergrid.rest.applications.collection;
-import java.io.IOException;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.UniformInterfaceException;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
-import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Collection;
-
-import org.apache.usergrid.rest.test.resource.model.Credentials;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.QueryParameters;
import org.apache.usergrid.rest.test.resource.model.Token;
-
import org.junit.Ignore;
import org.junit.Test;
-import org.mortbay.jetty.security.Credential;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.client.ResponseProcessingException;
+import java.io.IOException;
+
import static org.junit.Assert.*;
@@ -66,9 +62,9 @@ public class CollectionsResourceIT extends AbstractRestIT {
try {
this.clientSetup.getRestClient().org(org).app(app).collection("cities").get();
fail("Call to bad path exists, but it should not");
- } catch (UniformInterfaceException e) {
+ } catch (ResponseProcessingException e) {
//verify the correct error was returned
- JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( e.getResponse().readEntity( String.class ));
assertEquals( "organization_application_not_found", node.get( "error" ).textValue() );
}
@@ -79,9 +75,9 @@ public class CollectionsResourceIT extends AbstractRestIT {
try {
this.clientSetup.getRestClient().org(org).app(app).collection("cities").post(payload);
fail("Call to bad path exists, but it should not");
- } catch (UniformInterfaceException e) {
+ } catch (ResponseProcessingException e) {
//verify the correct error was returned
- JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( e.getResponse().readEntity( String.class ));
assertEquals( "organization_application_not_found", node.get( "error" ).textValue() );
}
@@ -89,9 +85,9 @@ public class CollectionsResourceIT extends AbstractRestIT {
try {
this.clientSetup.getRestClient().org(org).app(app).collection("cities").entity(entity).put(payload);
fail("Call to bad path exists, but it should not");
- } catch (UniformInterfaceException e) {
+ } catch (ResponseProcessingException e) {
//verify the correct error was returned
- JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( e.getResponse().readEntity( String.class ));
assertEquals( "organization_application_not_found", node.get( "error" ).textValue() );
}
@@ -99,9 +95,9 @@ public class CollectionsResourceIT extends AbstractRestIT {
try {
this.clientSetup.getRestClient().org(org).app(app).collection("cities").entity(entity).delete();
fail("Call to bad path exists, but it should not");
- } catch (UniformInterfaceException e) {
+ } catch (ResponseProcessingException e) {
//verify the correct error was returned
- JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
+ JsonNode node = mapper.readTree( e.getResponse().readEntity( String.class ));
assertEquals( "organization_application_not_found", node.get( "error" ).textValue() );
}