{"id":18687432,"url":"https://github.com/alfresco/alfresco-java-sdk","last_synced_at":"2025-07-05T04:05:49.347Z","repository":{"id":37694301,"uuid":"331050474","full_name":"Alfresco/alfresco-java-sdk","owner":"Alfresco","description":"Alfresco Out-Of-Process SDK for Java Developers","archived":false,"fork":false,"pushed_at":"2025-07-01T07:06:54.000Z","size":3346,"stargazers_count":16,"open_issues_count":20,"forks_count":7,"subscribers_count":50,"default_branch":"develop","last_synced_at":"2025-07-01T07:23:43.726Z","etag":null,"topics":["alfresco","events","java","out-of-process","rest-client","sdk"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alfresco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-19T17:02:13.000Z","updated_at":"2025-07-01T07:06:56.000Z","dependencies_parsed_at":"2023-02-16T23:46:07.609Z","dependency_job_id":"515eb260-2e8f-4307-ae76-b4d90bca6401","html_url":"https://github.com/Alfresco/alfresco-java-sdk","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/Alfresco/alfresco-java-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alfresco%2Falfresco-java-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alfresco%2Falfresco-java-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alfresco%2Falfresco-java-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alfresco%2Falfresco-java-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alfresco","download_url":"https://codeload.github.com/Alfresco/alfresco-java-sdk/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alfresco%2Falfresco-java-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263679238,"owners_count":23495014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alfresco","events","java","out-of-process","rest-client","sdk"],"created_at":"2024-11-07T10:32:50.485Z","updated_at":"2025-07-05T04:05:49.322Z","avatar_url":"https://github.com/Alfresco.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to the Alfresco Java SDK\n\n\u003cp align=\"center\"\u003e\n  \u003cimg title=\"alfresco\" alt='alfresco' src='docs/images/alfresco.png'  width=\"229px\" height=\"160px\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n## What is Alfresco Java SDK?\n\nThe Alfresco Java SDK includes a set of APIs and samples that allows developers to quickly build Java applications that integrate with Alfresco. \u003cbr/\u003e\n\nThis SDK provides functionality to connect to both on-premise and Cloud-based servers. Alfresco servers of version 7.x and above are supported.\n\n## How does it work?\n\nAlfresco Java SDK consist of the following groups of libraries:\n\n* [alfresco-acs-java-rest-api](alfresco-acs-java-rest-api): Allows applications to consume ACS public REST APIs.\n* [alfresco-java-event-api](alfresco-java-event-api): Allows applications to react to events produced by Alfresco Repository.\n\nThe [samples](samples) folder includes examples, sample applications and code snippets of the different features supported by the SDK. Each sample application\ncontains a `docker-compose` file and scripts that allows you to build and run the extension.\n\n### Pre-Requisites\n\n* Java version 17 or higher\n* Spring boot 3.1 or higher\n* Maven version 3.3 or higher\n\n### Quick start\n\n#### 1. Create a new Spring Boot application\n\n#### 2. Add these dependencies to your project's build file:\n\nMaven:\n\nFirst, add to the repositories the Alfresco public repository containing the artifacts:\n\n```xml\n\n\u003crepositories\u003e\n\n  \u003crepository\u003e\n    \u003cid\u003ealfresco-public\u003c/id\u003e\n    \u003curl\u003ehttps://artifacts.alfresco.com/nexus/content/groups/public\u003c/url\u003e\n  \u003c/repository\u003e\n\n\u003c/repositories\u003e\n```\n\nThen, add the dependency on the desired starter(s)\n\n```xml\n\n\u003cdependencies\u003e\n\n  \u003c!-- ACS Java REST APIs --\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.alfresco\u003c/groupId\u003e\n    \u003cartifactId\u003ealfresco-acs-java-rest-api-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e7.0.0\u003c/version\u003e\n  \u003c/dependency\u003e\n\n  \u003c!-- Java Event API --\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.alfresco\u003c/groupId\u003e\n    \u003cartifactId\u003ealfresco-java-event-api-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e7.0.0\u003c/version\u003e\n  \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\nGradle:\n\nFirst, add to the repositories the Alfresco public repository containing the artifacts:\n\n```groovy\nrepositories {\n  maven {\n    url \"https://artifacts.alfresco.com/nexus/content/groups/public\"\n  }\n}\n```\n\nThen, add the dependency on the desired starter(s)\n\n```groovy\ncompile \"org.alfresco:alfresco-acs-java-rest-api-spring-boot-starter:7.0.0\"\ncompile \"org.alfresco:alfresco-java-event-api-spring-boot-starter:7.0.0\"\n```\n\n#### 3. Configure Event API\n\nIn your ```application.properties``` file define the properties required to connect to the ActiveMQ broker in order to handle Repository events:\n\n```\nspring.activemq.brokerUrl=tcp://activemq-host:61616\n```\n\nAlternatively, set `SPRING_ACTIVEMQ_BROKER_URL` environment variable.\n\nAlso, this property is required if you want Spring Boot to auto-define the ActiveMQConnectionFactory, otherwise you can define that bean in Spring config\n\n```\nspring.jms.cache.enabled=false\n```\n\nSimilarly, you can alternatively set `SPRING_JMS_CACHE_ENABLED` environment variable.\n\nFor additional configuration properties of Event API, check [alfresco-java-event-api](alfresco-java-event-api).\n\n#### 4. Configure REST API\n\nIn your ```application.properties``` file provide URL, authentication mechanism and credentials for accessing the REST API:\n\n```\ncontent.service.url=http://repository:8080\ncontent.service.security.basicAuth.username=admin\ncontent.service.security.basicAuth.password=admin\n```\n\nIf you are using OAuth2, you can use client-credential based authentication:\n\n```\nspring.security.oauth2.client.registration.alfresco-rest-api.provider=alfresco-identity-service\nspring.security.oauth2.client.registration.alfresco-rest-api.client-id=clientId\nspring.security.oauth2.client.registration.alfresco-rest-api.client-secret=clientSecret\nspring.security.oauth2.client.registration.alfresco-rest-api.authorization-grant-type=client_credentials\nspring.security.oauth2.client.provider.alfresco-identity-service.token-uri=${keycloak.auth-server-url}/auth/realms/${keycloak.realm}/protocol/openid-connect/token\n```\n\nOr OAuth2 password based authentication:\n\n```\nspring.security.oauth2.client.registration.alfresco-rest-api.provider=alfresco-identity-service\nspring.security.oauth2.client.registration.alfresco-rest-api.client-id=clientId\nspring.security.oauth2.client.registration.alfresco-rest-api.client-secret=clientSecret\nspring.security.oauth2.client.registration.alfresco-rest-api.username=username\nspring.security.oauth2.client.registration.alfresco-rest-api.password=pwd\nspring.security.oauth2.client.registration.alfresco-rest-api.authorization-grant-type=password\nspring.security.oauth2.client.provider.alfresco-identity-service.token-uri=${keycloak.auth-server-url}/auth/realms/${keycloak.realm}/protocol/openid-connect/token\n```\n\nFinally, if you want to provide a custom authentication mechanism, you can enable the delegated external authentication:\n\n```\ncontent.service.security.delegated=true\n```\n\nAnd provide a bean that implements the interface ```DelegatedAuthenticationProvider```.\n\n#### 5. Handle events produced by the Repository\n\nUse out-of-the-box Event Handlers to handle specific events, using Event Filters to react to the event, only if it meets certain conditions.\n\n```java\n/**\n * Sample event handler to demonstrate reacting to the update of a content in the repository.\n */\n@Component\npublic class ContentUpdatedHandler implements OnNodeUpdatedEventHandler {\n\n  private static final Logger LOGGER = LoggerFactory.getLogger(ContentUpdatedHandler.class);\n\n  @Override\n  public void handleEvent(final RepoEvent\u003cDataAttributes\u003cResource\u003e\u003e repoEvent) {\n    LOGGER.info(\"The content of the node {} has been updated!\",\n      ((NodeResource) repoEvent.getData().getResource()).getName());\n  }\n\n  @Override\n  public EventFilter getEventFilter() {\n    return ContentChangedFilter.get();\n  }\n}\n```\n\nUse `@Order` annotation to define an execution order of multiple event handlers.\n\n```java\n    /**\n * This event handler definition illustrates how you can use Spring's {@link Order} annotation to sort the execution of event handlers.\n */\n@Bean\n@Order(10)\npublic OnNodeCreatedEventHandler firstCustomNodeCreatedEventHandler(){\n  return repoEvent-\u003eLOGGER.info(\"First Event handler triggered on node created - Event: {}\",repoEvent);\n  }\n\n/**\n * This event handler definition illustrates how you can use Spring's {@link Order} annotation to sort the execution of event handlers.\n */\n@Bean\n@Order(20)\npublic OnNodeCreatedEventHandler secondCustomNodeCreatedEventHandler(){\n  return repoEvent-\u003eLOGGER.info(\"Second Event handler triggered on node created - Event: {}\",repoEvent);\n  }\n```\n\nAlternatively, use Spring Integration to consume events:\n\n```java\n    @Bean\npublic IntegrationFlow logTheCreationOfHTMLContent(){\n  return IntegrationFlows.from(EventChannels.MAIN)\n  .filter(IntegrationEventFilter.of(EventTypeFilter.NODE_CREATED\n  .and(MimeTypeFilter.of(\"text/html\"))))\n  .handle(t-\u003eLOGGER.info(\"An HTML content has been created! - Event: {}\",t.getPayload().toString()))\n  .get();\n  }\n```\n\nYou can find more information about how to consume events at [alfresco-java-event-api](alfresco-java-event-api).\n\n#### 6. Consume the REST API\n\n```java\n    CommentsApi commentsApi;\n\npublic void addComentToNode(final String nodeId){\n  CommentBody commentBody=new CommentBody().content(\"I like this file\");\n  commentsApi.createComment(nodeId,commentBody);\n  }\n  }\n```\n\nYou can find more information about how to consume the REST API at [alfresco-java-rest-api](alfresco-java-rest-api).\n\n#### Integrating Alfresco Event Gateway\n\nAlfresco Java SDK is now compatible with [Alfresco Event Gateway](https://www.github.com/Alfresco/alfresco-event-gateway).\n\nUsing [Alfresco Event Gateway REST API](alfresco-java-rest-api/alfresco-java-rest-api-lib/alfresco-event-gateway-api), extensions can manage the lifecycle of an\nevent subscription.\n\nFor example, an out-of-process extension may create a subscription to receive certain types of events in a specific topic of an ActiveMQ broker.\n\n```java\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport org.alfresco.gateway.handler.SubscriptionsApi;\nimport org.alfresco.gateway.model.Filter;\nimport org.alfresco.gateway.model.Subscription;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\npublic class Sample {\n\n  private static final Logger LOGGER = LoggerFactory.getLogger(Sample.class);\n\n\n  public static void create(String[] args) {\n\n    @Inject\n    SubscriptionsApi subscriptionsApi;\n\n    Map\u003cString, String\u003e config = new HashMap\u003c\u003e();\n    config.put(\"broker-id\", \"my-broker\"); // Id of the a broker in alfresco-event-gateway configuration\n    config.put(\"destination\", \"topic:sample-topic\"); // Name of the topic to which the gateway shall publish the events\n\n    Filter filter = new Filter();\n    filter.setType(\"event-type\");\n    // Comma-separated list of event types accepted by the filter\n    filter.setConfig(Collections.singletonMap(\"event-types\", \"org.alfresco.event.node.Created,org.alfresco.event.node.Updated\"));\n\n    Subscription subscriptionRequest = new Subscription();\n    subscriptionRequest.setType(\"jms-activemq\");\n    subscriptionRequest.setConfig(config);\n    subscriptionRequest.setFilters(Collections.singletonList(filter));\n\n    Subscription result = subscriptionsApi.createSubscription(subscriptionRequest);\n    LOGGER.info(\"Created subscription with id: {}\", result.getId());\n  }\n}\n```\n\nThe ActiveMQ broker can be different from the one used by the Alfresco Repository and is configured in both the out-of-process extension and the Event Gateway.\n\n##### Configuring a specific ActiveMQ broker for an out-of-process extension - (Alfresco Event SDK):\n\n```\nspring.activemq.brokerUrl=tcp://my-broker-host:61616\nspring.activemq.username=test\nspring.activemq.password=my-secret\n\n# This property is required if you want Spring Boot to auto-define the ActiveMQConnectionFactory, otherwise you can define that bean in Spring config\nspring.jms.cache.enabled=false\n\nalfresco.events.topicName=topic:sample-topic\n```\n\nMore Information: [Configuring out-of-process extensions](alfresco-java-event-api)\n\n##### Configuring a specific ActiveMQ broker for an out-of-process extension - (Alfresco Event Gateway):\n\n```\n## EVENT GATEWAY BROKER CONFIG\n# This is a sample about how to configure a broker config with id \"my-broker\" (only broker-url is\n# mandatory). You can add any number of different broker configurations\n\nalfresco.event.gateway.publication.jms.broker.my-broker.broker-url=tcp://my-broker-host:61616\nalfresco.event.gateway.publication.jms.broker.my-broker.username=admin\nalfresco.event.gateway.publication.jms.broker.my-broker.password=my-secret\n```\n\nMore Information: [Configuring Alfresco Event Gateway](https://www.github.com/Alfresco/alfresco-event-gateway)\n\n## How to build the SDK project\n\n### Pre-Requisites\n\n* Java version 17 or higher\n* Maven version 3.3 or higher\n\n### Build command\n\nSimply run the next command:\n\n```console\nmvn clean install\n```\n\nThe previous command will generate the source code for the ACS REST API clients first and then it will compile all the modules and run the\ncorresponding unit and integration tests.\n\nIf you want to skip the generation of the REST API clients code, you can do it sending the maven property `skip.generation`:\n\n```console\nmvn clean install -Dskip.generation\n```\n\nRemember that you need to build the project at least once without skipping the generation step to be able to compile all the code properly. From that point, you\ncan skip the generation step if don't need it.\n\n### Integration tests\n\nRunning the integration tests requires an ACS environment to work properly. The configuration of the ACS environment to use in the integration test can be done\nusing the environment variables `CONTENT_SERVICE_URL`, `CONTENT_SERVICE_SECURITY_BASICAUTH_USERNAME` and `CONTENT_SERVICE_SECURITY_BASICAUTH_PASSWORD`.\n\nThe default values for the ACS environment used for integration tests are:\n\n- `CONTENT_SERVICE_URL` - `http://localhost:8080`\n- `CONTENT_SERVICE_SECURITY_BASICAUTH_USERNAME` - `admin`\n- `CONTENT_SERVICE_SECURITY_BASICAUTH_PASSWORD` - `admin`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfresco%2Falfresco-java-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfresco%2Falfresco-java-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfresco%2Falfresco-java-sdk/lists"}