Generator-jhipster: Unable save data into Micro Service using Gateway UI

Created on 19 Jan 2018  ·  13Comments  ·  Source: jhipster/generator-jhipster

I set up my micro-services application with one microservice and one gateway. I generated micro service entities using jhipster import-jdl books.jh and entities UI in gateway. I used below JDL files to generate UI for entities in the gateway, and entities server code in microservices. I was looking at docs and issues raised by other people, I couldn't find proper to documentation to connect Micro Service entities with UI for those entities in the gateway through JDL import (should be able to specify the path of micro service similar to command line process). Correct me if my syntax is incorrect. Everything went well, when open I entity page and try to save the object, it did not save it. I got following error on console.

POST http://localhost:8080/api/addresses 404 error (not found)

Books Micro Service JDL file:

entity Address
{
    streetName  String required,
    apartmentOrHouseNumber  String,
    city    String  required,
    zipcode Long    required,
    state   String,
    country String
}

entity BookCoverType
{
    coverType   String  required
}


entity Author
{
    firstName   String  required,
    lastName    String  required,
    middleName  String,
}

entity Book 
{
    bookName String required,
    bookTitle String    required,
    numberOfPages Integer   required,
}






relationship OneToOne 
{
    //Book{bookCoverType(coverType)} to BookCoverType
    Author{address(streetName)} to Address
}

relationship OneToMany 
{
    BookCoverType{book(bookTitle)} to Book
    Book{author(firstName)} to Author
    Author{book(bookTitle)} to Book

}


paginate Book with pagination
paginate Author with pagination

BookStore gateway JDL file:
entity Address
{
    streetName  String required,
    apartmentOrHouseNumber  String,
    city    String  required,
    zipcode Long    required,
    state   String,
    country String
}

entity BookCoverType
{
    coverType   String  required
}


entity Author
{
    firstName   String  required,
    lastName    String  required,
    middleName  String,
}

entity Book 
{
    bookName String required,
    bookTitle String    required,
    numberOfPages Integer   required,
}




relationship OneToOne 
{
    //Book{bookCoverType(coverType)} to BookCoverType
    Author{address(streetName)} to Address
}

relationship OneToMany 
{
    BookCoverType{book(bookTitle)} to Book
    Book{author(firstName)} to Author
    Author{book(bookTitle)} to Book

}

skipServer *
microservice * with books

paginate Book with pagination
paginate Author with pagination

Address.json
{
    "fluentMethods": true,
    "relationships": [],
    "fields": [
        {
            "fieldName": "streetName",
            "fieldType": "String",
            "fieldValidateRules": [
                "required"
            ]
        },
        {
            "fieldName": "apartmentOrHouseNumber",
            "fieldType": "String"
        },
        {
            "fieldName": "city",
            "fieldType": "String",
            "fieldValidateRules": [
                "required"
            ]
        },
        {
            "fieldName": "zipcode",
            "fieldType": "Long",
            "fieldValidateRules": [
                "required"
            ]
        },
        {
            "fieldName": "state",
            "fieldType": "String"
        },
        {
            "fieldName": "country",
            "fieldType": "String"
        }
    ],
    "changelogDate": "20180119060434",
    "entityTableName": "address",
    "dto": "no",
    "pagination": "no",
    "service": "no",
    "jpaMetamodelFiltering": false,
    "skipServer": true
}
##### **JHipster Version(s)**
[email protected] /Users/pjadda/kubernetesapps/bookstore
└── [email protected] 

##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.bookstore"
    },
    "jhipsterVersion": "4.13.3",
    "baseName": "bookstore",
    "packageName": "com.bookstore",
    "packageFolder": "com/bookstore",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "hazelcast",
    "enableHibernateCache": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": true,
    "jwtSecretKey": "replaced-by-jhipster-info",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "gateway",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory


JDL entity definitions

entity Address (address) {
  streetName String required,
  apartmentOrHouseNumber String,
  city String required,
  zipcode Long required,
  state String,
  country String
}
entity BookCoverType (book_cover_type) {
  coverType String required
}
entity Author (author) {
  firstName String required,
  lastName String required,
  middleName String
}
entity Book (book) {
  bookName String required,
  bookTitle String required,
  numberOfPages Integer required
}

relationship OneToOne {
  Author{address(streetName)} to Address
}
relationship OneToMany {
  Book{author} to Author{book},
  BookCoverType{book} to Book{bookCoverType},
  Author{book} to Book{author}
}

paginate Author, Book with pagination

Environment and Tools

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

git version 2.13.1

node: v8.9.3

npm: 5.6.0

bower: 1.8.2

yarn: 1.3.2

Docker version 17.12.0-ce, build c97c6d6

docker-compose version 1.18.0, build 8dd22a9

Browsers and Operating System
macOS High Sierra, Chrome browser

  • [x] Checking this box is mandatory (this is just to show you read everything)
area

Most helpful comment

import-jdl should work as well, but its a been a while since I tested it. But you should be using skipSever option and no need to have 2 JDL files, you should use the below JDL and run the same on both microservice and gateway

entity Address
{
    streetName  String required,
    apartmentOrHouseNumber  String,
    city    String  required,
    zipcode Long    required,
    state   String,
    country String
}

entity BookCoverType
{
    coverType   String  required
}


entity Author
{
    firstName   String  required,
    lastName    String  required,
    middleName  String,
}

entity Book 
{
    bookName String required,
    bookTitle String    required,
    numberOfPages Integer   required,
}




relationship OneToOne 
{
    //Book{bookCoverType(coverType)} to BookCoverType
    Author{address(streetName)} to Address
}

relationship OneToMany 
{
    BookCoverType{book(bookTitle)} to Book
    Book{author(firstName)} to Author
    Author{book(bookTitle)} to Book

}

microservice * with books

paginate Book with pagination
paginate Author with pagination

@MathieuAA may be we should create a sample microservice JDL with a gateway and 2 microservices, WDYT?

All 13 comments

I reformatted your text as it was a pain to read, next time please paste jhipster info output as is.

I'm not sure what you did exactly but it seems to me that you did not found the doc about generating entities in a microservices architecture. You don't need to use skip server.

@gmarziou I was able to generate entities. I was trying to generate UI for those entities in the gateway and perform CRUD operations.

My point is about what you did in gateway which looks strange to me but I might have misunderstood what you did exactly. Please list which command you ran on gateway.

@gmarziou Sorry for misunderstanding. Please look at the modified description. I used
$jhipster import-jdl books.jh in gateway folder.

Well the doc says to run the entity generator so jhipster entity <Entity name>.
I have never tried to run the jdl import generator in gateway maybe it works but from your 404 error it's clear that URL lacks the service prefix.
Also I don't understand how this process with JDL would work with many services, doc needs to be clarified by someone who knows about JDL.

import-jdl should work as well, but its a been a while since I tested it. But you should be using skipSever option and no need to have 2 JDL files, you should use the below JDL and run the same on both microservice and gateway

entity Address
{
    streetName  String required,
    apartmentOrHouseNumber  String,
    city    String  required,
    zipcode Long    required,
    state   String,
    country String
}

entity BookCoverType
{
    coverType   String  required
}


entity Author
{
    firstName   String  required,
    lastName    String  required,
    middleName  String,
}

entity Book 
{
    bookName String required,
    bookTitle String    required,
    numberOfPages Integer   required,
}




relationship OneToOne 
{
    //Book{bookCoverType(coverType)} to BookCoverType
    Author{address(streetName)} to Address
}

relationship OneToMany 
{
    BookCoverType{book(bookTitle)} to Book
    Book{author(firstName)} to Author
    Author{book(bookTitle)} to Book

}

microservice * with books

paginate Book with pagination
paginate Author with pagination

@MathieuAA may be we should create a sample microservice JDL with a gateway and 2 microservices, WDYT?

@jpavanaryan please try it and let us know

@deepu105 Where should I specify skipServer option? JDL file (skipServer for *)or command line (jhipster import-jdl books.jh --skipServer)?

@jpavanaryan Because the entities are declared as microservice entities (microservice * with books), the server is automatically skipped.

@jpavanaryan I meant you shouldnt be using skipServer, it was a typo

Thanks, @deepu105 and @ruddell. It worked. It would be nice to have proper documentation for cases like this

@deepu105 Agreed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deepu105 picture deepu105  ·  75Comments

hdurix picture hdurix  ·  58Comments

deepu105 picture deepu105  ·  62Comments

deepu105 picture deepu105  ·  56Comments

deepu105 picture deepu105  ·  81Comments