[英]Error in consuming XML data Content type 'application/xml;charset=utf-8' not supported spring
I am trying to process the request with XML Data getting error as我正在尝试使用 XML 处理请求数据获取错误为
RecurlyController.processEvents(java.lang.Object,javax.servlet.http.HttpServletRequest)]:
org.springframework.web.HttpMediaTypeNotSupportedException:
Controller Controller
I want XML data of any structure that's why I am using Object in request我想要任何结构的 XML 数据,这就是为什么我在请求中使用 Object
@RequestMapping(value = "events", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public ModelAndView processEvents(@RequestBody Object recurlyEvent, HttpServletRequest request {
Response response = recurlyManager.processEvents(recurlyEvent);
return prepareModelAndView(response);
}
Http request to spring app using postman Http 请求使用 spring 应用程序使用 postman
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<new_subscription_notification>\n <account>\n <account_code>1</account_code>\n <username nil=\"true\">verena</username>\n <email>verena@example.com</email>\n <first_name>Verena</first_name>\n <last_name>Example</last_name>\n <company_name nil=\"true\">Company, Inc.</company_name>\n </account>\n <subscription>\n <plan>\n <plan_code>bronze</plan_code>\n <name>Bronze Plan</name>\n </plan>\n <uuid>8047cb4fd5f874b14d713d785436ebd3</uuid>\n <state>active</state>\n <quantity type=\"integer\">2</quantity>\n <total_amount_in_cents type=\"integer\">17000</total_amount_in_cents>\n <subscription_add_ons type=\"array\">\n <subscription_add_on>\n <add_on_code>premium_support</add_on_code>\n <name>Premium Support</name>\n <quantity type=\"integer\">1</quantity>\n <unit_amount_in_cents type=\"integer\">15000</unit_amount_in_cents>\n <external_sku>pre-123</external_sku>\n <add_on_type>fixed</add_on_type>\n <usage_percentage nil=\"true\"></usage_percentage>\n <measured_unit_id nil=\"true\"></measured_unit_id>\n </subscription_add_on>\n <subscription_add_on>\n <add_on_code>email_blasts</add_on_code>\n <name>Email Blasts</name>\n <quantity type=\"integer\">1</quantity>\n <external_sku>email-123</external_sku>\n <unit_amount_in_cents type=\"integer\">50</unit_amount_in_cents>\n <add_on_type>usage</add_on_type>\n <usage_percentage nil=\"true\"></usage_percentage>\n <measured_unit_id type=\"integer\">394681687402874853</measured_unit_id>\n </subscription_add_on>\n <subscription_add_on>\n <add_on_code>donations</add_on_code>\n <name>Donations</name>\n <quantity type=\"integer\">1</quantity>\n <unit_amount_in_cents nil=\"true\"></unit_amount_in_cents>\n <add_on_type>usage</add_on_type>\n <usage_percentage>0.6</usage_percentage>\n <measured_unit_id type=\"integer\">394681920153192422</measured_unit_id>\n </subscription_add_on>\n </subscription_add_ons>\n <activated_at type=\"datetime\">2009-11-22T13:10:38Z</activated_at>\n <canceled_at type=\"datetime\"></canceled_at>\n <expires_at type=\"datetime\"></expires_at>\n <current_period_started_at type=\"datetime\">2009-11-22T13:10:38Z</current_period_started_at>\n <current_period_ends_at type=\"datetime\">2009-11-29T13:10:38Z</current_period_ends_at>\n <trial_started_at type=\"datetime\">2009-11-22T13:10:38Z</trial_started_at>\n <trial_ends_at type=\"datetime\">2009-11-29T13:10:38Z</trial_ends_at>\n <collection_method>automatic</collection_method>\n </subscription>\n</new_subscription_notification>");
Request request = new Request.Builder()
.url("http://a346f04e.ngrok.io")
.method("POST", body)
.addHeader("Content-Type", "application/xml")
.build();
Response response = client.newCall(request).execute();
For someone looking for an answer to a similar question.对于寻找类似问题答案的人。 Removing consumes worked for me.
消除消耗对我有用。
@RequestMapping(value = "events", method = RequestMethod.POST)
public ModelAndView processEvents(@RequestBody String recurlyEvent, HttpServletRequest request {
Response response = recurlyManager.processEvents(recurlyEvent);
return prepareModelAndView(response);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.