1818
1919package org .apache .skywalking .apm .plugin .jdbc .connectionurl .parser ;
2020
21- import java .util .ArrayList ;
22- import java .util .List ;
2321import org .apache .skywalking .apm .network .trace .component .ComponentsDefine ;
2422import org .apache .skywalking .apm .plugin .jdbc .trace .ConnectionInfo ;
2523import org .apache .skywalking .apm .util .StringUtil ;
2624
25+ import java .util .ArrayList ;
26+ import java .util .List ;
27+
2728/**
2829 * {@link OracleURLParser} presents that how to parse oracle connection url.
2930 * <p>
@@ -36,9 +37,16 @@ public class OracleURLParser extends AbstractURLParser {
3637 private static final int DEFAULT_PORT = 1521 ;
3738 public static final String SERVICE_NAME_FLAG = "@//" ;
3839 public static final String TNSNAME_URL_FLAG = "DESCRIPTION" ;
40+ public static final String SERVICE_NAME_FIELD = "SERVICE_NAME" ;
41+ public static final String HOST_FIELD = "HOST" ;
42+ public static final String PORT_FIELD = "PORT" ;
43+
44+ // only use to indexOf TNS url keyword
45+ private final String upperUrl ;
3946
4047 public OracleURLParser (String url ) {
4148 super (url );
49+ upperUrl = url == null ? null : url .toUpperCase ();
4250 }
4351
4452 @ Override
@@ -63,24 +71,24 @@ protected URLLocation fetchDatabaseHostsIndexRange() {
6371 @ Override
6472 protected URLLocation fetchDatabaseNameIndexRange () {
6573 int hostLabelStartIndex ;
66- int hostLabelEndIndex = url .length ();
74+ int hostLabelEndIndex = upperUrl .length ();
6775 if (isServiceNameURL ()) {
68- hostLabelStartIndex = url .lastIndexOf ("/" ) + 1 ;
76+ hostLabelStartIndex = upperUrl .lastIndexOf ("/" ) + 1 ;
6977 } else if (isTNSNameURL ()) {
70- hostLabelStartIndex = url .indexOf ("=" , url .indexOf ("SERVICE_NAME" )) + 1 ;
71- hostLabelEndIndex = url .indexOf (")" , hostLabelStartIndex );
78+ hostLabelStartIndex = upperUrl .indexOf ("=" , upperUrl .indexOf (SERVICE_NAME_FIELD )) + 1 ;
79+ hostLabelEndIndex = upperUrl .indexOf (")" , hostLabelStartIndex );
7280 } else {
73- hostLabelStartIndex = url .lastIndexOf (":" ) + 1 ;
81+ hostLabelStartIndex = upperUrl .lastIndexOf (":" ) + 1 ;
7482 }
7583 return new URLLocation (hostLabelStartIndex , hostLabelEndIndex );
7684 }
7785
7886 private boolean isServiceNameURL () {
79- return url .contains (SERVICE_NAME_FLAG );
87+ return upperUrl .contains (SERVICE_NAME_FLAG );
8088 }
8189
8290 private boolean isTNSNameURL () {
83- return url .contains (TNSNAME_URL_FLAG );
91+ return upperUrl .contains (TNSNAME_URL_FLAG );
8492 }
8593
8694 @ Override
@@ -110,23 +118,23 @@ private ConnectionInfo tnsNameURLParse() {
110118 }
111119
112120 private String parseDatabaseHostsFromURL () {
113- int beginIndex = url .indexOf ("DESCRIPTION" );
121+ int beginIndex = upperUrl .indexOf (TNSNAME_URL_FLAG );
114122 List <String > hosts = new ArrayList <String >();
115123 do {
116- int hostStartIndex = url .indexOf ("HOST" , beginIndex );
124+ int hostStartIndex = upperUrl .indexOf (HOST_FIELD , beginIndex );
117125 if (hostStartIndex == -1 ) {
118126 break ;
119127 }
120- int equalStartIndex = url .indexOf ("=" , hostStartIndex );
121- int hostEndIndex = url .indexOf (")" , hostStartIndex );
128+ int equalStartIndex = upperUrl .indexOf ("=" , hostStartIndex );
129+ int hostEndIndex = upperUrl .indexOf (")" , hostStartIndex );
122130 String host = url .substring (equalStartIndex + 1 , hostEndIndex );
123131
124132 int port = DEFAULT_PORT ;
125- int portStartIndex = url .indexOf ("PORT" , hostEndIndex );
126- int portEndIndex = url .length ();
133+ int portStartIndex = upperUrl .indexOf (PORT_FIELD , hostEndIndex );
134+ int portEndIndex = upperUrl .length ();
127135 if (portStartIndex != -1 ) {
128- int portEqualStartIndex = url .indexOf ("=" , portStartIndex );
129- portEndIndex = url .indexOf (")" , portEqualStartIndex );
136+ int portEqualStartIndex = upperUrl .indexOf ("=" , portStartIndex );
137+ portEndIndex = upperUrl .indexOf (")" , portEqualStartIndex );
130138 port = Integer .parseInt (url .substring (portEqualStartIndex + 1 , portEndIndex ).trim ());
131139 }
132140 hosts .add (host .trim () + ":" + port );
0 commit comments