Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Web Services
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Web Services
getting error 405 Method Not Allowed when calling a @GET webservice using a post method.
Lilly Rose
Ranch Hand
Posts: 40
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can we call a webservice method which uses @GET in another resful service using POST method.
I'm calling the methods in ServiceRestful.java, the method looks like this
@GET @WebMethod @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Path("/{client}/policy/{policyNumber}/autoDebitSignupId") public AutoPayResponse AutoDebitId(@PathParam("client") String client, @PathParam("policyNumber") String policyNumber, @QueryParam("payCardId") String payCardId, @QueryParam("payBankId") String payBankId) { AutoPaySignupRequest request = new AutoPaySignupRequest(); AutoPayResponse response = null; if (StringUtils.isNotEmpty(payBankId)) { try { String shortPolicyNumber = PolicyNumber.to7Digit(policyNumber); PaymentBankAccount bankDetails = paymentService.getAccount(payBankId); Policy policy = policyService.findLatestPolicy(shortPolicyNumber); request.setClient(client); request.setPolicyNumber(shortPolicyNumber); request.setBankAccountNumber(bankDetails.getAccountNumber()); request.setBankRoutingNumber(bankDetails.getRoutingNumber()); request.setPaymentMethod("CHECK"); request.setBillingFirstName(policy.getInsuredPerson().getFirstName()); request.setBillingLastName(policy.getInsuredPerson().getLastName()); request.setBillingStreet(policy.getInsuredPerson().getStreet()); request.setBillingCity(policy.getInsuredPerson().getCity()); request.setBillingState(policy.getInsuredPerson().getState()); request.setBillingZip(policy.getInsuredPerson().getZip()); response = policyInquiryServiceDelegate.autoDebitSignUp(request); } catch (Exception e) { response = new AutoPayResponse(); handleException(e, response); } } else if (StringUtils.isNotEmpty(payCardId)) { try { PaymentCard cardDetails = paymentService.getCard(payCardId); request.setClient(client); request.setPolicyNumber(policyNumber); request.setToken(cardDetails.getCreditCardToken()); request.setExpirationMonth(cardDetails.getCardExpirationMonth()); request.setExpirationYear(cardDetails.getCardExpirationYear()); request.setPaymentMethod("LAST_CREDIT"); request.setBillingFirstName(cardDetails.getFirstName()); request.setBillingLastName(cardDetails.getLastName()); request.setBillingStreet(cardDetails.getStreet()); request.setBillingCity(cardDetails.getCity()); request.setBillingState(cardDetails.getState()); request.setBillingZip(cardDetails.getZip()); response = policyInquiryServiceDelegate.autoDebitSignUp(request); } catch (Exception e) { response = new AutoPayResponse(); handleException(e, response); } } return response; } I'm calling this AutoDebitId method in another controller.java @RequestMapping(value = "/policy/{policyNumber}/{type}", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_VALUE }) public @ResponseBody String autoDebitById(@PathVariable String policyNumber, @PathVariable String type,@RequestBody AutoDebitRequest request) { RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> responseEntity = null; String paycardIdPath = null; String paybankIdPath = null; System.out.println("----------->type"+type); System.out.println("----------->payCardId"+payCardId); String payCardId = request.getPayCardId(); String payBankId = request.getPayBankId(); if(StringUtils.isNotEmpty(type)&&type.equals("CardId")) { paycardIdPath = autoDebitEndPoint + "/" + CLIENT_NATIVE_MOBILE + "/policy/" + policyNumber + "/autoDebitSignupId" + "?payCardId=" + payCardId; responseEntity = restTemplate.exchange(paycardIdPath, HttpMethod.POST, new HttpEntity(""), String.class); return responseEntity.getBody(); } else if(StringUtils.isNotEmpty(payBankId)) { paybankIdPath = autoDebitEndPoint + "/" + CLIENT_NATIVE_MOBILE + "/policy/" + policyNumber + "/autoDebitSignupId" + "?payBankId=" + payBankId; responseEntity = restTemplate.exchange(paybankIdPath, HttpMethod.POST, new HttpEntity(""), String.class); return responseEntity.getBody(); } return responseEntity.getBody(); } I'm using Chrome Postman using POST, set the url like this, passing the body { "payCardId" : "45", "payBankId" : ""} http://localhost:8080/NativeMobileServiceV2/rest/autoDebit/policy/3559182/CardId I'm getting error : 405 Method not allowed. 10/03, 13:55:51 DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'nativeMobileServiceV2' processing POST request for [/NativeMobileServiceV2/rest/autoDebit/policy/3559182/CardId] 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /autoDebit/policy/3559182/CardId 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.pgac.nmsv2.controller.AutoDebitController.autoDebitById(java.lang.String,java.lang.String,com.pgac.nmsv2.model.AutoDebitRequest)] 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Reading [class com.pgac.nmsv2.model.AutoDebitRequest] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@5558f568] ----------->typeCardId ----------->payCardId71 10/03, 13:55:51 DEBUG org.springframework.web.client.RestTemplate - Created POST request for "http://localhost:8080/PolicyInquiryService/inquiry/Native-Mobile/policy/3559182/autoDebitSignupId?payCardId=71" 10/03, 13:55:51 DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, */*] 10/03, 13:55:51 DEBUG org.springframework.web.client.RestTemplate - Writing [com.pgac.nmsv2.model.AutoDebitRequest@2ce541cc] using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@7daafc62] 10/03, 13:55:51 WARN org.springframework.web.client.RestTemplate - POST request for "http://localhost:8080/PolicyInquiryService/inquiry/Native-Mobile/policy/3559182/autoDebitSignupId?payCardId=71" resulted in 405 (Method Not Allowed); invoking error handler 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.pgac.nmsv2.controller.AutoDebitController.autoDebitById(java.lang.String,java.lang.String,com.pgac.nmsv2.model.AutoDebitRequest)]: org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public java.lang.String com.pgac.nmsv2.controller.AutoDebitController.autoDebitById(java.lang.String,java.lang.String,com.pgac.nmsv2.model.AutoDebitRequest)]: org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed 10/03, 13:55:51 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.pgac.nmsv2.controller.AutoDebitController.autoDebitById(java.lang.String,java.lang.String,com.pgac.nmsv2.model.AutoDebitRequest)]: org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed 10/03, 13:55:51 DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
So then why are you calling
exchange
()
with
HttpMethod.POST
?
Lilly Rose
Ranch Hand
Posts: 40
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I did tried like this, I still get the same error
String
response = restTemplate.postForObject(paycardIdPath, request, String.class);
return response;
Ron McLeod
Marshal
Posts: 4501
572
I like...
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You are using a
POST
request targeted for a handler method which is annotated indicating that it handles
GET
requests --
405 Method Not Allowed
seems like a proper response.
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Well, it should be possible to forward the request to a
GET
action, but then pass the
GET
verb!
restTemplate.exchange(paycardIdPath, HttpMethod.GET, new HttpEntity(""), String.class);
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Basic Authentication 401 Unauthorized error calling restful web service
Need help in Spring Boot
org.springframework.http.converter.HttpMessageNotReadableException : Creating a client REST service
Map value passing
Problem mocking restTemplate
More...