2

When I click on "update preview", "update preview" show again and again.

Because Real URL is different from URL of Broker DB, the above problem happen.

So, I solve the problem by using ADF.

I refer to the follow pages. the follow pages are very useful for me.

http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-C6537469-7D70-4F82-B6C9-7883213F9F1B

http://jaimesantosalcon.blogspot.jp/2013/10/managing-claims-and-their-scope-in-sdl.html

http://erichuiza.blogspot.jp/2012/07/ambient-data-framework-in-nutshell.html

https://github.com/TridionPractice/tridion-practice/blob/master/AmbientDataFramework/ClaimStore.jsp

At first, to understand adf program, i implement easy program.

  1. Implement program and build
package com.tridion.tag.common;

import java.io.File;
import java.io.FileWriter;
import java.net.URI;
import java.util.Map;
import java.util.TreeMap;

import com.tridion.ambientdata.AmbientDataException;
import com.tridion.ambientdata.claimstore.ClaimStore;
import com.tridion.ambientdata.processing.AbstractClaimProcessor;

public class AmbientDataFrameworkExtensionHandler extends AbstractClaimProcessor {

  @Override
  public void onRequestStart(ClaimStore claimStore) throws AmbientDataException {
      try {
          TreeMap<String, Object> claims = new TreeMap<String, Object>();
          Map<URI, Object> allClaims = claimStore.getAll();
          File file1 = new File("/tmp/log_adf1.txt");
          for (URI claimUri : allClaims.keySet()) {
              claims.put(claimUri.toString(), allClaims.get(claimUri));
          }
          FileWriter filewriter = new FileWriter(file1);
          filewriter.write("onRequestStart");
      } catch (Exception e) {
          throw new AmbientDataException(e);
      }
  }

  @Override
  public void onRequestEnd(ClaimStore claimStore) throws AmbientDataException {
      try {
          File file = new File("/tmp/log_adf2.txt");
          FileWriter filewriter = new FileWriter(file);
          filewriter.write("onRequestEnd");
      } catch (Exception e) {
          throw new AmbientDataException(e);
      }
  }

  @Override
  public void onSessionStart(ClaimStore claimStore) throws AmbientDataException {
      try {
          File file = new File("/tmp/log_adf3.txt");
          FileWriter filewriter = new FileWriter(file);
          filewriter.write("onRequestEnd");
          filewriter.write(claimStore.getAll().size());
      } catch (Exception e) {
          throw new AmbientDataException(e);
      }
  }
}
  1. create cd_ambient_cartridge_conf.xml (configuration file)

    <ClaimDefinitions>
            <ClaimDefinition Uri="tcd:claim:userid" Scope="SESSION" Description="The user's unique identifier." />
    </ClaimDefinitions>
    
    <ClaimProcessorDefinitions>
            <ClaimProcessorDefinition Uri="tcd:claimprocessor:example:userdetails" ImplementationClass="com.tridion.tag.common.AmbientDataFrameworkExtensionHandler"
                                                    Description="Example">
            </ClaimProcessorDefinition>
    </ClaimProcessorDefinitions>
    

  2. configure cd_ambient_conf.xml

  3. restart webservice

  4. access the webpage

  5. confirm the result

    I confirm that log_adf1.txt and log_adf2.txt are created at tmp directory. but the above files are 0 KB and any error is not outputted. I expect that the files are described as each "onRequestStart", "onRequestEnd".

why the program is not work as expected is my program bad and my understarding wrong?

1 Answer 1

1

There's a lot of parts of this question, but I'll just try to answer your last question about why the log files are 0 bytes.

I think this is caused by you not closing the file correctly. I believe you need to call the close() method on the FileWriter for it to flush and unlock the file.

See the following answer for several different examples of how to do so:

Best way to close nested streams in Java 6

1
  • Thank you answering my question and solve the problem. I mistake. next, I try to solve the real issue (update preview). In fact, I don't know how to solve by using ADF
    – Arai Yuhei
    Jan 6, 2016 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.