Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 29 10:32
    Bycob edited #595
  • Jun 29 10:21
    Bycob opened #595
  • Jun 28 13:46
    ankitgit edited #594
  • Jun 28 13:45
    ankitgit opened #594
  • Jun 25 19:34
    falko-strenzke closed #593
  • Jun 25 19:34
    falko-strenzke commented #593
  • Jun 23 14:22
    falko-strenzke commented #593
  • Jun 20 14:04
    hw-dwalter opened #67
  • Jun 20 13:37
    hw-dwalter commented #593
  • Jun 20 13:34
    hw-dwalter commented #593
  • Jun 20 10:34
    Alberto-Izquierdo commented #531
  • Jun 16 18:18
    falko-strenzke commented #433
  • Jun 16 12:59
    falko-strenzke opened #593
  • Jun 16 10:08
    Alberto-Izquierdo commented #531
  • Jun 16 08:44
    Alberto-Izquierdo commented #531
  • Jun 16 08:04
    wjr20138216 opened #592
  • Jun 15 12:23
    mdumont-arcom opened #591
  • Jun 06 10:36
    yeshuanova opened #590
  • Jun 02 04:47
    doufu3344 opened #589
  • Jun 01 11:55
    lxyhh commented on 652f95c
oat++
@oatpp_io_twitter

@nikoladsp ,

You can do that.

  • You can have a proxy in front of all your services which proxies requests + has the swagger-ui for all upstream services.
  • Or, you can serve swagger-ui in a separate service. Just make sure that you have the correct server address in swagger-ui and that all your services are accessible at that host-name
Nikola Radovanovic
@nikoladsp
@oatpp_io_twitter , many thanks. I will probably go with second approach
shijiantouzouyiqie
@shijiantouzouyiqie
The browser establishes a link with the server websocket and actively sends data. The browser refreshes the page and closes the page for the first time. The server runs normally; The browser establishes a link with the server websocket and actively sends data. When the browser closes the page for the second time, it will send 1001 status code to the server, and the program crashes;
@oatpp_io_twitter Hello, the following is the current code. Is there a better optimization method?
void* StartThread(void* arg);
class WSInstanceListener : public oatpp::websocket::ConnectionHandler::SocketInstanceListener {
public:

.....
public:

  pthread_t m_pid;
  bool m_bQuitThread;
  oatpp::websocket::WebSocket* m_Socket;

};

WSInstanceListener::WSInstanceListener() {
    m_pid = -1;
    m_bQuitThread = true;
    m_Socket = NULL;
}

void WSInstanceListener::onAfterCreate(
        const oatpp::websocket::WebSocket &socket,
        const std::shared_ptr<const ParameterMap> &params) {
    SOCKETS++;
    OATPP_LOGD(TAG, "New Incoming Connection. Connection count=%d",
            SOCKETS.load());

    socket.setListener(std::make_shared<WSListener>());

    m_Socket = (oatpp::websocket::WebSocket*) &socket;

    pthread_create(&m_pid, NULL, StartThread, (void*) this);
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
    pthread_detach(m_pid);

}

void WSInstanceListener::onBeforeDestroy(
        const oatpp::websocket::WebSocket &socket) {
    SOCKETS--;
    OATPP_LOGD(TAG, "Connection closed. Connection count=%d", SOCKETS.load());

    m_bQuitThread = false;
    pthread_cancel(m_pid);
    pthread_join(m_pid,NULL);
    this->m_Socket->stopListening();

}

void* StartThread(void *arg) {
    WSInstanceListener *lis = (WSInstanceListener*) arg;

    lis->m_bQuitThread = true;

    while (lis->m_bQuitThread) {
        pthread_testcancel();
        lis->m_Socket->sendOneFrameText("hello");
    }

    return (void*) 0;
}

 I |2021-12-15 19:46:53 1639568813189617| MyApp:Server running on port 8000
 D |2021-12-15 19:47:00 1639568820630942| Server_WSInstanceListener:New Incoming Connection. Connection count=1
 D |2021-12-15 19:47:06 1639568826556318| Server_WSListener:onClose code=1001
 D |2021-12-15 19:47:06 1639568826556353| Server_WSInstanceListener:Connection closed. Connection count=0
 D |2021-12-15 19:47:16 1639568836406451| Server_WSInstanceListener:New Incoming Connection. Connection count=1
 D |2021-12-15 19:47:21 1639568841210745| Server_WSListener:onClose code=1001
 terminate called after throwing an instance of 'std::runtime_error'
 D |2021-12-15 19:47:21 1639568841210782| Server_WSInstanceListener:Connection closed. Connection count=0
 terminate called recursively
AlexandreHURDYK
@AlexandreHURDYK

Hello.

I've got an annoying issue I'm trying to fix on my oat++ client application : if my server shuts down before it gets the time to send a response to my client after a client request, it causes my client to crash. This is probably a common problem. Any way to fix this client side ?

I can provide an example API call from my client if necessary.
There's probably something I forgot to do.
AlexandreHURDYK
@AlexandreHURDYK
Most basic example : if I call an API function while the server is not up, the client crashes.
As simple as that.
I can try to make a minimal working example.
Is there a way to make my request time out or something ?
Ok nevermind I fixed the problem and I'm stupid : the simple solution was just to surround the API calls with a try/catch.
Nikola Radovanovic
@nikoladsp
hi all, advice needed.
for simplicity, say that there is a DTO User class with id (primary key, auto inc, etc), salutation (mr,mrs, default null) and full name (string).
  1. for all crud methods apart create, id is required field. how is it possible to reuse one DTO in such way that swagger know that id is not present at all while creating user object (excluded from schema) and in all other cases is required? or do I need DTO per crud operation. Additionally, during update, id is the only required field, all others are optional, while reading for example I expect id and fullname to be present and salutation is optional.
  2. is it possible to use some pattern (decorator maybe?) to decouple DTO classes from "business" logic classes. I am interested for this especially in cases of relationships (composed objects, where one holds many others)
    thanks in advance
mmn
@mmn:matrix.org
[m]
Is there some easy way to determine the reason why oatpp::websocket::WebSocket::listen() returned? It catches the relevant exceptions and does not return any value, which makes it a bit hard.
Okay, maybe I should abandon listen() and "reimplement" it using iterateFrame().
oat++
@oatpp_io_twitter

Hey @nikoladsp ,

In an ideal world you would have to decouple the DB model and REST DTOs. The way you present data to service users and the way you store data may differ (and they do differ in most cases). Also, it's not recommended to expose DB ids - since they do not describe the actual resource in most cases.

Treat CRUD service as an adaptor of REST interface to DB model.

So the answer is - create two sets of DTOs - one for REST, second for DB.
Read from DB - do whatever transformations/compositions you need - join data in memory if needed - form response DTO and return it on the endpoint.

About the 'ID' problem - follow this issue - oatpp/oatpp#485
We may introduce hidden (from swagger docs) fields in future
oat++
@oatpp_io_twitter

Hey @mmn:matrix.org ,

if the WebSocket connection was closed gracefully - you'll receive the onClose method call in WS listener first, then the listen method will return.
If there was any kind of network issue - listen method will just return - no onClose event triggered.
Here is the implementation of listen - https://github.com/oatpp/oatpp-websocket/blob/master/src/oatpp-websocket/WebSocket.cpp#L279

1 reply
Please note that closed connection - is a normal situation for WebSocket - your application has to have the re-connecting functionality.
Also, make sure to respond with pong messages for all pings
Nikola Radovanovic
@nikoladsp
hi @oatpp_io_twitter many thanks, now to compile some stuff! :D
oat++
@oatpp_io_twitter

The browser establishes a link with the server websocket and actively sends data. The browser refreshes the page and closes the page for the first time. The server runs normally; The browser establishes a link with the server websocket and actively sends data. When the browser closes the page for the second time, it will send 1001 status code to the server, and the program crashes;
@oatpp_io_twitter Hello, the following is the current code. Is there a better optimization method?

Hey @shijiantouzouyiqie ,

Your program is missing a lot of things - and it has critical bugs:

  • please use std::thread instead of the pthread - just for simplicity and portability
  • synchronize with mutex access to m_bQuitThread
  • make sure that the socket is never used after m_bQuitThread is set to true
  • use sendOneFrameText call inside of try - catch block.
shijiantouzouyiqie
@shijiantouzouyiqie
@oatpp_io_twitter Thank you. I'm trying. I mainly use fewer threads. Set std::thread as a class member or the global does not understand the use of initialization. When I disconnect from the browser, the thread will be disconnected.
shijiantouzouyiqie
@shijiantouzouyiqie
@oatpp_io_twitter Thank you.
Using std::thread, the server can be used normally.
mmn
@mmn:matrix.org
[m]
So for the time being, I'm just deriving WebSocket with my own listen() (and stopListening(); can't use m_listening because it's private) which passes the exceptions through.
shijiantouzouyiqie
@shijiantouzouyiqie
Hello, theoatpp:: websocket:: websocket * m_socket; used here is initialized in the structure as a member variable. It is understood that it should be initialized bym_socket = new oatpp:: websocket:: websocket();. If an error is reported, I don't know how to solve this problem....
oat++
@oatpp_io_twitter
Hey @shijiantouzouyiqie , so what is the question?
1 reply
SSE4
@SSE4
how do I select from PostgreSQL ENUM type into the DTO with oatpp ENUM?
Leonid Stryzhevskyi
@lganzzzo
Hello @SSE4 , just creare a field in DTO with enum. Also, make sure to use enum as string or as a number - depending on your application
You can see an example in exaple-crud
That example is for SQLite, but there is no difference
SSE4
@SSE4
thank for the help. I made it work, I had to add a cast to my SELECT QUERY: CAST({0} as text)
otherwise, I was getting an exception: [oatpp::postgresql::mapping::Deserializer::deserializeString()]: Error. Unknown OID.
Zach
@acidtonic

I keep fighting some odd linker errors about missing vtable/constructors for DTO files even though they are correctly defined when linking across a few projects. But since the DTO's are only headers the static library for the DTO's are 8 bytes and basically empty.

I link everywhere else but on windows I get errors about the Vtable for the API-Client DTOs

Not sure what I am missing. I actually have two projects and one links but the other doesnt. Both use the same API library and dtos, just trying to track down why
Leonid Stryzhevskyi
@lganzzzo
Hey @acidtonic , I had before some errors with header only libraries. I ended up just adding an empty .cpp file. Just didnt want to spend time on that
Zach
@acidtonic
I have unfortunately a large multi-part project structure and I'm not sure if it's my fault or not :)
Likely is.... I'll probably follow your advice and throw in a cpp file
Zach
@acidtonic
Can I make the DTO's also contain a cpp or will that break the codegen?
I suspect the client-dto-lib is actually empty and brining no extra symbols over, but the dtos are reachable at compile time so I only get a link error. Still somewhat confused how
Leonid Stryzhevskyi
@lganzzzo
Can I make the DTO's also contain a cpp or will that break the codegen?
No, it wont break anything
I suspect the client-dto-lib is actually empty and brining no extra symbols over, but the dtos are reachable at compile time so I only get a link error. Still somewhat confused how
Can you please post the actual linker error
Mo Aboulmagd
@Maboulmagd
@oatpp_io_twitter I was wondering, how often do websockets disconnect? i.e Is it once every 10 hours, or does it depend on the host that I am listening to and their rules? Also, is there an implementation of the reconnecting functionality, that I can take a look at? Or is it as simple as using the connector to reconnect to the endpoint I am interested in, and resubscribing to streams that I was initially subscribed to?
oat++
@oatpp_io_twitter

@Maboulmagd

I was wondering, how often do websockets disconnect? i.e Is it once every 10 hours, or does it depend on the host that I am listening to and their rules?

Yes, It depends on the host rules and on the internet connection.
If you want your events stream to be stable - you should have a reconnect functionality.

Also, is there an implementation of the reconnecting functionality, that I can take a look at? Or is it as simple as using the connector to reconnect to the endpoint I am interested in, and resubscribing to streams that I was initially subscribed to?

Yes, it's just as simple as using the connector to connect again.

1 reply
AlexandreHURDYK
@AlexandreHURDYK

Hello. It's me again.

I'm trying to shove the content of a std::vector<bool> object inside a List<Boolean> DTO field, but the compiler isn't very happy about this and tells me there is no matching member function to call puch_back(), which is kinda strange because I managed to shove a std::vector<std::string> inside a List<String> DTO field without trouble.

What's the issue here ?

Here's the code bit you may want to see :
auto dtoEndosInfos = EndoResponse::createShared();

dtoEndosInfos->nbFiles = vecInfos.nbFiles;
for (int i = 0; i < vecInfos.nbFiles; i++)
{
    dtoEndosInfos->name->push_back(vecInfos.name[i]);
    dtoEndosInfos->isStamp->push_back(vecInfos.isStamp[i]);
    dtoEndosInfos->block->push_back(vecInfos.block[i]);
}
My DTO declaration while we're at it :
class EndoResponse : public oatpp::DTO
{
    DTO_INIT(EndoResponse, DTO)
    DTO_FIELD(List<String>, name);
    DTO_FIELD(List<Boolean>, isStamp);
    DTO_FIELD(List<String>, block);
    DTO_FIELD(Int32, nbFiles);

};