2016-04-22 2 views
0

Ich versuche, eine ReplicationEventListener für AEM 6.1 mit dem folgenden Code zu erstellen, aber es gibt eine classcast exception bei Linie ReplicationAction action = ReplicationAction)ReplicationAction.fromEvent(event);Replikation Ereignis-Listener in AEM Klasse werfen Ausnahme

Die Ausnahme

ist
java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to java.util.Date 
    at com.day.cq.replication.ReplicationEvent.fromEvent(ReplicationEvent.java:221) 
    at com.adobe.cq.listeners.ReplicationEventListener.handleEvent(ReplicationEventListener.java:30) 
    at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) 
    at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:118) 
    at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:159) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

Mein JAVA-Klasse ist

package com.adobe.cq.listeners; 
import org.apache.felix.scr.annotations.Component; 
import org.apache.felix.scr.annotations.Property; 
import org.apache.felix.scr.annotations.Service; 
import org.osgi.service.event.Event; 
import org.osgi.service.event.EventHandler; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

import com.day.cq.replication.ReplicationAction; 

@Component 
@Service() 
@Property(name = "event.topics", value = { ReplicationAction.EVENT_TOPIC }) 
public class ReplicationEventListener implements EventHandler{ 
private static final Logger log = LoggerFactory.getLogger(ReplicationEventListener.class); 


public void handleEvent(Event event) { 

    String n[] = event.getPropertyNames(); 
    log.info("Event properties: "); 

    for (String s : n) { 

     log.info(s + " = " + event.getProperty(s)); 
    } 

    ReplicationAction action = (ReplicationAction) ReplicationAction.fromEvent(event); 

    if (action != null) { 

     log.info("Replication action {} occured on {} ", action.getType() 
       .name(), action.getPath()); 



    } 



} 
    } 

Meine Eltern POM

<?xml version="1.0" encoding="UTF-8"?> 
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
     <modelVersion>4.0.0</modelVersion> 
     <!-- ====================================================================== --> 
     <!-- P A R E N T P R O J E C T D E S C R I P T I O N --> 
     <!-- ====================================================================== --> 

     <groupId>com.adobe.cq</groupId> 
     <artifactId>sample</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <packaging>pom</packaging> 

     <name>My Project - Reactor Project</name> 
     <description>Maven Multimodule project for My Project.</description> 

     <prerequisites> 
      <maven>3.0.2</maven> 
     </prerequisites> 

     <!-- ====================================================================== --> 
     <!-- P R O P E R T I E S --> 
     <!-- ====================================================================== --> 
     <properties> 
      <crx.host>localhost</crx.host> 
      <crx.port>4502</crx.port> 
      <crx.username>admin</crx.username> 
      <crx.password>admin</crx.password> 
      <publish.crx.host>localhost</publish.crx.host> 
      <publish.crx.port>4503</publish.crx.port> 
      <publish.crx.username>admin</publish.crx.username> 
      <publish.crx.password>admin</publish.crx.password> 
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     </properties> 

     <dependencyManagement> 
      <dependencies> 
       <dependency> 
        <groupId>org.osgi</groupId> 
        <artifactId>org.osgi.core</artifactId> 
        <version>4.2.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.osgi</groupId> 
        <artifactId>org.osgi.compendium</artifactId> 
        <version>4.2.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>org.apache.felix.scr.annotations</artifactId> 
        <version>1.6.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>biz.aQute</groupId> 
        <artifactId>bndlib</artifactId> 
        <version>1.43.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.slf4j</groupId> 
        <artifactId>slf4j-api</artifactId> 
        <version>1.5.10</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>servlet-api</artifactId> 
        <version>2.5</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>javax.jcr</groupId> 
        <artifactId>jcr</artifactId> 
        <version>2.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.sling</groupId> 
        <artifactId>org.apache.sling.api</artifactId> 
        <version>2.2.0</version> 
        <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.sling</groupId> 
        <artifactId>org.apache.sling.jcr.api</artifactId> 


     <version>2.1.0</version> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>junit</groupId> 
       <artifactId>junit</artifactId> 
       <version>4.8.1</version> 
       <scope>test</scope> 
      </dependency> 

      <dependency> 
    <groupId>com.day.cq</groupId> 
    <artifactId>cq-replication</artifactId> 
    <version>5.0.6</version> 
</dependency> 

    <dependency> 
     <groupId>org.apache.sling</groupId> 
     <artifactId>org.apache.sling.models.api</artifactId> 
     <version>1.1.0</version> 
     </dependency> 

      <dependency> 
    <groupId>com.day.cq</groupId> 

     <artifactId>cq-mailer</artifactId> 

     <version>5.6.2</version> 

     <scope>provided</scope> 

     </dependency> 
     <dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-email</artifactId> 
    <version>1.1</version> 
</dependency> 


     </dependencies> 
    </dependencyManagement> 

    <!-- 
     Inclusion of repositories in POMs is controversial, to say the least. 
     It would be best if you proxied the Adobe repository using a Maven 
     Repository Manager. Once you do that, remove these sections. 
    --> 
    <repositories> 
     <repository> 
      <id>adobe</id> 
      <name>Adobe Public Repository</name> 
      <url>http://repo.adobe.com/nexus/content/groups/public/</url> 
      <layout>default</layout> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>adobe</id> 
      <name>Adobe Public Repository</name> 
      <url>http://repo.adobe.com/nexus/content/groups/public/</url> 
      <layout>default</layout> 
     </pluginRepository> 
    </pluginRepositories> 

    <build> 
     <pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>maven-scr-plugin</artifactId> 
        <version>1.7.4</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>maven-bundle-plugin</artifactId> 
        <version>2.3.7</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.1</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.6</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-deploy-plugin</artifactId> 
        <version>2.7</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-install-plugin</artifactId> 
        <version>2.4</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.14.1</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-javadoc-plugin</artifactId> 
        <version>2.9</version> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.sling</groupId> 
        <artifactId>maven-sling-plugin</artifactId> 
        <version>2.1.0</version> 
        <configuration> 
         <username>${crx.username}</username> 
         <password>${crx.password}</password> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>com.day.jcr.vault</groupId> 
        <artifactId>content-package-maven-plugin</artifactId> 
        <version>0.0.20</version> 
        <extensions>true</extensions> 
        <configuration> 
         <failOnError>true</failOnError> 
         <username>${crx.username}</username> 
         <password>${crx.password}</password> 
        </configuration> 
       </plugin> 
       <!--This plugin's configuration is used to store Eclipse 
        m2e settings only. It has no influence on the Maven build itself. --> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId> 
              org.apache.felix 
             </groupId> 
             <artifactId> 
              maven-scr-plugin 
             </artifactId> 
             <versionRange> 
              [1.0.0,) 
             </versionRange> 
             <goals> 
              <goal>scr</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <ignore/> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <profiles> 
     <profile> 
      <id>autoInstallBundle</id> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.apache.sling</groupId> 
         <artifactId>maven-sling-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>install-bundle</id> 
           <goals> 
            <goal>install</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 
    <modules> 
    <module>bundle</module> 
    <module>content</module> 
    </modules> 
</project> 

Mein Bundle POM ist

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> 
    <modelVersion>4.0.0</modelVersion> 
    <!-- ====================================================================== --> 
    <!-- P A R E N T P R O J E C T D E S C R I P T I O N --> 
    <!-- ====================================================================== --> 
    <parent> 
     <groupId>com.adobe.cq</groupId> 
     <artifactId>sample</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <!-- ====================================================================== --> 
    <!-- P R O J E C T D E S C R I P T I O N --> 
    <!-- ====================================================================== --> 

    <artifactId>sample-bundle</artifactId> 
    <packaging>bundle</packaging> 
    <name>My Project Bundle</name> 

    <dependencies> 
     <dependency> 
      <groupId>org.osgi</groupId> 
      <artifactId>org.osgi.compendium</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.osgi</groupId> 
      <artifactId>org.osgi.core</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>org.apache.felix.scr.annotations</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>biz.aQute</groupId> 
      <artifactId>bndlib</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>javax.jcr</groupId> 
      <artifactId>jcr</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.sling</groupId> 
      <artifactId>org.apache.sling.api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.sling</groupId> 
      <artifactId>org.apache.sling.jcr.api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.sling</groupId> 
      <artifactId>org.apache.sling.models.api</artifactId> 
     </dependency> 

     <dependency> 
    <groupId>com.day.cq</groupId> 
    <artifactId>cq-replication</artifactId> 

</dependency> 

     <dependency> 
    <groupId>com.day.cq</groupId> 

     <artifactId>cq-mailer</artifactId> 



     <scope>provided</scope> 

     </dependency> 

<dependency> 
    <groupId>com.day.cq</groupId> 

     <artifactId>cq-mailer</artifactId> 



     <scope>provided</scope> 

     </dependency> 

     <dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-email</artifactId> 

</dependency> 


    </dependencies> 

    <!-- ====================================================================== --> 
    <!-- B U I L D D E F I N I T I O N --> 
    <!-- ====================================================================== --> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-scr-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>generate-scr-descriptor</id> 
         <goals> 
          <goal>scr</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
        <Sling-Model-Packages>com.adobe.cq.models</Sling-Model-Packages> 
         <Bundle-SymbolicName>com.adobe.cq.sample-bundle</Bundle-SymbolicName> 
         <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
         <!--<Embed-Directory>OSGI-INF/lib</Embed-Directory> 
         <Embed-Transitive>true</Embed-Transitive> 
         --> 
        </instructions> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.sling</groupId> 
       <artifactId>maven-sling-plugin</artifactId> 
       <configuration> 
        <slingUrl>http://${crx.host}:${crx.port}/apps/sampleProject/install</slingUrl> 
        <usePut>true</usePut> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-javadoc-plugin</artifactId> 
       <configuration> 
        <excludePackageNames> 
         *.impl 
        </excludePackageNames> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Any help is appreciated 

Vielen Dank im Voraus

+0

Würden Sie bitte ReplicationEvent.java Klasse hinzufügen? Dann wird es hilfreich sein, eine Antwort zu geben. @Shreya – SkyWalker

+0

@SkyWalker Ich habe bereits ReplicationEventListener class.Please siehe oben ist der erste Code, den ich hinzugefügt habe. –

+0

Ich möchte ReplicationEvent.java Klasse bereitstellen. Wenn möglich, aktualisieren Sie Ihre Frage und geben Sie den Java-Code – SkyWalker

Antwort

0

Der Runtime-APIs für cq-replication Paket paßt nicht zu dem, was Sie bei der Kompilierung verwenden. Sie müssen die Version dieses Glases auf den neuesten Stand in Ihrer pom.xml aktualisieren. Da dies auch eine Container-Bibliothek ist, sollten Sie diese als provided-Abhängigkeit haben. Die neuesten Versionen verschiedener Bibliotheken finden Sie in Adobe public nexus repository.