Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 25 17:37
    lgtm-com[bot] opened #664
  • Nov 25 09:33
    cyang-catalogicsoftware commented #662
  • Nov 25 09:22
    cyang-catalogicsoftware commented #662
  • Nov 25 03:46
    YundongGai commented #626
  • Nov 25 01:41
    SSDGADsss commented #662
  • Nov 24 08:03
    Peibohao commented #663
  • Nov 24 07:46
    csyJoy opened #663
  • Nov 24 04:25
    cyang-catalogicsoftware opened #662
  • Nov 24 03:49
    cyang-catalogicsoftware closed #658
  • Nov 23 03:47
    kekxv commented #661
  • Nov 23 00:46
    kekxv opened #661
  • Nov 22 13:28
    asiirtol opened #74
  • Nov 18 07:21
    djassie commented #630
  • Nov 17 03:32
    doufu3344 commented #599
  • Nov 17 03:31
    doufu3344 opened #660
  • Nov 17 02:01
    doufu3344 commented #639
  • Nov 16 00:27
    lganzzzo commented #652
  • Nov 15 23:48
    lganzzzo labeled #653
  • Nov 15 23:48
    lganzzzo commented #653
  • Nov 15 23:24
    lganzzzo commented #658
gaoyonghero
@gaoyonghero
Hello, is there a version of oatpp-postgresql that matches oatpp-1.2.5? Thanks
Al
@AHURDYK

Hello @AHURDYK ,

As you can see ParsingError contains position (getPosition() method) - it indicates position where parsing failed.

Yes but how do I use that class ?

I'm using an objectmapper to parse my JSON into a DTO.
And I'm note sure how I can use the ParsingError class properly.
I can't seem to be able to find any examples.
oat++
@oatpp_io_twitter

Hello @gaoyonghero ,

oatpp and all of it's modules are released under the same release tag.
So for oatpp-1.2.5 you have oatpp-postgresql-1.2.5 - https://github.com/oatpp/oatpp-postgresql/releases/tag/1.2.5

Also note - that we provide support for latest oatpp versions only.
So if you stuck with oatpp-1.2.5 asking for help - first thing you'll hear from us - is to update to the latest oatpp version.

oat++
@oatpp_io_twitter

Hello @AHURDYK ,

And I'm note sure how I can use the ParsingError class properly.

When you catch ParsingError, you can get position in the text where parser failed by calling ParsingError:: getPosition()

Note: position is the character index in the text - including \r\n\t chars

Fede
@dellarocca99_twitter
Hi oat++!
Fede
@dellarocca99_twitter
OATPP_CREATE_COMPONENT(BAFakeHW*, baFakeHW)([billAcceptor]{
    return new BAFakeHW(billAcceptor);
}());
OATPP_COMPONENT(BAFakeHW*, fakeHW);
return fakeHW;

At this point, I get the component returned correctly.

I have this code in one .cpp file.
Then in other file I try to inject that component like this:

OATPP_COMPONENT(BAFakeHW*, baFakeHW);

But when I try to use that component, I get the following error:
[oatpp::base::Environment::getComponent()]: Error. Component of given type doesn't exist: type='class BAFakeHW * __ptr64'

Hope you can help me, thanks in advance!

sterben-01
@sterben-01
Hello! I'm a starter and trying to build a webserver from zero. I'm confused about how to send a .html file as a http response.
class Handler : public oatpp::web::server::HttpRequestHandler
{
public:
    std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override {
        O_UNUSED(request);
        const oatpp::String myfilepath= "../oatfile/login.html";
        oatpp::data::resource::File file(myfilepath);
        auto filestream = file.openOutputStream();
        auto response = ResponseFactory::createResponse(Status::CODE_200, "Hello, World!");
        response->send(filestream); //some thing like this?
        return response;
    }
};
I think there will be some thing like response->send(filestream);But I have no idea and didn't find any samples.
And if I use DTO, what should be the type of the file?
Al
@AHURDYK

Hello.

Is there a way to make sure my oatpp server sends DTOs encoded in UTF-8 ? I have a crash issue related to a third party library on my client application : seems like that third party lib really dislikes when my DTO contains the character "€".

I've contacted the guys who made that third party library and they told me to make sure my file is encoded in UTF-8 (although my oatpp response is not a file, but whatever), so I guess I'll have to be extra-sure that my oatpp response has a specific encoding.

Al
@AHURDYK
I did the test of putting my DTO in an UTF-8 encoded file and open it with the "problematic" library and it worked this time, so it does sound like I need to make sure oatpp sends UTF-8 encoded responses.
I just don't know how to do so. How can I do that ?
Michał
@mkucmpro

Hey! I want to log the incoming requests and their payload.

I implemented my custom request interceptor: class LoggingRequestInterceptor : public oatpp::web::server::interceptor::RequestInterceptor but I'd like to know what is the suggested way to unpack the IncomingRequest to print it's data.

Would it be something like: request->readBodyToString()? (This throws an exception at me: [oatpp::web::protocol::http::incoming::SimpleBodyDecoder::decode()]: Error. Invalid Request.)

Note that this body should later be used inside my endpoints.

gaoyonghero
@gaoyonghero
Hello, I want to use a String as a key to get the value of one field in a DTO. Like using a map , I hope to use dto["name"] to get dto->name. So, how should I do it? Thanks!
oat++
@oatpp_io_twitter

Hello @dellarocca99_twitter ,

OATPP_CREATE_COMPONENT(BAFakeHW*, baFakeHW)([billAcceptor]{
    return new BAFakeHW(billAcceptor);
}());
OATPP_COMPONENT(BAFakeHW*, fakeHW);
return fakeHW;// <--------------- at this point your component was unregistered from the environment.

Another example

{
  OATPP_CREATE_COMPONENT(BAFakeHW*, baFakeHW)([billAcceptor]{
      return new BAFakeHW(billAcceptor);
  }());
  OATPP_COMPONENT(BAFakeHW*, fakeHW);
} //<------ component unregistered here

OATPP_COMPONENT(BAFakeHW*, fakeHW); //<------ error here

Make sure to use correct scope for your component

Another comment:
It is recommended not to use bare pointers for components. Instead wrap them in std::shared_ptr.
Because otherwise object won't be destroyed when component unregistered from the environment
oat++
@oatpp_io_twitter

Hello @sterben-01 ,

    std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override {
        oatpp::data::resource::File file("../oatfile/login.html");
        auto body = std::make_shared<oatpp::web::protocol::http::outgoing::StreamingBody>(file.openInputStream());
        return OutgoingResponse::createShared(Status::CODE_200, body);
    }

OR like this

    std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override {
      return ResponseFactory::createResponse(Status::CODE_200, oatpp::String::loadFromFile("../oatfile/login.html"));
    }
oat++
@oatpp_io_twitter

Hello @AHURDYK ,

Is there a way to make sure my oatpp server sends DTOs encoded in UTF-8 ? I have a crash issue related to a third party library on my client application : seems like that third party lib really dislikes when my DTO contains the character "€".

Oatpp does NOT impose any encoding on the strings. If you are sending utf-8 encoded string - it will be utf-8 encoded string.
Also, DTO serializer will escape all non-ASCII chars with code > 127 treating them as a UTF-8 symbols.

The only thing I can think about here - is that you are setting non-utf-8 string to DTO fields.

Hello @gaoyonghero ,

Hello, I want to use a String as a key to get the value of one field in a DTO. Like using a map , I hope to use dto["name"] to get dto->name. So, how should I do it? Thanks!

You want it - you do it:)
Checkout this test - https://github.com/oatpp/oatpp/blob/master/test/oatpp/core/data/mapping/type/ObjectTest.cpp#L434

oat++
@oatpp_io_twitter

Hello @mkucmpro ,

Hey! I want to log the incoming requests and their payload.
Note that this body should later be used inside my endpoints.

oatpp is all about streaming - it doesn't cache request body.
If you read body stream from request object - it will drain the stream making it unavailable for future reads in endpoints.

I would suggest two options:

  • log inside the endpoints
  • log the stream itself - add two wrapper classes (ConnectionProviderWrapper, ConnectionWrapper) - ConnectionWrapper - will wrap the actual connection, and each time someone calls read/write on the connection - you flush the data to file/logs

The downside of the second option is that you'll have unparsed data

gaoyonghero
@gaoyonghero

@oatpp_io_twitter Hello, if I use dto[“name”] to get dto->name, gcc throw an error message:

error: passing ‘oatpp::Object<UserDto> {aka const oatpp::data::mapping::type::DTOWrapper<UserDto>}’ as ‘this’ argument discards qualifiers [-fpermissive]
OATPP_LOGD("view", (*(dto["name"])).c_str());

Why such an error occurs and how to fix it?

gaoyonghero
@gaoyonghero
I got it! This method can only be used to modify the value of the property, not to read the parameters qualified by "const" .
sterben-01
@sterben-01
Hi, I'm trying to run the example-postgresql example on my Linux VM. My version is 18.04. But I found some issues.
First is in the file example-postgresql/src/db/UserDb.hpp, line6 is #include "oatpp-postgresql/orm.hpp". But that is not work for me and pops an errorlibpq-fe.h: No such file or directory.
In this answer https://stackoverflow.com/questions/6040583/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem
It said It looks like in Ubuntu that header is part of the libpq-dev package.
So I go to all related files and change #include <libpq-fe.h> to #include'/usr/include/postgresql/libpq-fe.h'
But after that, in the file example-postgresql/src/db/UserDb.hpp, line21 I got an error: undefined identifer for DATABASE_MIGRATIONS.
My question is what cause this problem? Does it caused by I edit all #include <libpq-fe.h> to #include'/usr/include/postgresql/libpq-fe.h'?
Thank you!
oat++
@oatpp_io_twitter

Hello @gaoyonghero ,

I got it! This method can only be used to modify the value of the property, not to read the parameters qualified by "const" .

Yes you can! You just have to cast to the correct value type.

    auto user = UserDto::createShared();
    user->email = "blah@blah.com";
    auto email = user["email"].cast<oatpp::String>(); // cast before using it

you can also do like this:

return createDtoResponse(Status::CODE_200, user["email"]); //<-- here no cast needed
oat++
@oatpp_io_twitter

Hello @sterben-01 ,

Hi, I'm trying to run the example-postgresql example on my Linux VM. My version is 18.04. But I found some issues.
First is in the file example-postgresql/src/db/UserDb.hpp, line6 is #include "oatpp-postgresql/orm.hpp". But that is not work for me and pops an errorlibpq-fe.h: No such file or directory.

There is no need to edit any includes in oatpp files. You just have to install correct packages on your LinuxVM
As said in oatpp-postgresql:
You need to install PostgreSQL dev package first.
And of course make sure to install all required oatpp packages too

sterben-01
@sterben-01
Hi thank you I will try it again
kchrome
@kchrome

When I upload using a simple upload (1.3.0) with a small text file I wind up with a zero byte file.

If I use a multipart upload then I get no file at all.

Al
@AHURDYK

My oatpp server returned me the following error :

[14:35:10][ERROR] : [RESPONSE][192.168.1.26:8000] : CODE 500 | server=oatpp/1.3.0 code=500 description=Internal Server Error message=wstring_convert::from_bytes

What could typically cause these kinds of error ?

oat++
@oatpp_io_twitter

Hello @kchrome ,

When I upload using a simple upload (1.3.0) with a small text file I wind up with a zero byte file.
If I use a multipart upload then I get no file at all.

Please post your endpoint code and your curl request to see

Hello @AHURDYK

My oatpp server returned me the following error :
[14:35:10][ERROR] : [RESPONSE][192.168.1.26:8000] : CODE 500 | server=oatpp/1.3.0 code=500 description=Internal Server Error message=wstring_convert::from_bytes

See the message - wstring_convert::from_bytes - most probably wstring_convert::from_bytes method threw an error.

Al
@AHURDYK
I don't think I'm using such a method though. Is it the kind of method that is automatically used by some commonly used functions ?
gaoyonghero
@gaoyonghero

Hello @gaoyonghero ,

I got it! This method can only be used to modify the value of the property, not to read the parameters qualified by "const" .

Yes you can! You just have to cast to the correct value type.

    auto user = UserDto::createShared();
    user->email = "blah@blah.com";
    auto email = user["email"].cast<oatpp::String>(); // cast before using it

you can also do like this:

return createDtoResponse(Status::CODE_200, user["email"]); //<-- here no cast needed

Thank you for your help. And how to do self-adaptive type conversion:
' auto email = user["email"].cast<Type>(); '
Is it possible for the program to obtain the 'Type' itself, rather than I determine in advance.

oat++
@oatpp_io_twitter
@AHURDYK ,
You have to check your code. It might be in some 3rd party lib or something

@gaoyonghero ,

auto email = user["email"].cast<Type>();

Unfortunately, no such magic available.
You have to check type, then read value using the correct type

Al
@AHURDYK

@AHURDYK ,
You have to check your code. It might be in some 3rd party lib or something

Indeed, it seemed to have been caused by some odd function I was using for utf8 string conversion. The issue was quite peculiar : my function was doing fine if my server was running on windows, but literally couldn't handle itself on linux.

I had to borrow someone else's UTF8 encoding function to fix it.
DominikStransky
@DominikStransky
Hey there!
I want to write unit tests for my oatpp websocket application. So I basically copied everything (all the non-async stuff) from this folder (test/oatpp-websocket/). However, I'm not able to trigger the readMessage() method of line 125 of the FullTest.cpp file. Can you tell me how to achieve that or what I might be doing wrong? (I want to test that my websocket server sends the correct messages.)
DominikStransky
@DominikStransky
I'm not even sure if socket.setListener(std::make_shared<ClientWebSocketListener>()); (see here) has any effect at all.
DominikStransky
@DominikStransky
Never mind. I think I got it after calling socket.listen() :D. Sorry for the spam!
EnderTheCoder
@EnderTheCoder
Can anyone take a look at this issue?
Compile Error in module libressl
it's so weird
EnderTheCoder
@EnderTheCoder
image.png
I encountered a weird issue with api client. It been normal for months. but now any request will break it.
I'm pretty sure it's not an issue with my code cause I haven't edited it for a long time. It might be a problem with curl or oatpp API client.
MateusDornelles
@MateusDornelles
Hi, how can I redirect an websocket connection ? I would like the user to "log in" using an endpoint and then redirect the connection to my websocket on another endpoint.