- How to get an API access token?
- How to work with Refresh Token and Access Token?
- How to Create and Deploy a Custom Publishing Activity?
- How to Create, Run, and Deploy a Custom Service?
- How to set or get the value of an attribute?
- How to create and manage a publishing channel?
- How to migrate configurations from one server to another?
- How to migrate REST Endpoints from v1.x to v3.x of QPPNG?
- How to retrieve audit events?
- How to generate custom audit events?
- How to check-in an asset to the repository?
- How to verify the status of a checked-in asset?
- How to create a collection on the repository?
- How to publish a document?
How to Create, Run, and Deploy a Custom Service?
Pre-requisites
You must have the following installed on your machine:
Java 8
Maven
Eclipse
Create App
Create a new spring boot app.
Include spring-boot-starter-web and spring-boot-starter-security starter projects.
Add the following necessary dependencies in the file pom.xml along with your third party dependencies.
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>com.quark.qpp</groupId>
<artifactId>qpp-content-services-remoting-stubs</artifactId>
<version>15.0-SNAPSHOT</version>
</dependency>
Add the files JwtAuthenticationProvider.java and SecurityConfig.java in any package scannable while building Spring application context.
Add your Services and their implementation code as required.
Package App
To build a package, you have to use Maven assembly plugin and maven-ant-plugin as per the following process:
Create a folder Build (in your workspace folder) and create a file pom.xml in the folder Build.
Create a folder Assembly inside the folder Build. Create the files pom.xml and assembly.xml files in the folder Assembly.
Add the relative path to the app you have created and to the folder Assembly in file Build > pom.xml. Take reference from the content below.
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.quark.qpp</groupId>
<artifactId>qpp-sample-service-main</artifactId>
<version>15.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../SampleService</module>
<module>Assembly</module>
</modules>
</project>
- Configure the file assembly.xml as follows:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>bundle</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>../../SampleService</directory>
<includes>
<include>**/src/main/resources/*.*</include>
</includes>
<outputDirectory>tempconf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<excludes>
<exclude>com.quark.qpp:*</exclude>
</excludes>
<outputDirectory>Build/dependencies</outputDirectory>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>com.quark.qpp:*</include>
</includes>
<outputDirectory>Build/lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
- Configure
maven-assembly-plugin andmaven-antrun-plugin In Plugins section of the file Build > Assembly > pom.xml. Add the app you have created as a dependency.
<dependencies>
<dependency>
<groupId>com.quark.qpp</groupId>
<artifactId>qpp-sample-service</artifactId>
<version>15.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy todir="./target/${project.artifactId}-${project.version}-bundle/Build/conf" flatten="true">
<fileset dir="./target/${project.artifactId}-${project.version}-bundle/tempconf" includes="**/src/main/resources/*.*" />
</copy>
<delete dir="./target/${project.artifactId}-${project.version}-bundle/tempconf" />
<copy todir="${ShuttleFolder}">
<fileset dir="./target/${project.artifactId}-${project.version}-bundle" includes="**" />
</copy>
<copy todir="${ShuttleFolder}/Build">
<fileset dir="../" includes="Start.bat"/>
</copy>
<copy todir="${ShuttleFolder}/Build">
<fileset dir="../" includes="Start.sh"/>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
From the folder Build, run the following command in command prompt:
mvn clean install
Copy the ${ShuttleFolder} to a linux ubuntu machine having docker installed.
Create Docker Image
- Create a file with name dockerfile parallel to the folder Build where you copied the contents of ${ShuttleFolder} on Linux ubuntu machine. Add the following content in the file dockerfile:
#Dockerfile for Sample Services
#Indicates that custom base image is being used, this image has Java(TM) SE Runtime Environment (build 1.8.0_201-b09) and imagemagick pre installed.
FROM amazoncorretto:8
#Set the Environment variables
ENV \
content.platform.services.url=qcpcontentservice:61400
#Copy server binaries to sever folder in container
COPY . server
#Open ports needed in container, this does not map them to host machine
EXPOSE 8080
#Install bash, needed for ease of use in case any error in container needs to be debugged
RUN apk add --update bash
RUN yum -y install procps
#Change permissions for Start.sh
RUN chmod 777 /server/Build/Start.sh
#Start server with docker container, the default command that will be executed
#can be overridden with docker run command
CMD ["bash", "-c", "./server/Build/Start.sh"]
From the folder where the file dockerfile is stored, run the following command in command prompt:
docker build -t <name/tag of the image> (for example, docker build -t qcpsampleservice)
To check if the image is listed in docker images, run the following command:
docker images | grep -i qcpsampleservice
Execute Docker Image
Create a YAML file with the following command:
sudo nano docker-compose.yml
Paste the following contents (with the same indentation) in to the YAML file and save the file.
qcpsampleservice:
image: qcpsampleservice:latest
container_name : qcpsampleservice
environment:
- content.platform.services.url=https://rivacorp.app.quark.com/
restart: always
ports:
- "8080:8080"
From the folder where the file docker-compose.yml is stored, run the following command:
docker-compose up -d
"-d" runs a container in the background.