You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-new/eclipse_lyo/setup-an-oslc-provider-consumer-application.md
+51-50Lines changed: 51 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
1
# Create an Eclipse Lyo project
2
2
3
-
This document provides step-by-step instructions for creating a Java project with the necessary configurations to develop any OSLC server/client using Lyo. The instructions assume you are using the Eclipse IDE, but should be equally valid for any other development environment.
3
+
This document provides step-by-step instructions for creating a Java project with the necessary configurations to develop OSLC server/client applications using Lyo. The instructions assume Eclipse IDE is being used, but are equally valid for other development environments.
4
4
5
5
## An alternative to the manual steps below
6
6
7
7
An alternative to the instructions on this page is to use [Lyo Designer](./lyo-designer.md) to quickly generate the project, including a very basic code skeleton. The generated project will also include the necessary setup for OpenApi/Swagger support, TRS, etc.
8
8
9
-
1.Make sure your environment is set up for Lyo development as instructed on [Eclipse Setup for Lyo-based Development](./eclipse-setup-for-lyo-based-development.md).
9
+
1.Set up the environment for Lyo development as instructed on [Eclipse Setup for Lyo-based Development](./eclipse-setup-for-lyo-based-development.md).
1. Follow the [Create a Modelling Project](./toolchain-modelling-workshop.md#create-modelling-project) instructions (*Only this particular section*) to create the Eclipse project.
12
-
1. Follow the [Adapter Interface](./toolchain-modelling-workshop.md#adaptor-interface-view) instructions (*Only this particular section*) to create a single Adaptor Interface in the model. You do not need to create any additional elements, such as a Service Provider Catalog, Service Provider, etc. Just make sure you set the generation settings as expected.
13
-
1. Follow the [Generate Lyo Java code](./toolchain-modelling-workshop.md#generate-oslc4j-java-code) instructions (*Only this particular section*) to generate your basic project setup.
14
-
1.You are done! But of course, you can proceed with Lyo Designer to model your complete OSLC Server/Client and generate even more of your project code.
12
+
1. Follow the [Adaptor Interface](./toolchain-modelling-workshop.md#adaptor-interface-view) instructions (*Only this particular section*) to create a single Adaptor Interface in the model. Do not create additional elements, such as a Service Provider Catalog, Service Provider, etc. Set the generation settings as expected.
13
+
1. Follow the [Generate Lyo Java code](./toolchain-modelling-workshop.md#generate-oslc4j-java-code) instructions (*Only this particular section*) to generate the basic project setup.
14
+
1.The process is complete! Lyo Designer can be used to model the complete OSLC Server/Client and generate additional project code.
15
15
16
16
## Introduction
17
17
18
-
In the instructions below, we assume the following parameters, which you will need to adjust for your particular project:
18
+
In the instructions below, the following parameters are assumed, which need to be adjusted for the particular project:
19
19
20
-
* Eclipse Project Name: *adaptor-sample-webapp*
21
-
* Base Package Name for Java Classes: *com.sample.adaptor*
20
+
* Eclipse Project Name: `adaptor-sample-webapp`
21
+
* Base Package Name for Java Classes: `com.sample.adaptor`
22
22
23
-
We will here only create the code skeleton. The [Toolchain Modelling Workshop](./toolchain-modelling-workshop.md) can then be used to generate the necessary code to become a fully functional server.
23
+
These instructions create only the code skeleton. The [Toolchain Modelling Workshop](./toolchain-modelling-workshop.md) can then be used to generate the necessary code to become a fully functional server.
24
24
25
25
As a complement when following the instructions below, you can find sample projects under the [Lyo Adaptor Sample Modelling](https://github.com/OSLC/lyo-adaptor-sample-modelling) git repository.
26
26
@@ -41,41 +41,41 @@ Creating the project consists of these steps:
41
41
42
42
## Set up Eclipse
43
43
44
-
Make sure your environment is set up for Lyo development as instructed on [Eclipse Setup for Lyo-based Development](./eclipse-setup-for-lyo-based-development.md).
44
+
Set up the environment for Lyo development as instructed on [Eclipse Setup for Lyo-based Development](./eclipse-setup-for-lyo-based-development.md).
45
45
46
46
## Create a Maven project
47
47
48
48
To create a Maven project from an archetype via Eclipse:
49
49
50
-
1. Select *File -> New -> Other*.
51
-
1. Then select *Maven Project* under *Maven* group.
52
-
1. Leave the *Create a simple project* checkbox unchecked.
53
-
1. Uncheck the *Use default Workspace location* option and point it to the project root.
54
-
1. Press *Next*.
50
+
1. Select **File -> New -> Other**.
51
+
1. Then select **Maven Project** under **Maven** group.
52
+
1. Leave the **Create a simple project** checkbox unchecked.
53
+
1. Uncheck the **Use default Workspace location** option and point it to the project root.
54
+
1. Press **Next**.
55
55
56
56

57
57
58
58
Next, select the `maven-archetype-webapp` archetype:
59
59
60
60

61
61
62
-
Next, fill in the **Group Id**, **Artefact Id**, and the **Package Base**.
62
+
Next, fill in the **Group Id**, **Artifact Id**, and the **Package Base**.
63
63
64
-
* The **Package Base** value (`com.sample.adaptor` on this page) will be used as a base package for your server code.
64
+
* The **Package Base** value (`com.sample.adaptor` on this page) will be used as a base package for the server code.
65
65
66
66

67
67
68
-
You should now have the project in Eclipse and the following folder structure:
68
+
The project is now available in Eclipse with the following folder structure:
We will also use properties to define a common version for Lyo packages:
78
+
Use properties to define a common version for Lyo packages:
79
79
80
80
```xml
81
81
<properties>
@@ -89,9 +89,9 @@ We will also use properties to define a common version for Lyo packages:
89
89
90
90
### (Optional) Add Lyo repositories
91
91
92
-
Lyo release artefacts are on Maven central since 4.0.0 - no action needed from your side.
92
+
Lyo release artefacts are on Maven central since 4.0.0 - no action needed.
93
93
94
-
If you wish to use the latest development snapshots, you will need the following entry:
94
+
If using the latest development snapshots is required, the following entry is needed:
95
95
96
96
```xml
97
97
<repositories>
@@ -111,7 +111,7 @@ If you wish to use the latest development snapshots, you will need the following
111
111
112
112
### SLF4J package dependencies
113
113
114
-
Lyo uses SLF4J for logging, leaving the choice of the actual logging library to use. We will use the simplest option:
114
+
Lyo uses SLF4J for logging, leaving the choice of the actual logging library to use. The simplest option:
115
115
116
116
```xml
117
117
<dependency>
@@ -124,7 +124,7 @@ Lyo uses SLF4J for logging, leaving the choice of the actual logging library to
124
124
125
125
### Servlet dependencies
126
126
127
-
We require Java EE 6 or higher and JSTL:
127
+
Java EE 6 or higher and JSTL are required:
128
128
129
129
```xml
130
130
<dependency>
@@ -146,7 +146,10 @@ Lyo depends on JAX-RS APIs and your application needs to add implementations of
146
146
147
147
#### For Lyo 5.x
148
148
149
-
For Lyo release 5.0.0 and above, you will need to choose a JAX-RS 2.0 implementation. If you are using Jersey, you should use version 2.35. *Note that starting with Jersey 2.26, HK2 is not bundled with the core artefacts (see the [Jersey migration guide](https://eclipse-ee4j.github.io/jersey.github.io/documentation/2.35/user-guide.html#mig-2.26)).*
149
+
For Lyo release 5.0.0 and above, choose a JAX-RS 2.0 implementation. If using Jersey, use version 2.35.
150
+
151
+
!!! note
152
+
Starting with Jersey 2.26, HK2 is not bundled with the core artefacts (see the [Jersey migration guide](https://eclipse-ee4j.github.io/jersey.github.io/documentation/2.35/user-guide.html#mig-2.26)).
150
153
151
154
```xml
152
155
<dependency>
@@ -211,7 +214,7 @@ If your server needs to support OAuth, include the following:
211
214
</dependency>
212
215
```
213
216
214
-
To support OAuth, you will need to add the following JAX-RS Providers to your Application (the `javax.ws.rs.core.Application` subclass):
217
+
To support OAuth, add the following JAX-RS Providers to the Application (the `javax.ws.rs.core.Application` subclass):
@@ -233,14 +236,14 @@ If your OSLC server also needs to consume resources from another server, a depen
233
236
234
237
### Configure the Embedded Jetty server for quick debugging
235
238
236
-
Finally, you should use an embedded servlet container during the debugging to simplify the development process.
239
+
Finally, use an embedded servlet container during the debugging to simplify the development process.
237
240
238
241
Replace the existing `<build>` entry with the Jetty configuration below, using the following customisations:
239
242
240
-
**adaptor-sample* is the context path that can be the same as your eclipse project name (or something more appropriate)
241
-
**8080* is the port number you want to run the services on.
243
+
*`adaptor-sample` is the context path that can be the same as the eclipse project name (or something more appropriate)
244
+
*`8080` is the port number to run the services on.
242
245
243
-
This will make your server available under the path http://localhost:8080/adaptor-sample.
246
+
This will make the server available under the path http://localhost:8080/adaptor-sample.
244
247
245
248
```xml
246
249
<build>
@@ -273,9 +276,9 @@ This will make your server available under the path http://localhost:8080/adapto
273
276
274
277
Modify the parameters in `/src/main/webapp/WEB-INF/web.xml` according to the template below.
275
278
276
-
**Adaptor Sample* could be the same as your eclipse project name (or something more appropriate).
277
-
**com.sample.adaptor* should be the same as the base package name for your project.
278
-
**8080* should match the port number specified in the POM file for Jetty configuration.
279
+
*`Adaptor Sample` could be the same as the eclipse project name (or something more appropriate).
280
+
*`com.sample.adaptor` should be the same as the base package name for the project.
281
+
*`8080` should match the port number specified in the POM file for Jetty configuration.
279
282
280
283
```xml
281
284
<?xml version="1.0" encoding="UTF-8"?>
@@ -317,11 +320,11 @@ The instructions below are based on [Swagger Core JAX RS Project Setup 1.5.X](ht
317
320
318
321
### Add OpenApi/Swagger Maven dependencies
319
322
320
-
Add the following Swagger dependency to your maven pom.xml file.
323
+
Add the following Swagger dependency to the maven pom.xml file.
321
324
322
325
#### For Lyo 5.0.0
323
326
324
-
Assuming you are adopting the Jersey implementation with the version specified above.
327
+
Assuming the Jersey implementation is adopted with the version specified above.
325
328
326
329
```xml
327
330
<dependency>
@@ -343,11 +346,11 @@ Assuming you are adopting the Jersey implementation with the version specified a
343
346
</dependency>
344
347
```
345
348
346
-
### Co-host Swagger UI with your server
349
+
### Co-host Swagger UI with the server
347
350
348
-
The following steps provide the end-user with an interactive console to the OSLC services, by integrating [Swagger UI](https://swagger.io/swagger-ui/) with your OSLC server.
351
+
The following steps provide the end-user with an interactive console to the OSLC services, by integrating [Swagger UI](https://swagger.io/swagger-ui/) with the OSLC server.
349
352
350
-
Add the following plugins to the existing `<plugins>` entry of your`pom.xml` file. These plugins download and extract the necessary `Swagger UI` files from [Swagger UI GitHub project](https://github.com/swagger-api/swagger-ui) onto your project:
353
+
Add the following plugins to the existing `<plugins>` entry of the`pom.xml` file. These plugins download and extract the necessary `Swagger UI` files from [Swagger UI GitHub project](https://github.com/swagger-api/swagger-ui) onto the project:
351
354
352
355
```xml
353
356
<build>
@@ -419,9 +422,9 @@ public class Application extends javax.ws.rs.core.Application {
419
422
420
423
### ConfigureSwagger's Servlet in the web.xml
421
424
422
-
Add the following to your web.xml:
425
+
Add the following to the `web.xml`:
423
426
424
-
* *swagger.api.basepath* depends on your particular settings, as instructed above.
427
+
* `swagger.api.basepath` depends on the particular settings, as instructed above.
425
428
426
429
```xml
427
430
<servlet>
@@ -446,7 +449,7 @@ The OpenApi documentation can be achieved with as little as adding `@Api` to eac
446
449
#### `@Api`
447
450
448
451
1. For each REST service (i.e. OSLC Service), simply add the `@Api` annotation.
449
-
1. (*OPTIONAL*) add the *value* and *description* details. The *value* is used to group the REST methods into common categories, helping in the structuring of the methods in the documentation. You can give it the same value as that of the @Path annotation, collecting all REST methods for the same service together.
452
+
1. (*OPTIONAL*) add the `value` and `description` details. The `value` is used to group the REST methods into common categories, helping in the structuring of the methods in the documentation. You can give it the same value as that of the @Path annotation, collecting all REST methods for the same service together.
450
453
451
454
```java
452
455
@Api(value = "requirements", description = "OSLC service for resources of type" + "Requirement")
@@ -464,7 +467,7 @@ For each REST method, add the `@ApiOperation` Swagger annotation.
464
467
!!! example
465
468
If your OSLC Service defines separate Java methods to handle HTML and RDF/XML content types for the same path and HTTP method, OpenApi will only recognise one of these methods and ignore the other.
466
469
467
-
**Workaround:** Annotate ALL methods that are identified as unique with the complete list of media types in the *produces* property of the `@ApiOperation` annotation. This way, the generated documentation correctly indicates the existence of all methods.
470
+
**Workaround:** Annotate ALL methods that are identified as unique with the complete list of media types in the `produces` property of the `@ApiOperation` annotation. This way, the generated documentation correctly indicates the existence of all methods.
468
471
469
472
```java
470
473
@GET
@@ -490,7 +493,7 @@ public class Requirement
490
493
491
494
### Access the Swagger UI interactive console
492
495
493
-
Before you can access the [Swagger UI](https://swagger.io/swagger-ui/) interactive console for the first time, edit the `swagger-ui/index.html` file, replacing the url `http://petstore.swagger.io/v2/swagger.json` with the url of your own yaml file `http://localhost:8080/adaptor-sample/services/swagger.yaml`.
496
+
Before accessing the [Swagger UI](https://swagger.io/swagger-ui/) interactive console for the first time, edit the `swagger-ui/index.html` file, replacing the url `http://petstore.swagger.io/v2/swagger.json` with the URL of the YAML file `http://localhost:8080/adaptor-sample/services/swagger.yaml`.
494
497
495
498
The generated interactive API console can be accessed via:
496
499
@@ -562,7 +565,7 @@ public class Application extends javax.ws.rs.core.Application {
562
565
}
563
566
```
564
567
565
-
Define the `InmemPagedTrsSingleton` singleton class. You will need to complete the code example below, with:
568
+
Define the `InmemPagedTrsSingleton` singleton class. Complete the code example below, with:
566
569
* the code that populates `uris` with the initial set of resources to be managed by `InmemPagedTrs`;
567
570
* the desired `basePageLimit` and `changelogPageLimit` parameters.
568
571
@@ -618,18 +621,16 @@ The application is now ready to respond to REST requests from a TRS Client. Once
618
621
619
622
### Update the TRS data set
620
623
621
-
To update the set of OSLC resources that form the TRS Base and ChangeLog, simply call the following methods in your code:
624
+
To update the set of OSLC resources that form the TRS Base and ChangeLog, call the following methods in the code:
Once the server is developed, you can run it by selecting *Run As ➞ Maven build ...* from the project's context menu, and setting the goal to `clean jetty:run-war`.
630
-
631
-
You can now access your server from http://localhost:8080/adaptor-sample.
632
+
Once the server is developed, run it by selecting **Run As ➞ Maven build ...** from the project's context menu, and setting the goal to `clean jetty:run-war`.
632
633
633
-
**adaptor-sample*and *8080* will depend on your particular settings, as instructed above.
634
+
Access the server from [http://localhost:8080/adaptor-sample](http://localhost:8080/adaptor-sample) (`adaptor-sample` and `8080` will depend on the particular settings, as instructed above).
634
635
635
-
>**ProTip:**Ifyou get the error *Project configuration is not up-to-date with pom.xml*, simply right click on the eclipse project and select *Maven ➞ UpdateProject*...
636
+
>**ProTip:**If the error `Project configuration is not up-to-date with pom.xml` occurs, right click on the eclipse project and select **Maven ➞ UpdateProject**...
0 commit comments