Movatterモバイル変換


[0]ホーム

URL:


In: content-servicesIn: All docs
Close
Alfresco Content Services

Debugging Content Services

As a developer you will need to be able to debug Content Services’ product code, and custom code contained inJARs/AMPswritten by you. To do this we usually use so-called Remote debugging. This means that we start up Content Services in debug mode ready to accept remote debugging sessions. We then connect with a debugger such as IntelliJ IDEA or Eclipse using aRemote debugging session.

IntelliJ provides atutorial on how to do remote debugging with the IDEA IDE using a Hello World example. It is worth having a look at this tutorial before continuing with this article to get an understanding of how to attach a debugger to a remote process. If you areusing Eclipse, then there isthis article that might be a good read before moving on.

If you are using any of the Alfresco SDKs, then you should be looking at the following sections for information about how to do remote debugging in these environments:

Introduction

Content Services is slightly more complex than the Hello World example above. Let’s see how to debug a ReST API call, such as thelogin to get a ticket.

Remote debugging can be done either by running Content Services inDocker containers or by running in a localTomcat environment.

Prerequisites

Download the following projects to your developer machine:

Only the first project is needed here, as it contains the product source code, but it’s recommended to have the other projects available as well. The packaging projects gives valuable information about how the Docker image for the Alfresco Repository is created. The packaging projects also contain information about how to create custom Docker images, which is very useful when customJARs/AMPs should be applied.

Debug in a Docker environment

To start remote debugging with Content Services running in Docker, then download the following project:

Then change into the/docker-compose directory and create a copy of the filecommunity-docker-compose.yml calleddebug-community-docker-compose.yml:

% git clone git@github.com:Alfresco/acs-deployment.gitCloning into 'acs-deployment'......% cd acs-deployment/docker-compose docker-compose % cp community-docker-compose.yml debug-community-docker-compose.yml% ls -ltotal 88-rw-r--r--  1 admin  staff  7979 16 Jun 09:37 6.1.N-docker-compose.yml-rw-r--r--  1 admin  staff  6846 16 Jun 09:37 6.2.N-docker-compose.yml-rw-r--r--  1 admin  staff   189 16 Jun 09:37 README.md-rw-r--r--  1 admin  staff  4931 16 Jun 09:37 community-docker-compose.yml-rw-r--r--  1 admin  staff  4931 16 Jun 09:38 debug-community-docker-compose.yml-rw-r--r--  1 admin  staff  7097 16 Jun 09:37 docker-compose.yml

Configure Docker Compose for remote debugging

Edit thedebug-community-docker-compose.yml file by adding the followingports andenvironment settings:

services:    alfresco:        image: alfresco/alfresco-content-repository-community:7.1.0-M1        mem_limit: 1500m        ports:            - 8000:8000        environment:            CATALINA_OPTS: "                -agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n                "            JAVA_TOOL_OPTIONS: "            ...

The-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n option tells the JVM to start with the port 8000 open, ready to accept remote debugging sessions.

Note that the remote debugging configuration is done via theCATALINA_OPTS variable instead ofJAVA_TOOL_OPTIONS orJAVA_OPTS as we need to instruct Tomcat running inside the Docker container, not the JVM directly (this is a big difference from the IntelliJ tutorial).

We need to also open the remote debug port from the container to the host, so thathttp://localhost:8000 will be propagated to the container and Tomcat. This is done with theports configuration.

Run Content Services

Now, run Content Services and wait for it to start:

docker-compose -f debug-community-docker-compose.yml up

It’s ready when you see logs as follows:

alfresco_1 | 2021-06-16 09:12:50,699  INFO  [management.subsystems.ChildApplicationContextFactory] [http-nio-8080-exec-9] Starting 'Transformers' subsystem, ID: [Transformers, default]alfresco_1 | 2021-06-16 09:12:50,884  INFO  [management.subsystems.ChildApplicationContextFactory] [http-nio-8080-exec-9] Startup of 'Transformers' subsystem, ID: [Transformers, default] complete

Debug some source code

To test out the new debug settings, let’s debug the source code that is called when you call the remote API toget a ticket that can be used for authentication.

Open thealfresco-community-repo project in IntelliJ IDEA and look up thesrc/main/java/org/alfresco/rest/api/impl/AuthenticationsImpl.java file. Set a breakpointin this file where a ticket is created, as shown:

create-ticket-breakpoint

Set up a Remote debugging session in IDEA (Run -> Debug… -> Edit Configurations… -> + -> Remote JVM Debug):

idea-remote-debug-setup

ClickDebug to start the debug session:

remote-debug-session-started

Now, call the Remote API that is used to log in and get a ticket (using the defaultadmin/admin credentials):

% curl --header "Content-Type: application/json" --request POST --data '{"userId":"admin","password":"admin"}' http://localhost:8080/alfresco/api/-default-/public/authentication/versions/1/tickets

This should make the debugger stop on the breakpoint line in IDEA:

idea-remote-debug-breakpoint-stop

We can see the credentials used to log in, and start debugging the code as we are used to.

This way of debugging works equally well for any custom code that you have applied to Content Services.

Debug in a Tomcat environment (no containers)

To start remote debugging with Content Services running directly in Tomcat (i.e. not using containers but running Content Services based on aZIP installation), then make sure you start Tomcat in debug mode (similar to how we configured theCATALINA_OPTS variable in the container environment).

See thisStackOverflow article for more information about how to start Apache Tomcat in debug mode. This article also links to the officialTomcat development page, which is a good read.

Debug some source code

Debugging in a Tomcat environment is the same as in a Docker container environment, seethis section above.

Edit this page

Suggest an edit on GitHub
By clicking "Accept Cookies", you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.View Cookie Policy.

[8]ページ先頭

©2009-2025 Movatter.jp