Skip to content

Commit 9ab7f75

Browse files
committed
feat(api) polish access point uri
1 parent 0faeb0c commit 9ab7f75

3 files changed

Lines changed: 22 additions & 25 deletions

File tree

openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import static io.openmessaging.api.OMSResponseStatus.generateException;
2323

2424
/**
25-
* Represents a <a href="https://github.com/openmessaging/specification/blob/master/oms_access_point_schema.md">AccessPoint String</a>.
26-
* The Connection String describes the details to connect a specific OMS service provider.
25+
* Represents a <a href="https://github.com/openmessaging/specification/blob/master/oms_access_point_schema.md">AccessPoint
26+
* String</a>. The Connection String describes the details to connect a specific OMS service provider.
2727
*/
2828
public class AccessPointURI {
2929
private static final String PREFIX = "oms:";
@@ -41,9 +41,10 @@ public class AccessPointURI {
4141
* <p>
4242
*
4343
* More details please refer to:
44-
* <a href="https://github.com/openmessaging/specification/blob/master/oms_access_point_schema.md">Access Point Schema</a>
44+
* <a href="https://github.com/openmessaging/specification/blob/master/oms_access_point_schema.md">Access Point
45+
* Schema</a>
4546
*/
46-
private static final String PATTERN = "^oms:.+://.+/.+$";
47+
private static final String PATTERN = "^oms:.+://.+(/.+)?";
4748

4849
AccessPointURI(String accessPointString) {
4950
validateAccessPointString(accessPointString);
@@ -58,9 +59,15 @@ public class AccessPointURI {
5859
unprocessedString = unprocessedString.substring(driverType.length() + 3);
5960

6061
idx = unprocessedString.lastIndexOf('/');
62+
String userAndHostInformation;
6163

62-
this.region = unprocessedString.substring(idx + 1);
63-
String userAndHostInformation = unprocessedString.substring(0, idx);
64+
if (idx != -1) {
65+
this.region = unprocessedString.substring(idx + 1);
66+
userAndHostInformation = unprocessedString.substring(0, idx);
67+
} else {
68+
this.region = null;
69+
userAndHostInformation = unprocessedString;
70+
}
6471

6572
idx = userAndHostInformation.indexOf('@');
6673

openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package io.openmessaging.api.internal;
1919

2020
import io.openmessaging.api.MessagingAccessPoint;
21-
import io.openmessaging.api.OMS;
2221
import io.openmessaging.api.OMSBuiltinKeys;
2322
import io.openmessaging.api.OMSResponseStatus;
2423
import io.openmessaging.api.exception.OMSRuntimeException;
@@ -49,14 +48,17 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, Propertie
4948

5049
attributes.put(OMSBuiltinKeys.ACCESS_POINTS, accessPointURI.getHosts());
5150
attributes.put(OMSBuiltinKeys.DRIVER_IMPL, driverImpl);
52-
attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion());
53-
attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId());
51+
if (accessPointURI.getRegion() != null) {
52+
attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion());
53+
}
54+
if (accessPointURI.getAccountId() != null) {
55+
attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId());
56+
}
5457

5558
try {
5659
Class<?> driverImplClass = Class.forName(driverImpl);
5760
Constructor constructor = driverImplClass.getConstructor(Properties.class);
5861
MessagingAccessPoint vendorImpl = (MessagingAccessPoint) constructor.newInstance(attributes);
59-
checkSpecVersion(OMS.specVersion, vendorImpl.version());
6062
return vendorImpl;
6163
} catch (Throwable e) {
6264
throw generateException(OMSResponseStatus.STATUS_10000, url);
@@ -70,16 +72,4 @@ private static String parseDriverImpl(String driverType, Properties attributes)
7072
return "io.openmessaging." + driverType + ".MessagingAccessPointImpl";
7173
}
7274

73-
private static void checkSpecVersion(final String specVersion, final String implVersion) {
74-
String majorVerOfImpl;
75-
String majorVerOfSpec = specVersion.substring(0, specVersion.indexOf('.', specVersion.indexOf('.') + 1));
76-
try {
77-
majorVerOfImpl = implVersion.substring(0, implVersion.indexOf('.', implVersion.indexOf('.') + 1));
78-
} catch (Throwable e) {
79-
throw generateException(OMSResponseStatus.STATUS_10002, implVersion);
80-
}
81-
if (!majorVerOfSpec.equals(majorVerOfImpl)) {
82-
throw generateException(OMSResponseStatus.STATUS_10003, implVersion, specVersion);
83-
}
84-
}
8575
}

openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public void testParse_DriverIsIllegal() {
3737
}
3838

3939

40-
String missRegion = "oms:rocketmq://alice@rocketmq.apache.org/";
40+
String missHost = "oms:rocketmq://";
4141
try {
42-
new AccessPointURI(missRegion);
42+
new AccessPointURI(missHost);
4343
failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
4444
} catch (Exception e) {
45-
assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missRegion));
45+
assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missHost));
4646
}
4747
}
4848

0 commit comments

Comments
 (0)