Skip to Content.
Sympa Menu

grouper-users - [grouper-users] RE: Notification from Consumer Class

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] RE: Notification from Consumer Class


Chronological Thread 
  • From: Chris Hyzer <>
  • To: "Klug, Lawrence" <>, "" <>
  • Subject: [grouper-users] RE: Notification from Consumer Class
  • Date: Thu, 4 Oct 2012 17:44:18 +0000
  • Accept-language: en-US

http://anonsvn.internet2.edu/svn/i2mi/branches/GROUPER_2_1_BRANCH/grouper-misc/grouperClient/

 

Check it out and look for HttpClient.  Here is an example from the discovery client in that grouperclient code.

 

        Map<String, Object> logMap = log.isDebugEnabled() ? new LinkedHashMap<String, Object>() : null;

 

        if (logMap != null) {

          logMap.put("method", "DiscoveryClient.retrieveFileFromDiscoveryServer.logic");

        }

 

        //this is the URL

        String url = "failoverLogicBean.getConnectionName();

               

        //strip last slash

        url = "GrouperClientUtils.stripEnd(url, "/");

       

        String fileNameNoSlash = GrouperClientUtils.stripStart(fileNameOnServer, "/");

       

        String fullUrl = url + "/" + fileNameNoSlash;

 

        if (logMap != null) {

          logMap.put("fullUrl", fullUrl);

        }

 

        //see if invalid SSL

        String httpsSocketFactoryName = GrouperClientUtils.propertiesValue("grouperClient.https.customSocketFactory", false);

       

        //is there overhead here?  should only do this once?

        //perhaps give a custom factory

        if (!GrouperClientUtils.isBlank(httpsSocketFactoryName)) {

          Class<? extends SecureProtocolSocketFactory> httpsSocketFactoryClass = GrouperClientUtils.forName(httpsSocketFactoryName);

          SecureProtocolSocketFactory httpsSocketFactoryInstance = GrouperClientUtils.newInstance(httpsSocketFactoryClass);

          Protocol easyhttps = new Protocol("https", httpsSocketFactoryInstance, 443);

          Protocol.registerProtocol("https", easyhttps);

        }

 

        HttpClient httpClient = new HttpClient();

 

        DefaultHttpParams.getDefaultParams().setParameter(

            HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));

 

        int soTimeoutMillis = GrouperClientUtils.propertiesValueInt(

            "grouperClient.discovery.httpSocketTimeoutMillis", 90000, false);

 

        httpClient.getParams().setSoTimeout(soTimeoutMillis);

        httpClient.getParams().setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, soTimeoutMillis);

 

        int connectionManagerMillis = GrouperClientUtils.propertiesValueInt(

            "grouperClient.discovery.httpConnectionManagerTimeoutMillis", 90000, false);

 

        httpClient.getParams().setConnectionManagerTimeout(connectionManagerMillis);

 

        String user = GrouperClientUtils.propertiesValue("grouperClient.discover.user", false);

       

        if (logMap != null) {

          logMap.put("user", user);

        }

       

        if (!GrouperClientUtils.isBlank(user)) {

       

          httpClient.getParams().setAuthenticationPreemptive(true);

 

          boolean disableExternalFileLookup = GrouperClientUtils.propertiesValueBoolean(

              "encrypt.disableExternalFileLookup", false, true);

         

          //lets lookup if file

          String pass = GrouperClientUtils.propertiesValue("grouperClient.discovery.password", false);

          String passFromFile = GrouperClientUtils.readFromFileIfFile(pass, disableExternalFileLookup);

 

          String passPrefix = null;

 

          if (!GrouperClientUtils.equals(pass, passFromFile)) {

 

            passPrefix = "Discovery pass: reading encrypted value from file: " + pass;

 

            String encryptKey = GrouperClientUtils.encryptKey();

            pass = new Crypto(encryptKey).decrypt(passFromFile);

           

          } else {

            passPrefix = "Discovery pass: reading scalar value from grouper.client.properties";

          }

         

          if (GrouperClientUtils.propertiesValueBoolean("grouperClient.logging.logMaskedPassword", false, false)) {

            if (logMap != null) {

              logMap.put(passPrefix, GrouperClientUtils.repeat("*", pass.length()));

            }

          }

 

          Credentials defaultcreds = new UsernamePasswordCredentials(user, pass);

 

          //set auth scope to null and negative so it applies to all hosts and ports

          httpClient.getState().setCredentials(new AuthScope(null, -1), defaultcreds);

        }

 

        GetMethod getMethod = new GetMethod(fullUrl);

 

        getMethod.setRequestHeader("Connection", "close");

       

        try {

 

          int responseCodeInt = httpClient.executeMethod(getMethod);

 

          if (responseCodeInt != 200) {

            throw new RuntimeException("Expected 200, but received response code: " + responseCodeInt);

          }

 

Then get the response, maybe as string? 

 

getMethod.getResponseBodyAsString();

 

Thanks,

Chris

 

 

From: Klug, Lawrence [mailto:]
Sent: Thursday, October 04, 2012 1:36 PM
To: Chris Hyzer;
Subject: RE: Notification from Consumer Class

 

>> there are examples (e.g. in GrouperClient).

 

Can you point me to the examples?  Are they in SVN?

 

Thanks,

 

Lawrence

 

From: Chris Hyzer []
Sent: Thursday, October 04, 2012 10:23 AM
To: Klug, Lawrence;
Subject: RE: Notification from Consumer Class

 

Jakarta HttpClient is what we use, its already in Grouper, and there are examples (e.g. in GrouperClient).  I wouldn’t go lower level than that unless you really like reinventing things J

 

Thanks,

Chris

 

From: On Behalf Of Klug, Lawrence
Sent: Thursday, October 04, 2012 12:17 PM
To:
Subject: [grouper-users] Notification from Consumer Class

 

Hi,

 

I’d like to construct an GET request from my ChangeLogConsumer class for notification to an outside application(Plone).  I was thinking of using HTTPClient or just standard java.net. – any suggestions about this?

 

Thanks,

 

Lawrence




Archive powered by MHonArc 2.6.16.

Top of Page