Skip to Content
author's profile photo Former Member
Former Member

How to create a custom commerce webservices

Hi All,

I have created a custom commerce webservices by giving ant extgen. After the custom extension got created, i added a controller.

It works if i don't add any parameter in the method signature. But if i add a method that accepts string or Json it doesnt work.

@RequestMapping(value = "/loginCheck1", method = RequestMethod.POST, consumes = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) @CacheControl(directive = CacheControlDirective.PUBLIC, maxAge = 300) @ResponseBody public void LoginCheck1(@RequestBody final String Json) { System.out.println("hii 222 /loginCheck"); System.out.println(Json); }

When i hit from postman client, if i dont add any values to request body it gives me 404 error. alt text

When add some value it gives 415 -Unsupported media type. alt text

Im getting the 415 even if i change it to type as text in header. Could someone let me know what i'm missing

9515-img1.png (17.8 kB)
9516-img3.png (22.9 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 09, 2017 at 01:47 PM

    Im using version 6.4

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 09, 2017 at 02:03 PM

    Hi,

    I have modified my method as shown below.

    @RequestMapping(value = "/{baseSiteId}/login/loginChk", method = RequestMethod.POST, headers = "Accept=application/xml,application/json") public void register(final TestCustomerDTO dto) {

         System.out.println(dto.getFirstName());
         System.out.println(dto.getLastName());
    
     }
    
    

    But output is:

    null null

    im passing a json { "firstName": "first", "lastName":"last"

    }

    still it doesn't work kindly help.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.