List of usage examples for java.net MalformedURLException toString
public String toString()
From source file:com.easy.facebook.android.apicall.GraphApi.java
private List<Photo> getPhotosCall(String friendID, int limitPhotos) throws EasyFacebookError { int numArrayElement = 0; int flagNext = 0; String until = ""; int countPhotos = 0; Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); if (friendID == null) friendID = "me"; String jsonResponse;//from ww w .j av a 2 s . c om List<Photo> photosList = new ArrayList<Photo>(); try { jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/photos", "GET", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } do { JSONObject objectJSON = new JSONObject(jsonResponse); String jsonData = ""; if (!objectJSON.isNull("data")) { jsonData = objectJSON.getString("data").toString(); JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData); numArrayElement = jsonArray.length(); for (int i = 0; i < jsonArray.length() && (countPhotos < limitPhotos || limitPhotos < 0); i++) { photosList.add(jsonArray.getPhoto(i)); countPhotos++; } String paging = ""; if (!objectJSON.isNull("paging")) { paging = objectJSON.getString("paging"); JSONObject objectnextJSON = new JSONObject(paging); String next = ""; if (!objectnextJSON.isNull("next")) { next = objectnextJSON.getString("next").toString(); if (!until.equals( next.substring(next.lastIndexOf("until=") + 6, next.length()).toString()) && (countPhotos < limitPhotos || limitPhotos < 0)) { flagNext = 1; until = next.substring(next.lastIndexOf("until=") + 6, next.length()); params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("limit", "25"); params.putString("until", until); jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/photos", "GET", params); objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } } else { flagNext = 0; } } } } } while (flagNext == 1 && numArrayElement > 0 && (countPhotos < limitPhotos || limitPhotos < 0)); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return photosList; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private List<Album> getAlbumsCall(String friendID, int limitAlbum) throws EasyFacebookError { int numArrayElement = 0; int flagNext = 0; String until = ""; int countAlbum = 0; Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); if (friendID == null) friendID = "me"; String jsonResponse;/*from ww w. j a v a2s .com*/ List<Album> albumList = new ArrayList<Album>(); try { jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/albums", "GET", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } do { JSONObject objectJSON = new JSONObject(jsonResponse); String jsonData = ""; if (!objectJSON.isNull("data")) { jsonData = objectJSON.getString("data").toString(); JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData); numArrayElement = jsonArray.length(); for (int i = 0; i < jsonArray.length() && (countAlbum < limitAlbum || limitAlbum < 0); i++) { albumList.add(jsonArray.getAlbum(i)); countAlbum++; } String paging = ""; if (!objectJSON.isNull("paging")) { paging = objectJSON.getString("paging"); JSONObject objectnextJSON = new JSONObject(paging); String next = ""; if (!objectnextJSON.isNull("next")) { next = objectnextJSON.getString("next").toString(); if (!until.equals( next.substring(next.lastIndexOf("until=") + 6, next.length()).toString()) && (countAlbum < limitAlbum || limitAlbum < 0)) { flagNext = 1; until = next.substring(next.lastIndexOf("until=") + 6, next.length()); params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("limit", "25"); params.putString("until", until); jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/albums", "GET", params); objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } } else { flagNext = 0; } } } } } while (flagNext == 1 && numArrayElement > 0 && (countAlbum < limitAlbum || limitAlbum < 0)); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return albumList; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private List<Events> getEventsCall(String friendID, int limitEvents) throws EasyFacebookError { int numArrayElement = 0; int flagNext = 0; String until = ""; int countEvents = 0; Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); if (friendID == null) friendID = "me"; String jsonResponse;//from ww w. j a v a 2s .co m List<Events> eventsList = new ArrayList<Events>(); try { jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/events", "GET", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } do { JSONObject objectJSON = new JSONObject(jsonResponse); String jsonData = ""; if (!objectJSON.isNull("data")) { jsonData = objectJSON.getString("data").toString(); JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData); numArrayElement = jsonArray.length(); for (int i = 0; i < jsonArray.length() && (countEvents < limitEvents || limitEvents < 0); i++) { eventsList.add(jsonArray.getEvent(i)); countEvents++; } String paging = ""; if (!objectJSON.isNull("paging")) { paging = objectJSON.getString("paging"); JSONObject objectnextJSON = new JSONObject(paging); String next = ""; if (!objectnextJSON.isNull("next")) { next = objectnextJSON.getString("next").toString(); if (!until.equals( next.substring(next.lastIndexOf("until=") + 6, next.length()).toString()) && (countEvents < limitEvents || limitEvents < 0)) { flagNext = 1; until = next.substring(next.lastIndexOf("until=") + 6, next.length()); params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("limit", "25"); params.putString("until", until); jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/events", "GET", params); objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } } else { flagNext = 0; } } } } } while (flagNext == 1 && numArrayElement > 0 && (countEvents < limitEvents || limitEvents < 0)); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return eventsList; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private List<Feed> getPostCall(String friendID, int limitPost) throws EasyFacebookError { int flagNext = 0; String until = ""; int countPost = 0; int numArrayElement = 0; Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); if (friendID == null) friendID = "me"; String jsonResponse;// w ww.j av a 2 s . c o m List<Feed> feedList = new ArrayList<Feed>(); try { jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/feed", "GET", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } do { JSONObject objectJSON = new JSONObject(jsonResponse); String jsonData = ""; if (!objectJSON.isNull("data")) { jsonData = objectJSON.getString("data").toString(); JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData); numArrayElement = jsonArray.length(); for (int i = 0; i < jsonArray.length() && (countPost < limitPost || limitPost < 0); i++) { feedList.add(jsonArray.getFeed(i)); countPost++; } String paging = ""; if (!objectJSON.isNull("paging")) { paging = objectJSON.getString("paging"); JSONObject objectnextJSON = new JSONObject(paging); String next = ""; if (!objectnextJSON.isNull("next")) { next = objectnextJSON.getString("next").toString(); if (!until.equals( next.substring(next.lastIndexOf("until=") + 6, next.length()).toString()) && (countPost < limitPost || limitPost < 0)) { flagNext = 1; until = next.substring(next.lastIndexOf("until=") + 6, next.length()); params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("limit", "25"); params.putString("until", until); jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/feed", "GET", params); objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } } else { flagNext = 0; } } } } } while (flagNext == 1 && numArrayElement > 0 && (countPost < limitPost || limitPost < 0)); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return feedList; }
From source file:com.t2.dataouthandler.DataOutHandler.java
/** * Initializes the current database//from ww w. jav a2 s . c om * * All new users should use this entry point for initializing the database * * @param remoteDatabase Name of remote database (URI) to use * @param mDatabaseType Database type (integer) (See DATABASE_TYPE_xxx) * @param t2AuthDelegate t2AuthDelegate Callbacks to send status to. * @throws DataOutHandlerException */ public void initializeDatabase(String remoteDatabase, int databaseType, T2AuthDelegate t2AuthDelegate) throws DataOutHandlerException, MalformedURLException { mDatabaseType = databaseType; mT2AuthDelegate = t2AuthDelegate; if (remoteDatabase == null) { throw new DataOutHandlerException("remoteDatabase must not be null"); } // Make sure a valid database was selected if (mDatabaseType != this.DATABASE_TYPE_T2_DRUPAL) { throw new DataOutHandlerException("Database type invalid or not supported at this time"); } // TODO: re-add support for T2Rest and AWS initializeDrupalDatabaseNames(remoteDatabase); // mEngage = JREngage.initInstance(mContext, mEngageAppId, mEngageTokenUrl, this); // // This is to account for a bug in janrain where a delegate might not get added in the initinstance call // // As odd as it seems, this ensures that only one delegate gets added per instance. // mEngage.removeDelegate(this); // mEngage.addDelegate(this); // // JREngage.blockOnInitialization(); try { mServicesClient = new ServicesClient(mRemoteDatabase); } catch (MalformedURLException e1) { Log.e(TAG, e1.toString()); e1.printStackTrace(); } catch (DataOutHandlerException e1) { Log.e(TAG, e1.toString()); e1.printStackTrace(); } mCookieStore = new PersistentCookieStore(mContext); mCookieStore.clear(); // Make sure to start fresh mServicesClient.setCookieStore(mCookieStore); try { mDbCache = new DbCache(mRemoteDatabase, mContext, mDatabaseUpdateListener); } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new DataOutHandlerException("Can't instantiate Cache"); } mDatabaseEnabled = true; // Now do any global database (or other) initialization Log.d(TAG, "Initializing T2 database dispatcher"); Log.d(TAG, "Remote database name = " + mRemoteDatabase); mDispatchThread = new DispatchThread(); mDispatchThread.start(); }
From source file:com.t2.dataouthandler.DataOutHandler.java
/** * Initializes the current database/*from w ww . j av a 2 s . co m*/ * * Note that all of the parameters (with the exception of remoteDatabase) sent to this routine are for CouchDB only. * Currently they are all N/A * * Endpoint for all initialize variants. * * @param databaseName N/A Local SQLITE database name * @param designDocName N/A Design document name * @param designDocId N/A Design document ID * @param viewName N/AView associated with database * @param remoteDatabase Name of external database * @throws DataOutHandlerException * @throws MalformedURLException */ public void initializeDatabase(String databaseName, String designDocName, String designDocId, String viewName, String remoteDatabase) throws DataOutHandlerException, MalformedURLException { mDatabaseEnabled = true; // Set database type mDatabaseType = DATABASE_TYPE_NONE; // Get chosen database from preferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); String databaseTypeString = mSharedPreferences.getString("external_database_type", "AWS"); // Based on database type: // Set up mRemoteDatabase based on either remoteDatabase if it's not blank, // or default values based on database type // Then do any database type specific initialization if (databaseTypeString.equalsIgnoreCase("AWS")) { Log.d(TAG, "Using AWS Database type"); mDatabaseType = DATABASE_TYPE_AWS; if (remoteDatabase != null) { if (remoteDatabase.equalsIgnoreCase("")) { mRemoteDatabase = DEFAULT_AWS_DB_URL; } else { mRemoteDatabase = remoteDatabase; } // // Note: for AWS we don't supply a token URL, thats // // only for interfacing with Drupal // mEngage = JREngage.initInstance(mContext, mEngageAppId, "", this); // // // This is to account for a bug in janrain where a delegate might not get added in the initinstance call // // As odd as it seems, this ensures that only one delegate gets added per instance. // mEngage.removeDelegate(this); // mEngage.addDelegate(this); // // JREngage.blockOnInitialization(); // clientManager = new AmazonClientManager(mContext.getSharedPreferences("com.amazon.aws.demo.AWSDemo", Context.MODE_PRIVATE), mRemoteDatabase); sClientManager = new AmazonClientManager(mSharedPreferences, mRemoteDatabase); // TBD - we should probably check the table status //new CheckTableStatusTask().execute(""); } } else if (databaseTypeString.equalsIgnoreCase("T2REST")) { Log.d(TAG, "Using T2 Rest Database type"); mDatabaseType = DATABASE_TYPE_T2_REST; if (remoteDatabase != null) { if (remoteDatabase.equalsIgnoreCase("")) { mRemoteDatabase = DEFAULT_REST_DB_URL; } else { mRemoteDatabase = remoteDatabase; } // mEngage = JREngage.initInstance(mContext, mEngageAppId, mEngageTokenUrl, this); // // This is to account for a bug in janrain where a delegate might not get added in the initinstance call // // As odd as it seems, this ensures that only one delegate gets added per instance. // mEngage.removeDelegate(this); // mEngage.addDelegate(this); // // JREngage.blockOnInitialization(); } } else if (databaseTypeString.equalsIgnoreCase("T2DRUPAL")) { Log.d(TAG, "Using T2 Drupal Database type"); mDatabaseType = DATABASE_TYPE_T2_DRUPAL; initializeDrupalDatabaseNames(remoteDatabase); // mEngage = JREngage.initInstance(mContext, mEngageAppId, mEngageTokenUrl, this); // // This is to account for a bug in janrain where a delegate might not get added in the initinstance call // // As odd as it seems, this ensures that only one delegate gets added per instance. // mEngage.removeDelegate(this); // mEngage.addDelegate(this); // // JREngage.blockOnInitialization(); try { mServicesClient = new ServicesClient(mRemoteDatabase); } catch (MalformedURLException e1) { Log.e(TAG, e1.toString()); e1.printStackTrace(); } catch (DataOutHandlerException e1) { Log.e(TAG, e1.toString()); e1.printStackTrace(); } mCookieStore = new PersistentCookieStore(mContext); mCookieStore.clear(); // Make sure to start fresh mServicesClient.setCookieStore(mCookieStore); try { mDbCache = new DbCache(mRemoteDatabase, mContext, mDatabaseUpdateListener); } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); } } // Make sure a valid database was selected if (mDatabaseType == DATABASE_TYPE_NONE) { throw new DataOutHandlerException("Invalid database type"); } // Now do any global database (ot other) initialization Log.d(TAG, "Initializing T2 database dispatcher"); Log.d(TAG, "Remote database name = " + mRemoteDatabase); mDispatchThread = new DispatchThread(); mDispatchThread.start(); }
From source file:com.oakesville.mythling.MediaActivity.java
protected void deleteRecording(final Recording recording) { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.confirm_delete)) .setMessage(getString(R.string.delete_recording) + ":\n" + recording.getDialogTitle()) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { new DeleteRecordingTask(recording).execute(getAppSettings().getMythTvServicesBaseUrl()); // remove in this same thread to avoid confusing user boolean removed = mediaList.removeItem(recording); if (!removed) { // must be categorized Category cat = mediaList.getCategory(recording.getTitle()); if (cat != null) removed = cat.removeItem(recording); }/*from w ww . ja v a 2 s . c o m*/ if (removed) { mediaList.setCount(mediaList.getCount() - 1); onResume(); } } catch (MalformedURLException ex) { stopProgress(); Log.e(TAG, ex.getMessage(), ex); if (getAppSettings().isErrorReportingEnabled()) new Reporter(ex).send(); Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(), Toast.LENGTH_LONG).show(); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { stopProgress(); } }).show(); }
From source file:com.oakesville.mythling.MediaActivity.java
/** * Starts a transcode without immediately watching. *///from ww w . ja va2s .c o m protected void transcodeItem(final Item item) { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(getString(R.string.hls_transcode)) .setMessage(getString(R.string.begin_transcode) + ":\n" + item.getDialogTitle() + "\n" + getString(R.string.with_video_quality)) .setPositiveButton(getString(R.string.internal), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { new TranscodeVideoTask(item, false) .execute(getAppSettings().getMythTvServicesBaseUrl()); Toast.makeText(getApplicationContext(), getString(R.string.transcoding_) + item.getOneLineTitle(), Toast.LENGTH_LONG) .show(); } catch (MalformedURLException ex) { stopProgress(); Log.e(TAG, ex.getMessage(), ex); if (getAppSettings().isErrorReportingEnabled()) new Reporter(ex).send(); Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(), Toast.LENGTH_LONG).show(); } } }).setNeutralButton(getString(R.string.external), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { new TranscodeVideoTask(item, true).execute(getAppSettings().getMythTvServicesBaseUrl()); Toast.makeText(getApplicationContext(), getString(R.string.transcoding_) + item.getOneLineTitle(), Toast.LENGTH_LONG) .show(); } catch (MalformedURLException ex) { stopProgress(); Log.e(TAG, ex.getMessage(), ex); if (getAppSettings().isErrorReportingEnabled()) new Reporter(ex).send(); Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(), Toast.LENGTH_LONG).show(); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { stopProgress(); // onResume(); } }).show(); }
From source file:com.dragonflow.StandardMonitor.URLOriginalMonitor.java
private static long getURLStatus_ForBackupToRegularMeansOnly(SocketSession socketsession, long l, String s, int i, int j) { if (i >= j) { System.out.println("URLOriginalMonitor KEEPTRYING!!! - URL: " + s + "FAILED THIS MANY TIMES: " + i); return l; }/*from w ww .j a v a 2 s . c o m*/ if (l != 200L && l != 302L && l != 301L) { System.out.println( "URLOriginalMonitor KEEPTRYING!!! - URL: " + s + " status: " + l + " times attempted: " + i); int k = 0; if (socketsession.context.getSetting("_timeout").length() > 0) { k = TextUtils.toInt(socketsession.context.getSetting("_timeout")) * 1000; } else { k = 60000; } Platform.sleep(k); StringBuffer stringbuffer = new StringBuffer(); try { URL url = new URL(s); URLConnection urlconnection = url.openConnection(); System.out.println( "URLOriginalMonitor KEEPTRYING Received a : " + urlconnection.getClass().getName()); System.out.println( "URLOriginalMonitor KEEPTRYING Received connection string : " + urlconnection.toString()); urlconnection.setDoInput(true); urlconnection.setUseCaches(false); System.out.println("URLOriginalMonitor KEEPTRYING Getting an input stream..."); java.io.InputStream inputstream = urlconnection.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); for (String s5 = null; (s5 = bufferedreader.readLine()) != null;) { stringbuffer.append(s5); } System.out.println("URLOriginalMonitor KEEPTRYING CONTENTS: " + stringbuffer.toString()); } catch (MalformedURLException malformedurlexception) { String s1 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + malformedurlexception.toString(); LogManager.log("Error", s1); LogManager.log("Error", FileUtils.stackTraceText(malformedurlexception)); System.out.println(s1); malformedurlexception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (IOException ioexception) { String s2 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + ioexception.toString(); LogManager.log("Error", s2); LogManager.log("Error", FileUtils.stackTraceText(ioexception)); System.out.println(s2); ioexception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (Exception exception) { String s3 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + exception.toString(); LogManager.log("Error", s3); LogManager.log("Error", FileUtils.stackTraceText(exception)); System.out.println(s3); exception.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } catch (Throwable throwable) { String s4 = "URLOriginalMonitor KEEPTRYING error attempted backup URL retrieval: " + s + " exception: " + throwable.toString(); LogManager.log("Error", s4); LogManager.log("Error", FileUtils.stackTraceText(throwable)); System.out.println(s4); throwable.printStackTrace(); return getURLStatus_ForBackupToRegularMeansOnly(socketsession, l, s, ++i, j); } return 200L; } else { return l; } }
From source file:orca.shirako.container.RemoteRegistryCache.java
/** * set up client-side SSL parameters/*from w w w . j av a2s.co m*/ */ public static void configureSSL() { if (configuredSSL) { return; } configuredSSL = true; registryUrl = Globals.getContainer().getConfiguration().getProperty(OrcaContainer.PropertyRegistryUrl); if (registryUrl == null) { Globals.Log.info("No external registry is specified."); return; } URL registryURL = null; try { registryURL = new URL(registryUrl); } catch (MalformedURLException e) { Globals.Log.info("Unable to parse registry URL: " + registryUrl); return; } // load registry cert fingerprint Globals.Log.debug("Loading registry certificate fingerprint"); String registryCertFingerprint = Globals.getContainer().getConfiguration() .getProperty(OrcaContainer.PropertyRegistryCertFingerprint); if (registryCertFingerprint == null) { Globals.Log.info( "Registry certificate fingerprint property (" + OrcaContainer.PropertyRegistryCertFingerprint + ") is not specified, skipping registry SSL configuration"); return; } // convert to byte array String[] fingerPrintBytes = registryCertFingerprint.split(":"); for (int i = 0; i < 16; i++) registryCertDigest[i] = (byte) (Integer.parseInt(fingerPrintBytes[i], 16) & 0xFF); // Create a trust manager that does not validate certificate chains TrustManager[] trustRegistryCert = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { // return 0 size array, not null, per spec return new X509Certificate[0]; } public void checkClientTrusted(X509Certificate[] certs, String authType) { // Trust always } public void checkServerTrusted(X509Certificate[] certs, String authType) { // Trust always MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); if (certs.length == 0) throw new CertificateException(); byte[] certDigest = md.digest(certs[0].getEncoded()); if (!Arrays.equals(certDigest, registryCertDigest)) { Globals.Log.error( "Certificate presented by registry does not match local copy, communications with registry is not possible"); sslError = true; if (threadStarted) RemoteRegistryCache.getInstance().stop(); ActorLiveness.allStop(); throw new CertificateException(); } } catch (NoSuchAlgorithmException e) { } catch (Exception e) { Globals.Log .error("Unable to compare server certificate digest to the existing registry digest: " + e.toString()); sslError = true; if (threadStarted) RemoteRegistryCache.getInstance().stop(); ActorLiveness.allStop(); } } } }; Globals.Log.info("Creating a multikey manager for registry communications"); // create multikeymanager mkm = new MultiKeyManager(); // register a new protocol ContextualSSLProtocolSocketFactory regSslFact = new ContextualSSLProtocolSocketFactory(); // add this multikey context factory for the registry host/port regSslFact.addHostContextFactory(new MultiKeySSLContextFactory(mkm, trustRegistryCert), registryURL.getHost(), registryURL.getPort()); // register the protocol (Note: All xmlrpc clients must use XmlRpcCommonsTransportFactory // for this to work). See ContextualSSLProtocolSocketFactory. Protocol reghhttps = new Protocol("https", (ProtocolSocketFactory) regSslFact, 443); Protocol.registerProtocol("https", reghhttps); }