From 5631fa61e09222abd4431fd97094e2af21d5d479 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 9 Dec 2019 10:51:30 -0600 Subject: [PATCH] SBR-1755 Don't share JacbContext - causes bundles issues when 2 bundles have the same packages --- META-INF/MANIFEST.MF | 8 +- build.xml | 4 +- .../core/aws/impl/AWSEndpointImpl.java | 156 +++++++++----- .../adapters/core/aws/TestAWSEndpoint.java | 198 +++++++++--------- 4 files changed, 205 insertions(+), 161 deletions(-) diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index d203b1a..06369e0 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -19,7 +19,7 @@ Import-Package: com.servicemesh.agility.api;version="3.1.0", javax.xml.namespace, org.apache.commons.codec.binary, org.apache.log4j;version="[1.2.17,2.0.0)" -Export-Package: com.servicemesh.agility.adapters.core.aws;version="1.2.1", - com.servicemesh.agility.adapters.core.aws.action;version="1.2.1", - com.servicemesh.agility.adapters.core.aws.security.group.resources;version="1.2.1", - com.servicemesh.agility.adapters.core.aws.util;version="1.2.1" +Export-Package: com.servicemesh.agility.adapters.core.aws;version="1.3.0", + com.servicemesh.agility.adapters.core.aws.action;version="1.3.0", + com.servicemesh.agility.adapters.core.aws.security.group.resources;version="1.3.0", + com.servicemesh.agility.adapters.core.aws.util;version="1.3.0" diff --git a/build.xml b/build.xml index 8c9bd4b..896e3b0 100644 --- a/build.xml +++ b/build.xml @@ -19,8 +19,8 @@ - - + + diff --git a/src/com/servicemesh/agility/adapters/core/aws/impl/AWSEndpointImpl.java b/src/com/servicemesh/agility/adapters/core/aws/impl/AWSEndpointImpl.java index de83504..7579b06 100644 --- a/src/com/servicemesh/agility/adapters/core/aws/impl/AWSEndpointImpl.java +++ b/src/com/servicemesh/agility/adapters/core/aws/impl/AWSEndpointImpl.java @@ -51,6 +51,9 @@ private static class Holder private static JAXBContext getContext(String contextPath, ClassLoader loader) { JAXBContext context; + /* Original code - this would have 2 different bundles sharing the same + * JAXBContext but on different classloaders... + * synchronized (Holder.lock) { context = Holder.contextMap.get(contextPath); if (context == null) { @@ -58,15 +61,25 @@ private static JAXBContext getContext(String contextPath, ClassLoader loader) Holder.contextMap.put(contextPath, context); } } + */ + // Always create a new context for each new endpoint: + synchronized (Holder.lock) + { + context = Holder.createContext(contextPath, loader); + Holder.contextMap.put(contextPath, context); + } + return context; } private static JAXBContext createContext(String contextPath, ClassLoader loader) { - try { + try + { return JAXBContext.newInstance(contextPath, loader); } - catch (Exception ex) { + catch (Exception ex) + { AWSEndpointImpl._logger.error("createContext: " + contextPath + ", exception=" + ex); return null; } @@ -75,7 +88,8 @@ private static JAXBContext createContext(String contextPath, ClassLoader loader) private static JAXBContext lookupContext(String contextPath) { JAXBContext context = null; - synchronized (Holder.lock) { + synchronized (Holder.lock) + { context = Holder.contextMap.get(contextPath); } return context; @@ -83,7 +97,8 @@ private static JAXBContext lookupContext(String contextPath) private static void unregisterContext(String contextPath) { - synchronized (Holder.lock) { + synchronized (Holder.lock) + { Holder.contextMap.remove(contextPath); } } @@ -116,8 +131,7 @@ public static void unregisterContext(String contextPath) * Creates an AWS endpoint. * * @param address - * The address of the AWS access point. See AWSEndpointFactory - * getEndpoint() methods. + * The address of the AWS access point. See AWSEndpointFactory getEndpoint() methods. * @param regionName * The AWS region name, e.g. "us-east-1". May be null, in which case it must be part of the address. * @param version @@ -140,23 +154,29 @@ public AWSEndpointImpl(String address, String regionName, String version, Cl String serviceName = null; int i1 = hostName.indexOf('.'); - if (i1 > 0) { + if (i1 > 0) + { serviceName = hostName.substring(0, i1); i1++; - if (! AWSUtil.isValued(regionName)) { + if (!AWSUtil.isValued(regionName)) + { int i2 = hostName.indexOf('.', i1); - if (i2 > i1) { + if (i2 > i1) + { regionName = hostName.substring(i1, i2); } } } - if (! AWSUtil.isValued(serviceName)) { + if (!AWSUtil.isValued(serviceName)) + { throw new AWSAdapterException(Resources.getString("missingService", address)); } - if (! AWSUtil.isValued(regionName)) { + if (!AWSUtil.isValued(regionName)) + { throw new AWSAdapterException(Resources.getString("missingRegion", address)); } - if (! AWSUtil.isValued(version)) { + if (!AWSUtil.isValued(version)) + { throw new AWSAdapterException(Resources.getString("emptyVersion")); } @@ -182,24 +202,29 @@ public AWSEndpointImpl(String address, String regionName, String version, Cl * One of the JAXB classes for the AWS API. Used to initialize the default context for the endpoint. */ public AWSEndpointImpl(String uriScheme, String hostName, String serviceName, String regionName, String version, - int urlExpireSecs, Class contextClass) + int urlExpireSecs, Class contextClass) { - if (! AWSUtil.isValued(uriScheme)) { + if (!AWSUtil.isValued(uriScheme)) + { throw new AWSAdapterException(Resources.getString("emptyUriScheme")); } - if (! AWSUtil.isValued(hostName)) { + if (!AWSUtil.isValued(hostName)) + { throw new AWSAdapterException(Resources.getString("emptyHostname")); } String address = uriScheme + "://" + hostName; hostName = parseHostName(address); - if (! AWSUtil.isValued(serviceName)) { + if (!AWSUtil.isValued(serviceName)) + { throw new AWSAdapterException(Resources.getString("emptyService")); } - if (! AWSUtil.isValued(regionName)) { + if (!AWSUtil.isValued(regionName)) + { throw new AWSAdapterException(Resources.getString("emptyRegion")); } - if (! AWSUtil.isValued(version)) { + if (!AWSUtil.isValued(version)) + { throw new AWSAdapterException(Resources.getString("emptyVersion")); } @@ -212,22 +237,24 @@ public AWSEndpointImpl(String uriScheme, String hostName, String serviceName private String parseHostName(String address) { String hostName = null; - try { + try + { URL url = new URL(address); hostName = url.getHost(); } - catch (Exception ex) { + catch (Exception ex) + { throw new AWSAdapterException(Resources.getString("invalidAddress", address)); } - if (! AWSUtil.isValued(hostName)) { + if (!AWSUtil.isValued(hostName)) + { throw new AWSAdapterException(Resources.getString("missingHostname", address)); } return hostName; } - private void init(String address, String hostName, String serviceName, - String regionName, String version, - int urlExpireSecs, Class contextClass) + private void init(String address, String hostName, String serviceName, String regionName, String version, + int urlExpireSecs, Class contextClass) { _address = address; _hostName = hostName; @@ -235,21 +262,23 @@ private void init(String address, String hostName, String serviceName, _regionName = regionName; _version = version; _urlExpireSecs = urlExpireSecs; - try { + try + { _contextLoader = contextClass.getClassLoader(); String contextPath = contextClass.getPackage().getName(); _context = Holder.getContext(contextPath, _contextLoader); - if (_context == null) { + if (_context == null) + { throw new AWSAdapterException(Resources.getString("missingContext", contextClass.getName())); } - if (_logger.isTraceEnabled()) { - _logger.trace("init: address=" + _address + ", hostName=" + - _hostName + ", serviceName=" + _serviceName + - ", regionName=" + _regionName + ", version=" + - _version + ", urlExpireSecs=" + _urlExpireSecs); + if (_logger.isTraceEnabled()) + { + _logger.trace("init: address=" + _address + ", hostName=" + _hostName + ", serviceName=" + _serviceName + + ", regionName=" + _regionName + ", version=" + _version + ", urlExpireSecs=" + _urlExpireSecs); } } - catch (Exception e) { + catch (Exception e) + { throw new AWSAdapterException(Resources.getString("contextException", e)); } } @@ -318,7 +347,8 @@ public T decode(IHttpResponse response, Class responseClass) public T decode(IHttpResponse response, String responseClassPath, Class responseClass) { JAXBContext responseContext = getContext(responseClassPath); - if (responseContext == null) { + if (responseContext == null) + { throw new AWSAdapterException(Resources.getString("missingDecodeContext", responseClassPath)); } return doDecode(response, responseClass, responseContext); @@ -326,33 +356,40 @@ public T decode(IHttpResponse response, String responseClassPath, Class r private T doDecode(IHttpResponse response, Class responseClass, JAXBContext responseContext) { - if (responseClass.isInstance(response)) { + if (responseClass.isInstance(response)) + { // We already have the return object return responseClass.cast(response); } StringBuilder err = new StringBuilder(); int statusCode = response.getStatusCode(); - if ((statusCode < 200) || (statusCode >= 300)) { + if ((statusCode < 200) || (statusCode >= 300)) + { err.append(Resources.getString("badStatus", statusCode)); handleError(err.toString(), response); } Object object = null; - try { + try + { object = HttpUtil.decodeObject(response.getContent(), null, responseContext); - if (_logger.isTraceEnabled()) { + if (_logger.isTraceEnabled()) + { _logger.trace("decoded: " + response.getContent()); } } - catch (HttpClientException ex) { + catch (HttpClientException ex) + { err.append(Resources.getString("decodeException", ex.getMessage())); handleError(err.toString(), response); } T responseObject = null; - if (responseClass.isInstance(object)) { + if (responseClass.isInstance(object)) + { responseObject = responseClass.cast(object); } - else { + else + { handleError(Resources.getString("unexpectedResponse"), response); } return responseObject; @@ -380,12 +417,15 @@ private List getAWSErrors(String content) int e1 = 0, e2 = 0; boolean done = (content == null); - while (!done) { + while (!done) + { done = true; e1 = content.indexOf("", e1); - if (e1 >= 0) { + if (e1 >= 0) + { e2 = content.indexOf("", e1 + "".length()); - if (e2 > e1) { + if (e2 > e1) + { done = false; errors.add(parseError(content, e1, e2)); e1 = e2; @@ -400,22 +440,26 @@ private AWSError parseError(String content, int e1, int e2) AWSError error = new AWSError(); String value = getValue(content, "", "", e1, e2); - if (value != null) { + if (value != null) + { error.setCode(value); } value = getValue(content, "", "", e1, e2); - if (value != null) { + if (value != null) + { error.setMessage(value); } value = getValue(content, "", "", e1, e2); - if (value != null) { + if (value != null) + { error.setResource(value); } value = getValue(content, "", "", e1, e2); - if (value != null) { + if (value != null) + { error.setRequestId(value); } return error; @@ -425,10 +469,12 @@ private String getValue(String content, String startTag, String endTag, int minI { String value = null; int iStart = content.indexOf(startTag, minIdx); - if ((iStart >= 0) && (iStart < maxIdx)) { + if ((iStart >= 0) && (iStart < maxIdx)) + { int iContent = iStart + startTag.length(); int iEnd = content.indexOf(endTag, iContent); - if ((iEnd > 0) && (iEnd < maxIdx)) { + if ((iEnd > 0) && (iEnd < maxIdx)) + { value = content.substring(iContent, iEnd); } } @@ -445,7 +491,8 @@ public String encode(Object obj) public String encode(String objClassPath, Object obj) { JAXBContext objContext = getContext(objClassPath); - if (objContext == null) { + if (objContext == null) + { throw new AWSAdapterException(Resources.getString("missingEncodeContext", objClassPath)); } return doEncode(obj, objContext); @@ -454,16 +501,19 @@ public String encode(String objClassPath, Object obj) private String doEncode(Object obj, JAXBContext objContext) { ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { + try + { Marshaller marshaller = objContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, os); - if (_logger.isTraceEnabled()) { + if (_logger.isTraceEnabled()) + { _logger.trace("encoded: " + os.toString()); } return os.toString(); } - catch (Exception ex) { + catch (Exception ex) + { AWSEndpointImpl._logger.error("encode Exception: " + ex); throw new AWSAdapterException(Resources.getString("encodeException", ex)); } diff --git a/test/unit/src/com/servicemesh/agility/adapters/core/aws/TestAWSEndpoint.java b/test/unit/src/com/servicemesh/agility/adapters/core/aws/TestAWSEndpoint.java index 3d35787..65eb26d 100644 --- a/test/unit/src/com/servicemesh/agility/adapters/core/aws/TestAWSEndpoint.java +++ b/test/unit/src/com/servicemesh/agility/adapters/core/aws/TestAWSEndpoint.java @@ -46,40 +46,37 @@ public void testContext() throws Exception String addressS3 = "https://s3.us-east-1.amazonaws.com"; AWSEndpoint epS3 = null; - try { - epf.getEndpoint(addressS3, "2006-03-01", - AWSAdapterException.class); + try + { + epf.getEndpoint(addressS3, "2006-03-01", AWSAdapterException.class); Assert.fail("Expected exception for endpoint with non-JAXB class"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } Assert.assertNull(epS3); - epS3 = epf.getEndpoint(addressS3, "2006-03-01", - LocationConstraint.class); + epS3 = epf.getEndpoint(addressS3, "2006-03-01", LocationConstraint.class); Assert.assertNotNull(epS3); String addressRDS = "https://rds.us-west-1.amazonaws.com"; - AWSEndpoint epRDS = epf.getEndpoint(addressRDS, "2010-07-28", - Parameter.class); + AWSEndpoint epRDS = epf.getEndpoint(addressRDS, "2010-07-28", Parameter.class); Assert.assertNotNull(epRDS); JAXBContext contextEP = epRDS.getContext(); Assert.assertNotNull(contextEP); - JAXBContext contextS3 = - epf.lookupContext(LocationConstraint.class.getPackage().getName()); + JAXBContext contextS3 = epf.lookupContext(LocationConstraint.class.getPackage().getName()); Assert.assertNotNull(contextS3); Assert.assertNotSame(contextEP, contextS3); - JAXBContext contextRDS = - epf.lookupContext(Parameter.class.getPackage().getName()); + JAXBContext contextRDS = epf.lookupContext(Parameter.class.getPackage().getName()); Assert.assertNotNull(contextRDS); Assert.assertSame(contextEP, contextRDS); String rmPath = ResponseMetadata.class.getPackage().getName(); contextEP = epRDS.getContext(rmPath); - Assert.assertSame(contextEP, contextRDS); + //Assert.assertSame(contextEP, contextRDS); NO LONGER TRUE JAXBContext noContext = epf.lookupContext("foo.bar"); Assert.assertNull(noContext); @@ -99,19 +96,23 @@ public void testContext() throws Exception Assert.assertEquals(encode1, encode2); TestHelpers.setLogLevel(AWSEndpointImpl.class.getName(), Level.TRACE); - try { + try + { epRDS.encode("foo.bar", rm); Assert.fail("Expected exception for encode with bad path"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } AWSAdapterException ex = new AWSAdapterException("hey"); - try { + try + { epRDS.encode(ex); Assert.fail("Expected exception for non-JAXB object"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } DefaultHttpResponse response = new DefaultHttpResponse(); @@ -121,32 +122,36 @@ public void testContext() throws Exception Assert.assertSame(response, iResponse); TestHelpers.setLogLevel(AWSEndpointImpl.class.getName(), Level.INFO); - ResponseMetadata rmdec = epRDS.decode(response, rmPath, - ResponseMetadata.class); + ResponseMetadata rmdec = epRDS.decode(response, rmPath, ResponseMetadata.class); Assert.assertNotNull(rmdec); Assert.assertEquals(rm.getRequestId(), rmdec.getRequestId()); TestHelpers.setLogLevel(AWSEndpointImpl.class.getName(), Level.TRACE); - try { + try + { epRDS.decode(response, Parameter.class); Assert.fail("Expected exception for decode invalid class"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } - try { - epRDS.decode(response, AWSAdapterException.class.getPackage().getName(), - AWSAdapterException.class); + try + { + epRDS.decode(response, AWSAdapterException.class.getPackage().getName(), AWSAdapterException.class); Assert.fail("Expected exception for decode invalid context"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } - try { + try + { epS3.decode(response, ResponseMetadata.class); Assert.fail("Expected exception for decode invalid class for context"); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { } //--------------------------------------------------------------------- @@ -195,8 +200,7 @@ public void testErrorResponses() throws Exception error.setCode("my code"); getErrors("Data 4", ep, status400, toContent(error), expected); - String garbledError = toContent(error).replace("", "") - .replaceFirst("", " "); + String garbledError = toContent(error).replace("", "").replaceFirst("", " "); error.setCode(null); getErrors("Garbled", ep, status400, garbledError, expected); error.setCode("my code"); @@ -216,37 +220,39 @@ public void testErrorResponses() throws Exception error3.setMessage("error message 3"); StringBuilder multi = new StringBuilder(""); - multi.append("\n").append(toContent(error2)).append("\n") - .append(toContent(error)).append("\n").append(toContent(error3)) - .append("\n\n"); + multi.append("\n").append(toContent(error2)).append("\n").append(toContent(error)).append("\n") + .append(toContent(error3)).append("\n\n"); getErrors("Multiple errors", ep, status400, multi.toString(), expected); } - private void getErrors(String scenario, AWSEndpoint ep, HttpStatus status, - String content, List expected) + private void getErrors(String scenario, AWSEndpoint ep, HttpStatus status, String content, List expected) { DefaultHttpResponse response = new DefaultHttpResponse(); response.setStatus(status); if (content != null) response.setContent(content.getBytes()); - try { + try + { ep.decode(response, Parameter.class); Assert.fail("Expected exception: " + scenario); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { Assert.assertTrue(scenario, expected == null); } - catch (AWSErrorException aee) { + catch (AWSErrorException aee) + { Assert.assertFalse(scenario, expected == null); List actual = aee.getErrors(); Assert.assertNotNull(scenario, actual); - if (expected.size() != actual.size()) { - Assert.fail(scenario + ", expSz=" + expected.size() + - ", actSz=" + actual.size()); + if (expected.size() != actual.size()) + { + Assert.fail(scenario + ", expSz=" + expected.size() + ", actSz=" + actual.size()); } - for (int i = 0 ; i < expected.size() ; i++) { + for (int i = 0; i < expected.size(); i++) + { AWSError expErr = expected.get(i); AWSError actErr = actual.get(i); Assert.assertEquals(scenario, expErr.toString(), actErr.toString()); @@ -257,16 +263,20 @@ private void getErrors(String scenario, AWSEndpoint ep, HttpStatus status, private String toContent(AWSError error) { StringBuilder sb = new StringBuilder(""); - if (error.getCode() != null) { + if (error.getCode() != null) + { sb.append("").append(error.getCode()).append(""); } - if (error.getMessage() != null) { + if (error.getMessage() != null) + { sb.append("").append(error.getMessage()).append(""); } - if (error.getResource() != null) { + if (error.getResource() != null) + { sb.append("").append(error.getResource()).append(""); } - if (error.getRequestId() != null) { + if (error.getRequestId() != null) + { sb.append("").append(error.getRequestId()).append(""); } sb.append(""); @@ -331,65 +341,53 @@ public void testAddress() throws Exception String serviceName = "rds"; regionName = "us-east-1"; int urlExpireSecs = AWSEndpoint.DEFAULT_URL_EXPIRE_SECS + 50; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, true); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, true); uriScheme = null; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); uriScheme = ""; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); uriScheme = "http"; hostName = null; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); hostName = ""; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); hostName = "rds.amazonws.com"; serviceName = null; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); serviceName = ""; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); serviceName = "rds"; regionName = null; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); regionName = ""; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); regionName = "us-west-1"; version = null; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); version = ""; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, false); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, false); version = "2008-10-01"; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, true); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, true); urlExpireSecs = -30; - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, true); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, true); urlExpireSecs = 0; TestHelpers.setLogLevel(AWSEndpointImpl.class.getName(), Level.INFO); - tryAddressUri(uriScheme, hostName, serviceName, regionName, version, - urlExpireSecs, true); + tryAddressUri(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, true); } private void tryAddress(String address, boolean isGood) throws Exception { - try { + try + { AWSEndpoint ep = AWSEndpointFactory.getInstance().getEndpoint(address, "2010-07-28", Parameter.class); - if (! isGood) + if (!isGood) Assert.fail("Failure expected: " + address); Assert.assertNotNull(ep); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { if (isGood) Assert.fail("Exception for " + address + ": " + aae); } @@ -397,46 +395,42 @@ private void tryAddress(String address, boolean isGood) throws Exception private void tryAddressRegion(String address, String regionName, String version, boolean isGood) throws Exception { - try { + try + { AWSEndpoint ep = AWSEndpointFactory.getInstance().getEndpoint(address, regionName, version, Parameter.class); - if (! isGood) - Assert.fail("Failure expected: address=" + address + - ", region=" + regionName + ", version=" + version); + if (!isGood) + Assert.fail("Failure expected: address=" + address + ", region=" + regionName + ", version=" + version); Assert.assertNotNull(ep); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { if (isGood) - Assert.fail("Exception for address=" + address + ", region=" + - regionName + ", version=" + version + ": " + aae); + Assert.fail("Exception for address=" + address + ", region=" + regionName + ", version=" + version + ": " + aae); } } - private void tryAddressUri(String uriScheme, String hostName, - String serviceName, String regionName, - String version, int urlExpireSecs, - boolean isGood) throws Exception + private void tryAddressUri(String uriScheme, String hostName, String serviceName, String regionName, String version, + int urlExpireSecs, boolean isGood) throws Exception { - try { - AWSEndpoint ep = AWSEndpointFactory.getInstance().getEndpoint(uriScheme, hostName, serviceName, regionName, version, urlExpireSecs, Parameter.class); - - if (! isGood) - Assert.fail("Failure expected: uriScheme=" + uriScheme + - ", hostName=" + hostName + ", serviceName=" + - serviceName + ", regionName=" + regionName + - ", version=" + version); + try + { + AWSEndpoint ep = AWSEndpointFactory.getInstance().getEndpoint(uriScheme, hostName, serviceName, regionName, version, + urlExpireSecs, Parameter.class); + + if (!isGood) + Assert.fail("Failure expected: uriScheme=" + uriScheme + ", hostName=" + hostName + ", serviceName=" + serviceName + + ", regionName=" + regionName + ", version=" + version); Assert.assertNotNull(ep); - int expSecs = (urlExpireSecs > 0) ? - urlExpireSecs : AWSEndpoint.DEFAULT_URL_EXPIRE_SECS; + int expSecs = (urlExpireSecs > 0) ? urlExpireSecs : AWSEndpoint.DEFAULT_URL_EXPIRE_SECS; Assert.assertEquals(expSecs, ep.getUrlExpireSecs()); } - catch (AWSAdapterException aae) { + catch (AWSAdapterException aae) + { if (isGood) - Assert.fail("Exception for uriScheme=" + uriScheme + - ", hostName=" + hostName + ", serviceName=" + - serviceName + ", regionName=" + regionName + - ", version=" + version + ": " + aae); + Assert.fail("Exception for uriScheme=" + uriScheme + ", hostName=" + hostName + ", serviceName=" + serviceName + + ", regionName=" + regionName + ", version=" + version + ": " + aae); } } }