}
uri = uri.replaceAll("&+","&");
String mappedURI = mapURI(uri);
JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS);
Element remoteFragment = (Element) xlinkCache.getFromGroup(uri.toLowerCase(), mappedURI);
if (remoteFragment == null) {
Log.info(Log.XLINK_PROCESSOR, "cache MISS on "+uri.toLowerCase());
try {
if(uri.startsWith(XLink.LOCAL_PROTOCOL)) {
LocalServiceRequest request = LocalServiceRequest.create(uri.replaceAll("&", "&"));
request.setDebug(false);
if(request.getLanguage() == null) {
request.setLanguage(srvContext.getLanguage());
}
request.setInputMethod(InputMethod.GET);
remoteFragment = srvContext.execute(request);
} else {
URL url = new URL(uri.replaceAll("&", "&"));
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
try {
remoteFragment = Xml.loadStream(in);
if(Log.isDebugEnabled(Log.XLINK_PROCESSOR))
Log.debug(Log.XLINK_PROCESSOR,"Read:\n"+Xml.getString(remoteFragment));
} finally {
in.close();
}
}
} catch (Exception e) { // MalformedURLException, IOException
synchronized(Processor.class) {
failures.add (System.currentTimeMillis());
}
Log.error(Log.XLINK_PROCESSOR,"Failed on " + uri
+ " with exception message " + e.getMessage());
}
if (remoteFragment != null && !remoteFragment.getName().equalsIgnoreCase("error")) {
xlinkCache.putInGroup(uri.toLowerCase(), mappedURI, remoteFragment);
if(Log.isDebugEnabled(Log.XLINK_PROCESSOR))
Log.debug(Log.XLINK_PROCESSOR,"cache miss for "+uri);
} else {
return null;
}