Skip to content

Commit ec89eff

Browse files
author
anirtek
committed
Swagger-integration-post
1 parent 44a9a35 commit ec89eff

8 files changed

+127
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ _site*
22
.sass-cache
33
.jekyll-metadata
44
*backup/
5+
.vscode/

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ title: Aniruddha's Waste Of Time
22
description: My Personal Stack Problems And Concepts
33
author: Aniruddha Tekade
44
github: https://github.com/anirtek
5-
about: CS Grad at Binghamton University. Currently doing more in Data Science, focused in Python and Java.
5+
about: Distributed Systems and AI Engineer
66
disqus_shortname: stackproblems
77
google_analytics: UA-XXXXXXXX-Y
88
avatar_url: /static/img/alpha.png

_posts/2018-07-14-pojo-explained.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: post
33
title: "POJO explained in details"
44
data: 2018-07-14 02:02:56
5-
categories: [java, j2ee, backend]
5+
categories: [java, backend]
66
---
77

88
### What is the concept of pojo?
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
layout: post
3+
title: "Hooking up OpenAPI with Jetty Server"
4+
data: 2021-06-12 06:038:56
5+
categories: [java, jetty, swagger, openapi]
6+
---
7+
8+
### Background
9+
10+
Jetty 11.X is released now and has deprecated its support for `javax` namespace required for the development of API. Instead, it has started supporting `jakarta` namespace now and this changes the game entirely. Because when you need to annotate your API, we `import javax.ws.rs.*` packages which is now on will be `import jakarta.ws.rs.*`. Nonetheless, swagger (OpenAPI) documentation that used to seamlessly integrate with core java APIs now has an additional dependency whether is a maven or gradle based project. Lets get started into the detailed process of how the new integration is done.
11+
12+
### What is Jetty?
13+
14+
The Ecplise Jetty Project provides a web server and servlet container, additionally providing support for HTTP/2, WebSocket, OSGi, JMX, JNDI, JAAS and many other integrations. These components are open source and are freely available for commercial use and distribution.
15+
16+
Jetty is used in a wide variety of projects and products, both in development and production. Jetty has long been loved by developers due to its long history of being easily embedded in devices, tools, frameworks, application servers, and modern cloud services.
17+
18+
Biggest advantage of using Jetty is that Jetty has been designed to have a small memory foot print. This is a critical basis for good performance and scalability. The less memory the server uses, the more memory is available for the application and/or more instances of the server can be run on virtual hardware. As such Jetty is very cloud friendly.
19+
20+
### What is Jersey?
21+
22+
23+
24+
### What is Swagger/OpenAPI?
25+
26+
27+
### What steps it should follow?
28+
29+
The rules are very simple and as follows:
30+
1. Create a jetty server
31+
2. Intercept API using Jersey
32+
3. Add OpenAPI servlet into Jetty Server
33+
4. Export API docs
34+
5. The class should not extend from any other Java class as in
35+
36+
### STEP 1. Create Jetty Server
37+
38+
```java
39+
```
40+
41+
### STEP 2. Intercept API using Jersey
42+
43+
```java
44+
```
45+
46+
### STEP 3. Add OpenAPI servlet into Jetty Server
47+
48+
```java
49+
```
50+
51+
Build.gradle should have dependencies like this -
52+
53+
```gradle
54+
```
55+
56+
### STEP 4. Export API docs
57+
```java
58+
```
59+
60+
```java
61+
public class EmployeeRecord {
62+
/*the private data members inside a class that is public*/
63+
private int empId;
64+
private String empName;
65+
private String empAddr;
66+
private int empSal;
67+
public int getEmpId() {
68+
return empId;
69+
}
70+
71+
public void setEmpId(int idIn) {
72+
empId = idIn;
73+
}
74+
public String getEmpName() {
75+
return empName;
76+
}
77+
public void setEmpName(String nameIn) {
78+
empName = nameIn;
79+
}
80+
81+
public String getEmpAddr() {
82+
return empAddr;
83+
}
84+
85+
public void setEmpAddr(String addrIn) {
86+
empAddr = addrIn;
87+
}
88+
89+
public int getEmpSal() {
90+
empSal;
91+
}
92+
93+
public void setEmpSal(int salaryIn) {
94+
empSal = salaryIn;
95+
}
96+
}
97+
```
98+
### Summary
99+
100+
In J2EE environment, POJO based programming model helps a lot to achieve the functionalities of dependency injection and inversion of control. Also this type of practice helps writing modules that are high cohesive and low coupled thereby making the project robust. Spring, one of the most popular Java framework in the industry always promotes the POJO based development.

category/jersey.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
layout: posts_by_category
3+
categories: jersey
4+
title: Jersey
5+
permlink: /category/jersey
6+
---

category/jetty.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
layout: posts_by_category
3+
categories: jetty
4+
title: Jetty
5+
permlink: /category/jetty
6+
---

category/openapi.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
layout: posts_by_category
3+
categories: openapi
4+
title: OpenAPI
5+
permlink: /category/openapi
6+
---

category/swagger.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
layout: posts_by_category
3+
categories: swagger
4+
title: Swagger
5+
permlink: /category/swagger
6+
---

0 commit comments

Comments
 (0)