Spring boot application Post method invocation, 405: Method Not Allowed - java

I am writing Rest Application with Spring boot. To expose my service code in as REST services.
I am able to expose my services in GET method when I am writing Post method with below code of Controller and Pojo class I am getting 405: Method Not Allowed error.
Not able to understand why ?
I have refered this link. and others related too but i could not figure out what is the problem.
Below is my controller and Pojo with jackson Json annotated code.
When i am calling using Advanced REST client - Chrome Web Store - Google and using as attached image i am getting below error.
In the same class i have some GET method that is working fine.
Error :
URL : http://localhost:8085/DBService/application/saveApplicationAnswer
{
"timestamp": 1470313096237
"status": 405
"error": "Method Not Allowed"
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException"
"message": "Request method 'POST' not supported"
"path": "/DBService/application/saveApplicationAnswer"
}
DBService is my Context Name
As I have set server.context-path=/DBService in application.properties
import java.io.Serializable;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.drd.hotel.db.service.IApplicationDBService;
import com.drd.hotel.db.service.dto.application.CustomerDTO;
import com.drd.hotel.db.service.dto.application.ApplicationAnswerDTO;
import com.drd.hotel.db.service.dto.application.ApplicationQuestionsDTO;
import com.drd.hotel.db.service.dto.application.ApplicationRecommendationDTO;
import com.drd.hotel.db.service.util.ServicesConstants;
#RestController
#RequestMapping("/application")
public class ApplicationDBController<T, I extends Serializable> {
#Autowired
private IApplicationDBService applicationDBService;
#RequestMapping(value = "/saveApplicationAnswer", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public int saveApplicationAnswer(#ModelAttribute(ServicesConstants.SURVERY_ANSWER_FL) ApplicationAnswerDTO applicationAnswer) {
LOG.info("ApplicationDBController fn saveApplicationAnswer BookingId {} {} {}",applicationAnswer.getBookingId(), ServicesConstants.CUSTOMER_ID_FL, applicationAnswer.getCustomerId());
return applicationDBService.saveapplicationAnswer(applicationAnswer);
}
}
My JSON:
{"answerId":1,"applicationQuestionId":1,"recommendId":1,"bookingId":123001,"customerId":19501,"reasonForCancelation":"I dont konw ","feedbackText":"I dont know what is this too bad design","applicationDate":"2016-08-04","funnelPageName":"I dont know what is the use of this.","applicationReferenceSource":"I dont knwo what is this field for","languageId":1}
MY Pojo annotated with JSON :
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
#JsonIgnoreProperties(ignoreUnknown = true)
#JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
#JsonSerialize(include =Inclusion.NON_NULL)
public class ApplicationAnswerDTO {
private int answerId;
private int applicationQuestionId;
private int recommendId;
private int bookingId;
private int customerId;
private String reasonForCancelation;
private String feedbackText;
private Date applicationDate;
private String funnelPageName;
private String applicationReferenceSource;
private int languageId;
public int getAnswerId() {
return answerId;
}
public void setAnswerId(int answerId) {
this.answerId = answerId;
}
public int getApplicationQuestionId() {
return applicationQuestionId;
}
public void setApplicationQuestionId(int applicationQuestionId) {
this.applicationQuestionId = applicationQuestionId;
}
public int getRecommendId() {
return recommendId;
}
public void setRecommendId(int recommendId) {
this.recommendId = recommendId;
}
public int getBookingId() {
return bookingId;
}
public void setBookingId(int bookingId) {
this.bookingId = bookingId;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getFeedbackText() {
return feedbackText;
}
public void setFeedbackText(String feedbackText) {
this.feedbackText = feedbackText;
}
public Date getApplicationDate() {
return applicationDate;
}
public void setApplicationDate(Date applicationDate) {
this.applicationDate = applicationDate;
}
public String getFunnelPageName() {
return funnelPageName;
}
public void setFunnelPageName(String funnelPageName) {
this.funnelPageName = funnelPageName;
}
public String getApplicationReferenceSource() {
return applicationReferenceSource;
}
public void setApplicationReferenceSource(String applicationReferenceSource) {
this.applicationReferenceSource = applicationReferenceSource;
}
public int getLanguageId() {
return languageId;
}
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
public String getReasonForCancelation() {
return reasonForCancelation;
}
public void setReasonForCancelation(String reasonForCancelation) {
this.reasonForCancelation = reasonForCancelation;
}
#Override
public String toString() {
return "ApplicationAnswerDTO [answerId=" + answerId + ", applicationQuestionId="
+ applicationQuestionId + ", recommendId=" + recommendId
+ ", bookingId=" + bookingId + ", customerId=" + customerId
+ ", reasonForCancelation="
+ reasonForCancelation + ", feedbackText="
+ feedbackText + ", applicationDate=" + applicationDate
+ ", funnelPageName=" + funnelPageName
+ ", applicationReferenceSource=" + applicationReferenceSource
+ ", languageId=" + languageId + "]";
}
}
Thanks in advance for any kind of info and suggestion.

Can you check the method type which your are requesting.
In the screen shot which your shared it is displaying only get and head method are allowed.
I have tried your code in my Soap ui. It is displaying the below response.
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 04 Aug 2016 13:03:11 GMT
1999999999
It is displaying the response which you shared when i try to call the same service using Get method.Below is the response.
{
"timestamp": 1470315684018,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'GET' not supported",
"path": "/saveApplicationAnswer"
}
and code I used is
{
#RequestMapping(value = "/saveApplicationAnswer", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public int saveApplicationAnswer(#ModelAttribute("hello") ApplicationAnswerDTO applicationAnswer) {
System.out.println(applicationAnswer);
return 1999999999;
}
Please try with different tools preferably soap ui.

#RequestMapping(value = "/saveApplicationAnswer", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public int saveApplicationAnswer(#RequestBody(ServicesConstants.SURVERY_ANSWER_FL) ApplicationAnswerDTO applicationAnswer) {
LOG.info("ApplicationDBController fn saveApplicationAnswer BookingId {} {} {}",applicationAnswer.getBookingId(), ServicesConstants.CUSTOMER_ID_FL, applicationAnswer.getCustomerId());
return applicationDBService.saveapplicationAnswer(applicationAnswer);
}
I have changed my parameter annotation refering this post.
From
#ModelAttribute(ServicesConstants.SURVERY_ANSWER_FL) ApplicationAnswerDTO applicationAnswer
To
#RequestBody(ApplicationAnswerDTO applicationAnswer
It worked for me. seems #RequestBody is correct. But i dont know the different between #RequestBody and #ModelAttribute. If any one knows the different please share here. That will be helpful for some one.
When i am pitting #RequestBody(ApplicationAnswerDTO applicationAnswer) It worked for me.
Any way Thanks for every one for your help and suggestion.

Related

SpringBoot Restful Web API not handling special characters well: json file displayed with wrong encoding

I want to create a website/API, that reads in a csv and returns the wanted resoureces. I use SpringBoot: the Spring Web dependency. For reading in the csv I import implementation('com.opencsv:opencsv:5.6') to dependencies in my build.gradle-file. I decided to use the following structure:
Four java-files in src\main\java\com\example\so:
The bean Car.java:
package com.example.so;
import com.opencsv.bean.CsvBindByName;
import java.math.BigDecimal;
public class Car {
#CsvBindByName
private int id;
#CsvBindByName(column = "name")
private String brand;
#CsvBindByName
private BigDecimal price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
#Override
public String toString() {
return "Car{" +
"id=" + id +
", brand='" + brand + '\'' +
", price=" + price +
'}';
}
}
To display the correct car I use CarController.java:
package com.example.so;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class CarController {
#GetMapping("/car/{id}")
public Car findcar(#PathVariable int id) {
for (Car car: ReadInCSV.cars){
if (car.getId()==id){
System.out.println(car.toString());
return car;
}
}
return null;
}
#GetMapping("")
public String findcar() {
return "Hi!";
}
}
To read in the csv-file ReadInCSV.java:
package com.example.so;
import com.opencsv.bean.CsvToBeanBuilder;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;
public class ReadInCSV {
static final String fileName="src/main/resources/static/abc.csv";
static List<Car> cars;
static {
try {
cars= new CsvToBeanBuilder(new FileReader(fileName)).withType(Car.class).build().parse();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}
and to start the webservice SoApplication.java:
package com.example.so;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SoApplication {
public static void main(String[] args) {
SpringApplication.run(SoApplication.class, args);
}
}
The file with the data abc.csv:
id,name,price
1,Audi,52642
2,Mercedes,57127
3,Skoda,9000
4,Volvo,29000
5,Bentley,350000
6,Citroën,21000
7,Füll,41400
8,Rosé,21600
9,Toyota,26700
It works more or less fine, but when you enter http://localhost:8080/car/6, my browser (Firefox) displays "Citroën" instead of "Citroën". Reading in the csv seems to work fine, because when you print the bean using its .toString() you get Car{id=6, brand='Citroën', price=21000}. So apparently the json-conversion is the problem. What can I do to solve this issue?
I am new to world of java-web, so feel free telling me if there are some other problems with my approach.
I don't think this is a problem with JSON conversion but with your character encoding. Make sure both your CSV file and the output to JSON are in the same encoding, it's probably best to use UTF8. If you explicitly set produces = APPLICATION_JSON_VALUE on your controller annotation, it should already use UTF8 for that. So if it then still fails, the question remains whether the CSV is in UTF8.
Also, if you don't know what I'm talking about, https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ is pretty much a must-read.

How to automatic decode Dto from GET query parameters

I Have a GET request with some parameters which I handle as an object on the controller, consider it could be several parameters.
The problem is that the values for the properties on the dto are being filled using url encoding which I dont want because it messes up queries to a database later on, ie.: name gets populated with "some%20name" instead of "some name" as I would expect.
How can I avoid this encoding problem?
Bellow is a small scenario that represents my issue:
public class SomeDto {
private String name;
private String hex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHex() {
return hex;
}
public void setHex(String hex) {
this.hex = hex;
}
}
#RestController
#RequestMapping("example")
public class RestController {
#GetMapping
public void example(final SomeDto someDto) {
System.out.println(someDto.getName());
System.out.println(someDto.getHex());
}
}
public class ClientApi {
private RestTemplate restTemplate;
private String hostUri;
public ClientApi(RestTemplate restTemplate, String hostUri) {
this.restTemplate = restTemplate;
this.hostUri = hostUri;
}
public void test(SomeDto someDto) {
var uri = UriComponentsBuilder.fromUriString(hostUri + "/example");
if(someDto != null) {
uri.queryParam("name", someDto.getName())
.queryParam("hex", someDto.getHex());
}
restTemplate.exchange(uri.toUriString(), HttpMethod.GET, null, Void.class);
}
}
#SpringBootTest(
classes = DemoApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
class ClientApiTest {
#LocalServerPort
private String port;
private ClientApi clientApi;
#BeforeEach
void before() {
clientApi = new ClientApi(new RestTemplate(), "http://localhost:" + port);
}
#Test
void testMethod() {
SomeDto someDto = new SomeDto();
someDto.setName("some name");
someDto.setHex("#ffffff");
clientApi.test(someDto);
}
}
UPDATE:
I was able to partially fix it by decoding the URL, however it only fixes name "some name" to reach the controller correctly, hex "#ffffff" on the other hand reaches as null.
var decodedUri = URLDecoder.decode(uri.toUriString(), Charset.defaultCharset());
Spring uses some symbols as service symbols.
E.g. you cannot parse param value if it contains a comma.
?someParam=some,value
Would be parsed as two params: some and value. But if receive type is not array or collection then the second value will be ignored. Hence, you'll get someParam=some.
The simplest way to avoid it is URL params base64 encoding.
For me, the convenient way was to encode params as json in Base64.
{
"name": "some name",
"hex": "fffffff"
}
Why json? Because there are many ready-made solutions for parsing JSON into an object.
So, your controller will receive Base64 value which is eyJuYW1lIjoic29tZSBuYW1lIiwgImhleCI6ImZmZmZmZmYifQ==
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Base64;
import java.util.Objects;
#RestController
public class RestController {
#GetMapping("/example")
public void example(String params) {
String decoded = decodeBase64(params);
SomeDto dto = parseTo(decodedFilters, SomeDto.class);
}
public String decodeBase64(String encoded) {
if (Objects.nonNull(encoded)) {
return new String(Base64.getDecoder().decode(encoded));
}
return "";
}
public <T> T parseTo(String jsonAsString, Class<T> classType) {
String toParse = Objects.nonNull(jsonAsString) ? jsonAsString : "{}";
try {
return new ObjectMapper().readValue(toParse, classType);
} catch (IOException e) {
throw new ValidationException(e.getMessage());
}
}
}

Unsupported Media Type while hitting my JAVA api through Postman

I am a beginner in REST-api development and I am facing this error : "Unsupported Media Type" while hitting my java api through postman. My Pojo Class is :
public class OrderRequest implements Serializable{
private static final long serialVersionUID = 1L;
public OrderRequest() {}
private long orderNo;
private int rateOverallExperience;
private String apiName;
private Double apiVersion;
public long getOrderNo() {
return orderNo;
}
public int getRateOverallExperience() {
return rateOverallExperience;
}
public String getApiName() {
return apiName;
}
public Double getApiVersion() {
return apiVersion;
}
public void setOrderNo(long orderNo) {
this.orderNo = orderNo;
}
public void setRateOverallExperience(int rateOverallExperience) {
this.rateOverallExperience = rateOverallExperience;
}
public void setApiName(String apiName) {
this.apiName = apiName;
}
public void setApiVersion(Double apiVersion) {
this.apiVersion = apiVersion;
}
}
My controller class for this is :
#RestController
public class OrderRatingController {
public OrderRatingController() {}
#Autowired
private OrderRequestService ordRequestService;
#Autowired
private ProductRatingService prdRatingService;
#RequestMapping(value = "/saveOrderRatings", method = RequestMethod.POST
,consumes = MediaType.APPLICATION_JSON_VALUE) //"application/json"
public OrderRequest saveOrder(#RequestBody OrderRequest requestObj) {
System.out.println("Inside saveOrder. Json Object recieved : " + requestObj);
//...OTHER CODE...
return requestObj;
}
}
I am using Jetty server(version:9.4.0.M0) to test my api.
In Postman>Body tab>raw , I have selected JSON(application/json) and sending :
{
"orderNo" : "737521F547D00D26",
"rateOverallExperience" : 4,
"apiName": "giveitemrating",
"apiVersion":"1.0"
}
Postman Header related details in a pic/snap:
When I am sending this, I get an Unsupported Media Type error. Anyone has any idea about this?
EDIT : As suggested in the comments, Updated controller class a follows : #RequestMapping(value = "/saveOrderRatings", method = RequestMethod.POST
,consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, headers = "Accept=application/json")
Further added a header in POSTMAN gui : Accept with value application/json .
This is how postman request looks like after sending the request(still showing the error but change in resultant headers) :
enter image description here
You shouldn't need to configure the consumes or produces attribute at all. Spring will automatically serve JSON based on the following factors.
The accepts header of the request is application/json
#ResponseBody annotated method
Jackson library on classpath
You can use the #RestController instead of #Controller annotation.

How to pass my object via RestTemplate

I'm making simple REST service and the client for it. I try to make some kind of security, so I generate UUID just, when you go to /login site:
#RequestMapping("/login")
public uuid getUUID()
{
temp = new uuid();
return temp;
}
Then by the client side I get this UUID. Now I want to pass this UUID to my service "getPerson" which looks like this:
#RequestMapping("/{userId}/getperson")
public Person getPerson(#PathVariable("userId") int user, uuid uuid)
{
if(System.currentTimeMillis() - uuid.getDate().getTime() < 60000 &&
uuid.getHash().toString().equals(temp.toString()))
return personService.getPerson(user);
else
return null;
}
What I wanted to achieve is a simple validation of UUID by comparing its timestamps and Strings with the previously made temp object. And here is my problem - I don't know how to pass the object uuid from client.
My very sophisticated client looks like this:
RestTemplate restTemplate = new RestTemplate();
uuid myUUID = restTemplate.getForObject("http://localhost:8080/login", uuid.class);
HttpEntity<uuid> requestUUID = new HttpEntity<uuid>(myUUID);
//HttpEntity<Person> request = new HttpEntity<Person>(new Person("John", "Great", 2));
//restTemplate.postForObject("http://localhost:8080/addperson", request, Person.class);
Person person = restTemplate.postForObject("http://localhost:8080/2/getperson", requestUUID, Person.class);
I don't know if this type of validation is safe, but would be great if you could tell me how to pass my object.
I found simple solution below,
It is the concept which i shown below
import java.util.UUID;
public class Person {
private UUID uuid;
public Person() {
}
public Person(UUID uuid) {
super();
this.uuid = uuid;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
#Override
public String toString() {
return "Person [uuid=" + uuid + "]";
}
}
Controller IWebExample Interface:
import java.util.UUID;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
public interface IWebExample {
#RequestMapping(value = "/login", method = RequestMethod.GET)
#ResponseBody
UUID getUUID();
#RequestMapping(value = "/{userId}/getPerson", method = RequestMethod.POST)
#ResponseBody
Person getPerson(int userId, UUID uuid);
}
Controller Implementation
import java.util.UUID;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import com.finvendor.serverwebapi.resources.example.IWebExample;
import com.finvendor.serverwebapi.resources.example.Person;
#Controller
public class WebExampleImpl implements IWebExample {
#Override
public UUID getUUID() {
return UUID.randomUUID();
}
#Override
public Person getPerson(#PathVariable("userId") int userId, #RequestBody UUID uuid) {
return new Person(uuid);
}
}
Client code:
import java.util.UUID;
import org.springframework.web.client.RestTemplate;
public class ClientMainApp {
public static void main(String[] args) {
RestTemplate template=new RestTemplate();
UUID uuid = template.getForObject("http://localhost:8080/mylogin",UUID.class);
System.out.println("UUID="+uuid);
//here i am passing uuid object (as per your requirement)
Person person = template.postForObject("http://localhost:8080/1/getPerson", uuid, Person.class);
System.out.println(person);
}
}
Step to run
-Create war file
-Deploy in tomcat and
-Run the client code
Output would be:
UUID=e1e89e96-8118-446c-900d-d123b1b566ea
Person [uuid=e1e89e96-8118-446c-900d-d123b1b566ea]
In output you can observe we pass object uuid in postForObject(...) rest template method in client code.
The bottom line of solution of your problem is you need to use #RequestBody for uuid input param
Hope you got the idea and solution!!

NullPointer when soap message invokes web service

Trying to consume a webservice using spring integration ws, On the webservice end i get a null pointer as it seems the object passed isnt been marshalled or not mapped in the xml, Below is the snippet of the client calling invoking the service .
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("springws.xml");
MessageChannel channel = context.getBean("request", MessageChannel.class);
String body = "<getPojo xmlns=\"http://johnson4u.com/\"><pojo>\n"
+ " <pojoId>23</pojoId>\n"
+ " <pojoName>dubic</pojoName>\n"
+ "</pojo></getPojo>";
MessagingTemplate messagingTemplate = new MessagingTemplate();
Message<?> message = messagingTemplate.sendAndReceive(
channel, MessageBuilder.withPayload(body).build());
System.out.println(message.getPayload());
}
The WSDL is genrated by the JAxWS endpoint class
package com.johnson4u;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
#WebService(serviceName = "SpringService")
public class SpringService {
#WebMethod(operationName = "getPojo" )
public Pojo getPojo(#WebParam(Pojo pjRequest){
//Null Pointer occurs here as pjRequest might not be mapped to xml
System.out.println("Pojo name is "+pjRequest.getPojoName());
return new Pojo(234,"IM new Pojo");
}
And the POJO
package com.johnson4u;
public class Pojo {
private int pojoId;
private String pojoName;
public Pojo(int pojoId, String pojoName) {
this.pojoId = pojoId;
this.pojoName = pojoName;
}
public int getPojoId() {
return pojoId;
}
public void setPojoId(int pojoId) {
this.pojoId = pojoId;
}
public String getPojoName() {
return pojoName;
}
public void setPojoName(String pojoName) {
this.pojoName = pojoName;
}
Unfortunately,stackoverflow cant format the wsdl properly, but the namespace id are based on the package name com.johnson4u, below is spring-ws-context.xml
<int:channel id="request" />
<int:channel id="response" />
<ws:outbound-gateway id="gateway"
request-channel="request"
uri="http://localhost:20151/SpringWs/SpringService?wsdl"/>
i believe the string body should be
String body = "<ns:getPojo xmlns:ns=\"http://johnson4u.com/\"><pojo>\n"
+ " <pojoId>23</pojoId>\n"
+ " <pojoName>dubic</pojoName>\n"
+ "</pojo><ns:/getPojo>";
the namespace notation 'ns' was not included
I believe for the object to be un-marshalled you need to specify the element in the object class.
public class Pojo {
#XmlElement(name="pojoId", required=true, namespace=YOUR_NAME_SPACE)
private int pojoId;
#XmlElement(name="pojoName", required=true, namespace=YOUR_NAME_SPACE)
private String pojoName;
// Getters and Setters ......
}
I changed web param value to
#WebMethod(operationName = "getPojo" )
public Pojo getPojo(#WebParam(name = "pojo") Pojo pjRequest){
System.out.println("Pojo name is "+pjRequest.getPojoName());
return new Pojo(234,"IM new Pojo");
}
}
and xml request to
String body = "<ns0:getPojo xmlns:ns0=\"http://johnson4u.com/\">\n" +
" <pojo>"
+ "<pojoId>456</pojoId>"
+"<pojoName>Johnson</pojoName>"
+ "</pojo>\n" +
" </ns0:getPojo>";

Categories

Resources