Welcome to the Linux Foundation Forum!

Lab 4 not quite working - cant add data

gadzooksgadzooks Posts: 6
edited June 2017 in LFD232 Class Forum

Hi all,

I have managed to get the Roster. jar file onto PWS and it seems to be working fine. However in Lab 4 we are asked to add data to the application. I have tried the following and it is returning an error. I am trying this through a Windows Command prompt. I think the issue is to do with the PATH. I have tried all the following:

https:\\roster-beauish-gesticulator.cfapps.io OR

roster-beauish-gesticulator.cfapps.io

roster

 

C:\Users\PG\CF>cf app roster

Showing health and status for app roster in org xxxxx / space development as xxxxxxxxxxxxx

OK

 

requested state: started

instances: 1/1

usage: 1G x 1 instances

urls: roster-beauish-gesticulator.cfapps.io

last uploaded: Tue Jun 13 10:50:14 UTC 2017

stack: cflinuxfs2

buildpack: container-certificate-trust-store=2.0.0_RELEASE java-buildpack=v3.15-offline-https://github.com/cloudfoundry/java-buildpack.git#a3a9e61 java-main open-jdk-like-jre=1.8.0_121 open-jdk-like-memory-calculator=2.0.2_RELEASE spring-auto-reconfiguration=1.10...

     state     since                    cpu    memory         disk           details

#0   running   2017-06-13 11:51:37 AM   0.5%   567.2M of 1G   154.7M of 1G

C:\Users\PG\CF>cf curl "roster-beauish-gesticulator" -H "Content-Type: application/json" -X POST -d "{"firstName":"foo", "lastName": "bar"}"

{

   "description": "Unknown request",

   "error_code": "CF-NotFound",

   "code": 10000

}

Comments

  • amatelliniamatellini Posts: 15
    edited June 2017

    Try this:

    curl -H "Content-Type: application/json" -X POST -d '{"firstName":"foo", "lastName": "bar"}' http://roster-beauish-gesticulator.cfapps.io/people

    All on the same line.

     

  • TimHarris123TimHarris123 Posts: 8
    edited June 2017

    Yes Amatellini - that looks good.  Using linux "curl" is correct for accessing this endpoint, not "cf curl" in this case.  

  • amulleramuller Posts: 14
    edited June 2017

    Hello,

    I had some problems to run the curl command properly under Windows.

    This syntax should be OK:

    curl -H "Content-Type: application/json" -X POST -d "{\"firstName\":\"foo\",\"lastName\":\"bar\"}" http://roster-presageful-creature.cfapps.io/people

    Regards,

    Anthony

  • amatelliniamatellini Posts: 15
    edited June 2017

    Hi Anthony, the syntax is correct. It shold work on Windows, at least it worked for me. What kind of problem do you have?

    I suggest you to install cygwin, so you can use linux syntax. 

    Andrea

     

  • gadzooksgadzooks Posts: 6
    edited June 2017

    Guys,

    Many thanks for your suggestions so far but this still isnt workig for me. I am not sure if this is because it is a Windows prompt and this is a Linux command thing, a syntax mistake by myself or something else.

    If I try: 

    curl -H "Content-Type: application/json" -X POST -d "{\"firstName\":\"foo\",\"lastName\":\"bar\"}" http://roster-beauish-gesticulator.cfapps.io

    'curl' is not recognized as an internal or external command,

    operable program or batch file.

     

    If I try:

    cf curl -H "Content-Type: application/json" -X POST -d "{\"firstName\":\"foo\",\"lastName\":\"bar\"}" http://roster-beauish-gesticulator.cfapps.io

    {

       "description": "Unknown request",

       "error_code": "CF-NotFound",

       "code": 10000

    }

     

    I have tried intalling cygwin but after installing cygwin and using the Developer libraries that include curl I find there is a known cygwin bug preventing Windows users from using curl. I am a bit stuck.

    Should I try different syntax commands in Windows prompt, or should I install Linux?

     

     

     

  • gadzooksgadzooks Posts: 6
    edited June 2017

    Sorry, one more that I might add. If I try ' cf curl' then it seem to work and I get the following:

    cf curl

    Incorrect Usage: the required argument `PATH` was not provided

    NAME:

       curl - Executes a request to the targeted API endpoint

    USAGE:

       cf curl PATH [-iv] [-X METHOD] [-H HEADER] [-d DATA] [--output FILE]

       By default 'cf curl' will perform a GET to the specified PATH. If data

       is provided via -d, a POST will be performed instead, and the Content-Type

       will be set to application/json. You may override headers with -H and the

       request method with -X.

       For API documentation, please visit http://apidocs.cloudfoundry.org.

    EXAMPLES:

       cf curl "/v2/apps" -X GET -H "Content-Type: application/x-www-form-urlencoded" -d 'q=name:myapp'

       cf curl "/v2/apps" -d @/path/to/file

     

    ......more stufff that I copy from the Windows promp

  • amatelliniamatellini Posts: 15
    edited June 2017

    Hi, cf curl is only for query cf api.

    You need to install curl for windows, or cygwin (I assure you that it works), or git bash (that works to).

    For windows you can download curl at this link:

    https://bintray.com/artifact/download/vszakats/generic/curl-7.54.1-win64-mingw.7z   (source https://curl.haxx.se/download.html)

    you can extract it with winrar or 7zip. You need only the bin folder.

    Then open a Windows command prompt and write something like:

    curl -H "Content-Type: application/json" -X POST -d "{\"firstName\":\"foo\",\"lastName\":\"bar\"}" http://roster-presageful-creature.cfapps.io/people

    If you use cygwin/git bash open the bash terminial and write something like:

    curl -H "Content-Type: application/json" -X POST -d '{"firstName":"foo", "lastName": "bar"}' http://roster-beauish-gesticulator.cfapps.io/people

     

     

     

     

     

  • rdquintasrdquintas Posts: 6
    edited February 19

    Hello there.
    I'm having similar issue and I'm not able to create data.

    • App was properly deployed
    • I'm using an SAP Cloud Foundry instance
    • I'm trying with POSTMAN (not using CURL - I'm on a Windows machine)
    • When doing the POST and GET I always get status "200 OK". So this confirms app is reachable and up-and-running
    • But no data seems to be stored

    Here's 2 screenshots from POSTMAN.
    This one with the POST request

    And this one with the GET

    What could be wrong ?

    I've also looked into the logs on the instance and found nothing suspicious...

    Running out of ideas.... :neutral:

  • Everything certainly looks correct. Would you be comfortable adding me to your space? I would be happy to take a look and you could remove me immediately after. If you are not comfortable with it, that is ok too.

    If you are ok with adding me, you can do the following:

    cf set-space-role sgr[email protected] YOUR_ORG YOUR_SPACE SpaceDeveloper
    

    To remove me after debugging, it would be:

    cf unset-space-role [email protected] YOUR_ORG YOUR_SPACE SpaceDeveloper
    
  • Hi Steve @spgreenberg
    Thank you for your reply.
    I have now added you to my space with role Space Dev.

    Here's the info regarding the deployed app
    URL: http://roster-shiny-klipspringer.cfapps.eu10.hana.ondemand.com
    api endpoint: https://api.cf.eu10.hana.ondemand.com
    api version: 2.158.0
    org: bdccdb05trial
    space: dev

    Thanks in advance...

  • Thanks for adding me. This is an interesting one, but it appears posting to https:// works while http:// fails. This is specific to this instance (SAP) and I am still trying to figure out why. I will add more shortly.

  • rdquintasrdquintas Posts: 6
    edited February 20

    Thanks again Steve... I did saw some "foo" "bar" there... and I thought I was having some visions or going crazy...
    :D
    But now I understand you were experimenting while I was trying stuff at the same time. Sorry for that.
    I won't touch it for the next hours... so it's all yours.

    I was just doing some scale and log exercises while moving forward with this training... but I'll pause now.

  • But you're right... just did a quick POST using https instead, as you suggested, and it seems to be saving the data now.
    You'll see some entries with my name in there "Ricardo Quintas"

  • SAP... it's a whole new experience. Everyday there's a surprise... :p

  • spgreenbergspgreenberg Posts: 78
    edited February 20

    I think the confusing part is caused by Postman's behavior and not entirely SAP. Though SAP could handle this better. I expand below. Feel free to remove me from your space using the unset-space-role command above.

    I will expand on what I am seeing below, but you can feel free to ignore this. It is not a Cloud Foundry issue, but standard HTTP protocols and response codes. Fair warning, it is a bit down in the weeds.

    It is common for a platform like SAP to require https. This is typically handled with an HTTP status code of 301 indicating a permanent redirect when the client originally executes a GET request. However, when a client executes a POST, they could respond with a 308. This is a relatively new status code (2014) and is not a requirement. SAP does not appear to use a 308.

    curl -i -H "Content-Type: application/json" -X POST -d '{"firstName":"foo","lastName": "bar"}' http://roster.../people
    
    HTTP/1.1 301 Moved Permanently
    Content-length: 0
    Location: https://roster-.../people
    Connection: close
    

    Now the tricky part... Source: https://everything.curl.dev/http/redirects

    "All three of these response codes, 301 and 302/303, will assume that the client sends a GET to get the new URI, even if the client might have sent a POST in the first request."

    Therefore, you are seeing Postman follow the redirect and perform a GET to the https endpoint (rather than a POST). This explains why you see the results and a 200 status code. This also explains why you don't see any errors in the logs. There are none.

    Postman and the command line curl behave differently. With curl, you explicitly see the redirect (unless you tell it to follow redirects with the -L flag). With Postman, you do not. I suspect if SAP returned a 308, Postman would still follow the redirect but instead do the POST. There is no way to test this though as SAP does not return a 308.

  • Thank you Steve!!
    Really awesome reply.

    I also tried to play with POSTMAN settings, it seems there's an option to enable/disable "follow redirect"

    But not much help... the only difference is that I get "1" this time, as the reply.

    So using HTTPS solves the issue.

    Thanks again Steve!!
    :)

Sign In or Register to comment.