Revision 2819
Added by Matt Jones over 18 years ago
LSIDAuthorityMain.java | ||
---|---|---|
40 | 40 |
import com.ibm.lsid.wsdl.LSIDMetadataPort; |
41 | 41 |
import com.ibm.lsid.wsdl.SOAPLocation; |
42 | 42 |
|
43 |
public class LSIDAuthorityMain extends SimpleAuthority { |
|
43 |
public class LSIDAuthorityMain extends SimpleAuthority |
|
44 |
{ |
|
44 | 45 |
|
45 |
private LSIDDataLookup lookup = null; |
|
46 |
private static Log logger = LogFactory.getLog( "edu.ucsb.nceas.metacat.lsid" ); |
|
47 |
|
|
48 |
public void initService(LSIDServiceConfig cf) throws LSIDServerException { |
|
46 |
private LSIDDataLookup lookup = null; |
|
47 |
private static Log logger = LogFactory |
|
48 |
.getLog("edu.ucsb.nceas.metacat.lsid"); |
|
49 |
|
|
50 |
public void initService(LSIDServiceConfig cf) throws LSIDServerException |
|
51 |
{ |
|
49 | 52 |
logger.info("Starting LSIDAuthorityMain."); |
50 |
lookup = new LSIDDataLookup();
|
|
51 |
}
|
|
53 |
lookup = new LSIDDataLookup();
|
|
54 |
}
|
|
52 | 55 |
|
53 |
public ExpiringResponse getKnownURIs() throws LSIDServerException { |
|
56 |
public ExpiringResponse getKnownURIs() throws LSIDServerException |
|
57 |
{ |
|
54 | 58 |
logger.debug("In LSIDAuthorityMain.getKnownURIs()"); |
55 |
return null;
|
|
56 |
}
|
|
59 |
return null;
|
|
60 |
}
|
|
57 | 61 |
|
58 |
public LSIDMetadataPort[] getMetadataLocations(LSID lsid, String url) { |
|
62 |
public LSIDMetadataPort[] getMetadataLocations(LSID lsid, String url) |
|
63 |
{ |
|
59 | 64 |
logger.debug("In LSIDAuthorityMain.getMetadataLocations()"); |
60 | 65 |
if (lookup == null) |
61 |
return null;
|
|
66 |
return null;
|
|
62 | 67 |
|
63 |
int lsType; |
|
64 |
try { |
|
65 |
lsType = lookup.lsidType(lsid); |
|
66 |
} |
|
67 |
catch (LSIDServerException ex) { |
|
68 |
ex.printStackTrace(); |
|
69 |
lsType = LSIDDataLookup.UNKNOWN; |
|
70 |
} |
|
71 |
if (lsType == LSIDDataLookup.UNKNOWN) |
|
72 |
return null; |
|
68 |
int lsType; |
|
69 |
try { |
|
70 |
lsType = lookup.lsidType(lsid); |
|
71 |
} catch (LSIDServerException ex) { |
|
72 |
ex.printStackTrace(); |
|
73 |
lsType = LSIDDataLookup.UNKNOWN; |
|
74 |
} |
|
75 |
if (lsType == LSIDDataLookup.UNKNOWN) |
|
76 |
return null; |
|
73 | 77 |
|
74 |
HostDescriptor hd = new HostDescriptor(url); |
|
75 |
return new LSIDMetadataPort[] { |
|
76 |
// thau added http metadata port here |
|
77 |
new HTTPLocation( |
|
78 |
hd.host, hd.port, |
|
79 |
hd.pathPrefix + "/authority/metadata" |
|
80 |
), |
|
81 |
new SOAPLocation( |
|
82 |
hd.baseURL + "metadata" |
|
83 |
) |
|
84 |
}; |
|
85 |
} |
|
78 |
HostDescriptor hd = new HostDescriptor(url); |
|
79 |
return new LSIDMetadataPort[] { |
|
80 |
// thau added http metadata port here |
|
81 |
new HTTPLocation(hd.host, hd.port, |
|
82 |
hd.pathPrefix + "/authority/metadata"), |
|
83 |
new SOAPLocation(hd.baseURL + "metadata")}; |
|
84 |
} |
|
86 | 85 |
|
87 |
public LSIDDataPort[] getDataLocations(LSID lsid, String url) { |
|
86 |
public LSIDDataPort[] getDataLocations(LSID lsid, String url) |
|
87 |
{ |
|
88 | 88 |
logger.debug("In LSIDAuthorityMain.getDataLocations()"); |
89 |
if (lookup == null)
|
|
90 |
return null;
|
|
89 |
if (lookup == null)
|
|
90 |
return null;
|
|
91 | 91 |
|
92 |
int lsType; |
|
93 |
try { |
|
94 |
lsType = lookup.lsidType(lsid); |
|
95 |
} |
|
96 |
catch (LSIDServerException ex) { |
|
97 |
ex.printStackTrace(); |
|
98 |
lsType = LSIDDataLookup.UNKNOWN; |
|
99 |
} |
|
100 |
if (lsType == LSIDDataLookup.UNKNOWN) |
|
101 |
return null; |
|
102 |
if (lsType == LSIDDataLookup.ABSTRACT) |
|
103 |
return new LSIDDataPort[0]; |
|
104 |
|
|
105 |
HostDescriptor hd = new HostDescriptor(url); |
|
106 |
return new LSIDDataPort[] { |
|
107 |
new HTTPLocation( |
|
108 |
hd.host, hd.port, |
|
109 |
hd.pathPrefix + "/authority/data" |
|
110 |
), |
|
111 |
new SOAPLocation( |
|
112 |
hd.baseURL + "data" |
|
113 |
) |
|
114 |
}; |
|
115 |
} |
|
92 |
int lsType; |
|
93 |
try { |
|
94 |
lsType = lookup.lsidType(lsid); |
|
95 |
} catch (LSIDServerException ex) { |
|
96 |
ex.printStackTrace(); |
|
97 |
lsType = LSIDDataLookup.UNKNOWN; |
|
98 |
} |
|
99 |
if (lsType == LSIDDataLookup.UNKNOWN) |
|
100 |
return null; |
|
101 |
if (lsType == LSIDDataLookup.ABSTRACT) |
|
102 |
return new LSIDDataPort[0]; |
|
116 | 103 |
|
117 |
private static final Pattern HOST_PTN = Pattern.compile( |
|
118 |
"https?://([^/:]+)(?::(\\d+))?(.*)/authority(.*)" |
|
119 |
); |
|
120 |
|
|
121 |
/* Q&D implementation */ |
|
122 |
private class HostDescriptor { |
|
123 |
public String host; |
|
124 |
public int port; |
|
125 |
public String pathPrefix; |
|
126 |
public String baseURL; |
|
127 |
|
|
128 |
public HostDescriptor(String url) { |
|
104 |
HostDescriptor hd = new HostDescriptor(url); |
|
105 |
return new LSIDDataPort[] { |
|
106 |
new HTTPLocation(hd.host, hd.port, hd.pathPrefix |
|
107 |
+ "/authority/data"), |
|
108 |
new SOAPLocation(hd.baseURL + "data")}; |
|
109 |
} |
|
110 |
|
|
111 |
private static final Pattern HOST_PTN = Pattern |
|
112 |
.compile("https?://([^/:]+)(?::(\\d+))?(.*)/authority(.*)"); |
|
113 |
|
|
114 |
/* Q&D implementation */ |
|
115 |
private class HostDescriptor |
|
116 |
{ |
|
117 |
public String host; |
|
118 |
public int port; |
|
119 |
public String pathPrefix; |
|
120 |
public String baseURL; |
|
121 |
|
|
122 |
public HostDescriptor(String url) |
|
123 |
{ |
|
129 | 124 |
logger.debug("Creating a HostDescriptor for: " + url); |
130 |
//Thread.dumpStack(); |
|
131 |
host = "localhost";
|
|
132 |
port = -1;
|
|
133 |
pathPrefix = "";
|
|
134 |
if (url != null || url.length() > 0) {
|
|
125 |
// Thread.dumpStack();
|
|
126 |
host = "localhost";
|
|
127 |
port = -1;
|
|
128 |
pathPrefix = "";
|
|
129 |
if (url != null || url.length() > 0) {
|
|
135 | 130 |
logger.debug("HostDescriptor: url is > 0 length"); |
136 |
Matcher m = HOST_PTN.matcher(url);
|
|
137 |
if (m.lookingAt()) {
|
|
138 |
host = m.group(1);
|
|
131 |
Matcher m = HOST_PTN.matcher(url);
|
|
132 |
if (m.lookingAt()) {
|
|
133 |
host = m.group(1);
|
|
139 | 134 |
logger.debug("HostDescriptor.host: " + host); |
140 |
if ((m.group(2) != null) && (m.group(2).length() > 0)) {
|
|
141 |
port = Integer.parseInt(m.group(2));
|
|
135 |
if ((m.group(2) != null) && (m.group(2).length() > 0)) {
|
|
136 |
port = Integer.parseInt(m.group(2));
|
|
142 | 137 |
} |
143 | 138 |
logger.debug("HostDescriptor.port: " + port); |
144 |
pathPrefix = m.group(3);
|
|
139 |
pathPrefix = m.group(3);
|
|
145 | 140 |
logger.debug("HostDescriptor.pathPrefix: " + pathPrefix); |
146 |
}
|
|
147 |
}
|
|
148 |
if (port > 0) {
|
|
149 |
baseURL = "http://" + host + ":" + port +
|
|
150 |
pathPrefix + "/authority/";
|
|
141 |
}
|
|
142 |
}
|
|
143 |
if (port > 0) {
|
|
144 |
baseURL = "http://" + host + ":" + port + pathPrefix
|
|
145 |
+ "/authority/";
|
|
151 | 146 |
} else { |
152 |
baseURL = "http://" + host + pathPrefix + "/authority/";
|
|
147 |
baseURL = "http://" + host + pathPrefix + "/authority/";
|
|
153 | 148 |
} |
154 | 149 |
logger.debug("HostDescriptor.baseURL: " + baseURL); |
155 |
}
|
|
156 |
}
|
|
150 |
}
|
|
151 |
}
|
|
157 | 152 |
} |
Also available in: Unified diff
Reformatted LSID code for consistency.