Tuesday, 4 June 2013

Submitting .NET client application data to the Adobe CQ JCR

You can create a .NET client application that can modify Adobe CQ JCR nodes and properties by using a Restful Sling request. The .NET application can create a node, modify an existing node, and delete a node. For example, assume that you responsible for building an application for an insurance company interested in persisting claim data in the Adobe CQ JCR. When an end user fills in the form and clicks the submit button, the .NET application data is submitted to Adobe CQ. A new node is created and the data is stored as node properties.

A .NET client application that is able to submit data to the Adobe CQ JCR

When the user fills in this .NET application and clicks the 'Submit Claim to JCR', the data is submitted to the CQ JCR.

















Claim data submitted from the .NET client application

Because Adobe CQ accepts Restful requests, you are not limited to the type of client technology to use to submit data. That is, you can use any client technology that supports Restful requests. This development article walks you through how to build this .NET client application that can submit data to the Adobe CQ JCR. To read this entire development article, click

http://helpx.adobe.com/experience-manager/using/using-net-client-application.html

Adobe Digital Marketing Community

Join the Adobe Digital Marketing Community. Start by clicking this banner

About the Author

I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with over 16 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.

Linked Inhttp://www.linkedin.com/in/scottmacdonald2010

6 comments:

  1. Scott,
    Thanks for your article, great stuff. The only thing I can't configure it to do is read from AEM. I have adjusted my code but for some reason the httpWReq.Credentials will not authenticate (or so it appears). Do you have any suggestions or code splash for reading JCR content?

    Thanks,
    Doug
    Douglas.scott@dtag.com

    ReplyDelete
  2. I will look into issue and post an update -- thxs for your feedback!

    ReplyDelete
    Replies
    1. Just an FYI, I got the authentication working by just adding a user agent to the request (see below in watered down example). But the reesponse is not what I expected - all that's in it is the script tag at the end of html. The URL below pulls some rudimentary html from an out of the box installation of AEM but like I said, none of it is there. I'm starting to wonder if it's at all possible??

      Any suggestions would be greatly appreciated. Thanks!

      String postURL = "http://localhost:4502/content/geometrixx/en/toolbar/contacts/jcr:content/par.html";

      System.Uri uri = new System.Uri(postURL);
      HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(uri);
      ASCIIEncoding encoding = new ASCIIEncoding();
      NetworkCredential nc = new NetworkCredential("admin","admin","localhost");


      httpWReq.UserAgent = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)";
      httpWReq.Method = "GET";
      httpWReq.Credentials = nc;
      httpWReq.ContentType = "application/x-www-form-urlencoded";

      HttpWebResponse response = (HttpWebResponse) httpWReq.GetResponse();
      var stream = response.GetResponseStream();
      var reader = new StreamReader(stream);
      var html = reader.ReadToEnd();
      string test = html;

      response.Close();
      stream.Close();

      Delete
  3. Here's what we came up with for reading - it seems you have to manually add the authorization to the header:

    String postURL = "http://localhost:4502/content/claim/newClaim_a60033aa-dc40-48db-bc81-00cf28092ea4.infinity.json";

    System.Uri uri = new System.Uri(postURL);
    HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(uri);
    ASCIIEncoding encoding = new ASCIIEncoding();
    httpWReq.Method = "GET";
    string header = "admin:admin";
    byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(header);
    string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);

    httpWReq.Headers.Add("Authorization", "Basic " + returnValue);
    HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
    var stream = response.GetResponseStream();
    var reader = new StreamReader(stream);
    var html = reader.ReadToEnd();
    string test = html;

    response.Close();
    stream.Close();

    If you know of a better way, please let us know, thanks!

    Doug

    ReplyDelete
  4. A better way would be to write a custom sling servet, read the JCR, return the result set from the servet in JSON. The .NET app can invoke different servers. I will follow up this with a new article.

    ReplyDelete
  5. Hi Scott,

    Can you please provide jar files or path for the jar files. I am not able to search on internet.

    Regards,
    Ashish

    ReplyDelete