DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

The Latest Software Design and Architecture Topics

article thumbnail
5 DevOps Tools To Add to Your Stack in 2022
DevOps tools emerge each year to improve existing workflows or introduce new functionality. Here are five DevOps tools you can add to your tech stack in 2022.
February 18, 2022
by Ryan Kh
· 15,724 Views · 7 Likes
article thumbnail
Kubernetes Auditing: Which IAM User Deleted a Namespace?
Learn how to collect audit logs that are passed through the Kubernetes API server to IBM Log Analysis to check who initiated a request and when they did so.
February 17, 2022
by Vidyasagar (Sarath Chandra) Machupalli FBCS DZone Core CORE
· 7,862 Views · 4 Likes
article thumbnail
How to Use Embedded Hazelcast on Kubernetes
Take a look at how you can create an embedded instance of Hazelcast so it can scale simultaneously with your Kubernetes clusters.
Updated February 17, 2022
by Rafał Leszko
· 23,892 Views · 6 Likes
article thumbnail
Top 10 Ways To Secure Containers
In this article, we'll discuss container security best practices that we can follow and implement to reduce the security risks in containerized workloads.
February 17, 2022
by Anjul Sahu
· 6,150 Views · 3 Likes
article thumbnail
Redshift vs. Snowflake: The Definitive Guide
Discover the key differences between Redshift and Snowflake around architecture, pricing, security, compliance, data support, administration, data protection, performance, etc...
February 16, 2022
by Luke Kline
· 5,074 Views · 3 Likes
article thumbnail
Spring Boot Secured By Let's Encrypt
In this post, learn how to use the Let's Encrypt tool with Spring Boot to generate HTTPS certificates and automatically renew them.
Updated February 16, 2022
by Emad Heydari Beni
· 134,101 Views · 24 Likes
article thumbnail
Getting Started With Apache Cassandra
In this hands-on primer on the powerful open-source NoSQL database Apache Cassandra, our discussion includes the CAP theorem and how to structure data.
February 16, 2022
by David Jones-Gilardi
· 6,889 Views · 3 Likes
article thumbnail
Strict Validations in Mulesoft APIkit Router
This article will help you in your understanding of the functionality of Query Parameters and Headers Strict Validations in the MuleSoft APIkit Router.
February 16, 2022
by Abhishek Bathwal
· 9,692 Views · 2 Likes
article thumbnail
Using Travis CI for Deploying Mulesoft Applications to Cloudhub
This tutorial explains what Travis CI is and how you can use it to deploy Mulesoft applications to Cloudhub. Read below to find out more!
February 16, 2022
by Kuldeep Rana
· 10,532 Views · 2 Likes
article thumbnail
Win Your War Against Hackers and Secure Your Network
With hackers becoming more active every year, it's more important than ever to insure proper security practices in your organization. Read on for some practical tips.
Updated February 16, 2022
by Giridhara Raam
· 8,031 Views · 5 Likes
article thumbnail
What Is BizTalk Server?
A developer discusses what makes BizTalk server a great middleware for integration, and how it works to receive, orchestrate, and send messages.
Updated February 16, 2022
by Kamlesh Kumar
· 22,580 Views · 8 Likes
article thumbnail
Understanding OpenJDK and Why You Should Use It
In this article, we will try to answer this question by reviewing the process of constant upgrading of OpenJDK and its open-source approach to development.
February 16, 2022
by Dmitry Chuyko
· 4,912 Views · 4 Likes
article thumbnail
Using Azure Load Balancer With CockroachDB
Today, we'll set up Azure Load Balancer service with CockroachDB. Our docs have a note on it but I'll attempt to fill in the blanks of setting up ALB.
February 16, 2022
by Artem Ervits DZone Core CORE
· 7,087 Views · 3 Likes
article thumbnail
Microservice: Creating JPA Application Using Jakarta Persistence API in Payara Micro
In this blog, we will discuss how your Java microservice application can connect to and interact with a relational database through the Jakarta Persistence API.
Updated February 16, 2022
by BUHAKE SINDI DZone Core CORE
· 5,493 Views · 4 Likes
article thumbnail
Introduction to Couchbase for Oracle Developers and Experts: Part 1- Architecture
In this article, we'll compare and contrast Oracle with Couchbase from a SQL point of view. You'll get a good feel for the architecture and capabilities of Couchbase.
Updated February 16, 2022
by Keshav Murthy DZone Core CORE
· 10,913 Views · 6 Likes
article thumbnail
Intelligent Data as a Service (iDaaS) - Example Data Insights
In our previous article from this series we talked about the example iDaaS data architecture specifically integration for HL7 and FHIR healthcare standards. ...
February 16, 2022
by Eric D. Schabell DZone Core CORE
· 4,644 Views · 2 Likes
article thumbnail
Microservice API Patterns: A Language for API Design
Axway Catalyst Erik Wilde describes how Microservice API Patterns can help quickly come up with API designs that solve problems.
February 15, 2022
by Erik Wilde
· 4,936 Views · 5 Likes
article thumbnail
Email Security Tips for Outlook: How to Send a Secure Email in Outlook
Here are two methods to send a secure email in Outlook. It includes S/MIME and OME techniques, which are essential for email security in Outlook.
February 15, 2022
by Aryan Malhotra
· 2,211 Views · 5 Likes
article thumbnail
Top 9 Google Cloud Platform Certification Courses for 2022
Become Google Cloud certified and advance your career with this curated list of the 9 most in-demand GCP Certification courses.
February 15, 2022
by Chase Bolt
· 4,338 Views · 2 Likes
article thumbnail
Generate Server Code Using OpenAPI Generator
In this blog, you will learn how to generate server code using the OpenAPI Generator based on an OpenAPI specification. The code will be generated for a Spring Boot Application, but OpenAPI supports many other languages which can be used. 1. Introduction In November I attended JFall, the largest one day Java conference in the Netherlands organized by NLJUG. You can read here my impressions of that day. One of the talks I attended described how to design your API first and how to generate code by using the OpenAPI Generator. The talk is ‘API-First: from design to development’ from Vasco Veloso. You can watch it on YouTube. The talk inspired me to take a closer look to the OpenAPI generator and how it can be used during development. OpenAPI Generator can generate code based on an OpenAPI yaml specification. Many languages are supported and the complete documentation of the library can be found here. In this blog, you will create a basic OpenAPI yaml specification and you will use it to generate your server side code for a Spring Boot application. The code used in this blog is available at GitHub. 2. Create OpenAPI spec First thing to do is to design the OpenAPI specification for your application. You are going to design a Customer API. The API allows you to create a Customer and to retrieve the Customer based on its ID. A real life API will be more elaborate, but let’s keep it simple. An easy way to design the API is by using the Swagger Editor. This will give you immediate feedback whether your specification has errors and it generates the Swagger documentation on the fly. More information about the OpenAPI specification itself, is available in the official documentation. The header of the OpenAPI specification contains some metadata about the API, like title, version, the server the API is running. Tags can be used to group the resources, which will give you more overview. YAML openapi: "3.0.2" info: title: API Customer version: "1.0" servers: - url: https://localhost:8080 tags: - name: Customer description: Customer specific data. The paths section contains the specification for the resources. The first resource you define is the one to create a Customer which will be done by means of a POST containing a JSON body. The operationId will be used by the generator to create the method name for this resource. For simplicity, only a successful response is considered. The schemas refer to the JSON body, they will be covered later in this section. YAML /customer: post: tags: - Customer summary: Create Customer operationId: createCustomer requestBody: content: application/json: schema: $ref: '#/components/schemas/Customer' responses: '200': description: OK content: 'application/json': schema: $ref: '#/components/schemas/CustomerFullData' The second resource will allow you to retrieve a Customer. This resource also takes a path parameter containing the customerId to be retrieved. When the ID does not exist, a NOT FOUND response will be returned. YAML /customer/{customerId}: get: tags: - Customer summary: Retrieve Customer operationId: getCustomer parameters: - name: customerId in: path required: true schema: type: integer format: int64 responses: '200': description: OK content: 'application/json': schema: $ref: '#/components/schemas/CustomerFullData' '404': description: NOT FOUND And finally, in the components section, the used schemas are defined. The Customer schema and the CustomerFullData schemas share all properties, except for the ID. For better maintainability, the allOf property can be used. YAML components: schemas: Customer: type: object properties: firstName: type: string description: First name of the customer lastName: type: string description: Last name of the customer CustomerFullData: allOf: - $ref: '#/components/schemas/Customer' - type: object properties: customerId: type: integer description: The ID of the customer format: int64 description: Full data of the customer. The OpenAPI specification for the application is now complete. 3. Create Spring Boot Application For creating the Spring Boot application, you navigate to start.spring.io, choose the latest stable Spring Boot version, Java 17 and add the Spring Web dependency. Download the generated project and open it into your favourite IDE. Add the OpenAPI specification to the src/main/resources directory with name customer.yml. You will be using the Open API Generator Maven plugin, so add the plugin to the build section of the pom file. Use spring as generatorName since you are using a Spring Boot application and set the path to the customer.yml file with the inputSpec property. XML org.openapitools openapi-generator-maven-plugin 5.3.0 generate ${project.basedir}/src/main/resources/customer.yml spring Execute the following command in order to generate the code: Shell $ mvn clean compile The compilation fails with the following errors: Shell package io.swagger.annotations does not exist package io.swagger.annotations does not exist package org.openapitools.jackson.nullable does not exist cannot find symbol In order to solve these problems, you add the following dependencies to the pom file: XML io.swagger swagger-annotations 1.6.3 javax.validation validation-api 2.0.1.Final org.openapitools jackson-databind-nullable 0.2.1 Running the compilation again, results in the following errors: Shell package springfox.documentation.builders does not exist package springfox.documentation.builders does not exist package springfox.documentation.service does not exist package springfox.documentation.service does not exist package springfox.documentation.spi does not exist package springfox.documentation.spring.web.paths does not exist package springfox.documentation.spring.web.paths does not exist package springfox.documentation.spring.web.plugins does not exist package springfox.documentation.swagger2.annotations does not exist Adding the following dependencies to the pom file solves these errors: XML io.springfox springfox-swagger-ui 2.6.0 io.springfox springfox-swagger2 2.6.0 Take a closer look to what has been generated. Navigate to the directory target/generated-sources/open-api where the generated files can be found. The following directories contain the generated files: src/main/org/openapitools/api: an interface for a Spring Controller but also an implementation; src/main/org/openapitools/configuration: a Controller for the Swagger documentation; src/main/org/openapitools/model: The model for the API based on the API specification; src/main/org/openapitools: a OpenAPI2SpringBoot class which is a SpringBootApplication. When you want to run the Spring Boot application, you will run into an error since Spring Boot can not determine which SpringBootApplication it needs to run: Shell $ mvn spring-boot:run The resulting error is: Shell Unable to find a single main class from the following candidates [org.openapitools.OpenAPI2SpringBoot, com.mydeveloperplanet.myopenapiplanet.MyOpenApiPlanetApplication] By default a lot of code is generated, maybe more than you will need. How to tweak the configuration will be covered in the next paragraph. 4. Configure OpenAPI plugin Besides all the options documented in the Maven section of the OpenAPI plugin, many extra options are available which can be configured in the configOptions section of the configuration section of the OpenAPI plugin. The available options can be revealed by adding the configHelp property to the configuration section. XML ${project.basedir}/src/main/resources/customer.yml spring true From this list, you will use the interfaceOnly property, which will only generate the interface for the Controller and the API model. XML ... true At this point, you can also remove the springfox dependencies which were added earlier. These are not needed anymore. Another thing what can be seen from the generated code, is that the code is generated in the package org.openapitools. You probably want this to be your own package name and this can be configured with some basic properties. With property packageName you can set the default package name. It is however also necessary to set the properties apiPackage and modelPackage, otherwise these will still be generated in the org.openapitools package. Add the following to the configuration section. XML .... com.mydeveloperplanet.myopenapiplanet com.mydeveloperplanet.myopenapiplanet.api com.mydeveloperplanet.myopenapiplanet.model .... The generated interface for the Controller looks as follows: Java @javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-01-15T12:51:43.809971036+01:00[Europe/Amsterdam]") @Validated @Api(value = "customer", description = "the customer API") public interface CustomerApi { default Optional getRequest() { return Optional.empty(); } /** * POST /customer : Create Customer * * @param customer (optional) * @return OK (status code 200) */ @ApiOperation(value = "Create Customer", nickname = "createCustomer", notes = "", response = CustomerFullData.class, tags={ "Customer", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = CustomerFullData.class) }) @RequestMapping( method = RequestMethod.POST, value = "/customer", produces = { "application/json" }, consumes = { "application/json" } ) default ResponseEntity createCustomer(@ApiParam(value = "") @Valid @RequestBody(required = false) Customer customer) { getRequest().ifPresent(request -> { for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "null"; ApiUtil.setExampleResponse(request, "application/json", exampleString); break; } } }); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } ... During the generation, a warning is raised because of the usage of the allOf property. However, the generated code looks ok. Shell [WARNING] allOf with multiple schemas defined. Using only the first one: Customer 5. Use Generated Code For the application, you first create a Customer domain class in package domain. Java public class Customer { private Long customerId; private String firstName; private String lastName; // Getters and setters } Create a CustomerController which implements the generated CustomerApi interface. Creating the customer is a basic implementation where you add the customer to a HashMap: a calculated index is the key, the domain Customer object is the value. In a real application you will save the Customer to a database. Retrieving the Customer first checks whether the requested ID exists in the HashMap. When the ID is found, the Customer domain object is converted to the Customer API model object and returned to the requester. When the ID is not found, a NOT FOUND response is returned. Java @RestController public class CustomerController implements CustomerApi { private final HashMap customers = new HashMap<>(); private Long index = 0L; @Override public ResponseEntity createCustomer(Customer apiCustomer) { com.mydeveloperplanet.myopenapiplanet.domain.Customer customer = new com.mydeveloperplanet.myopenapiplanet.domain.Customer(); customer.setCustomerId(index); customer.setFirstName(apiCustomer.getFirstName()); customer.setLastName(apiCustomer.getLastName()); customers.put(index, customer); index++; return ResponseEntity.ok(domainToApi(customer)); } @Override public ResponseEntity getCustomer(Long customerId) { if (customers.containsKey(customerId)) { return ResponseEntity.ok(domainToApi(customers.get(customerId))); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } private CustomerFullData domainToApi(com.mydeveloperplanet.myopenapiplanet.domain.Customer customer) { CustomerFullData cfd = new CustomerFullData(); cfd.setCustomerId(customer.getCustomerId()); cfd.setFirstName(customer.getFirstName()); cfd.setLastName(customer.getLastName()); return cfd; } } Run the Spring Boot application: Shell $ mvn spring-boot:run Add a Customer Foo Bar: Shell $ curl -i -X 'POST' \ > 'http://localhost:8080/customer' \ > -H 'accept: application/json' \ > -H 'Content-Type: application/json' \ > -d '{ > "firstName": "Foo", > "lastName": "Bar" > }' HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked Date: Sat, 15 Jan 2022 11:42:47 GMT {"firstName":"Foo","lastName":"Bar","customerId":0} Add a Customer John Doe: Shell $ curl -i -X 'POST' \ > 'http://localhost:8080/customer' \ > -H 'accept: application/json' \ > -H 'Content-Type: application/json' \ > -d '{ > "firstName": "John", > "lastName": "Doe" > }' HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked Date: Sat, 15 Jan 2022 11:43:11 GMT {"firstName":"John","lastName":"Doe","customerId":1} Verify whether a Customer can be retrieved by ID: Shell $ curl -i http://localhost:8080/customer/1 HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked Date: Sat, 15 Jan 2022 11:45:21 GMT {"firstName":"John","lastName":"Doe","customerId":1} Verify whether a NOT FOUND is returned for a non-existing Customer: Shell $ curl -i http://localhost:8080/customer/2 HTTP/1.1 404 Content-Length: 0 Date: Sat, 15 Jan 2022 11:46:18 GMT 6. Add OpenAPI Documentation Adding the dependency springdoc-openapi-ui will publish the OpenAPI documentation to an endpoint. For more information see the springdoc documentation. XML org.springdoc springdoc-openapi-ui 1.5.12 Navigate into your browser to http://localhost:8080/swagger-ui.html and the OpenAPI documentation is displayed and the OpenAPI yaml specification can be downloaded here. When you take a close look at the documentation, you will notice that it differs from the documentation shown in the Swagger Editor. The springdoc dependency will by default generate the documentation from the source code and will use this generated documentation. How to configure springdoc in order that it uses the customer.yml file? First, you need to move the customer.yml file to directory src/main/resources/static/customer.yml. This also means that you need to change the Open API generator configuration in the pom. XML ${project.basedir}/src/main/resources/static/customer.yml ... Add the following property to the application.properties file. Properties files springdoc.swagger-ui.url=/customer.yml The URL now shows the API as defined in the customer.yml you created. 7. Conclusion First designing your API is a good approach and forces you to think more deeply about your API design on beforehand. The OpenAPI Generator plugin generates an interface and model for your Controller and this way, code will be in line with the OpenAPI specification you created.
February 15, 2022
by Gunter Rotsaert DZone Core CORE
· 14,077 Views · 2 Likes
  • Previous
  • ...
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • ...
  • Next

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: