Note that there are some explanatory texts on larger screens.

plurals
  1. POStruggled with Content-Type "application/x-www-form-urlencoded" in REST webservices
    text
    copied!<p>Thanks in advance for providing your advices on the following problem I am facing with CXF REST providers.</p> <p>I have developed REST web service server using Apache CXF. Following is the contract definition. Please note this is used in Camel context.</p> <pre><code>public class PaymentSandboxService { @POST @Consumes({"application/json", "application/x-www-form-urlencoded"}) @Produces({"application/json", "application/x-www-form-urlencoded"}) @Path("/2_1/payment/{endUserId}/transactions/amount") public Response charge(@Body final AmountTransaction amountTransaction, @PathParam("endUserId") final String endUserId) throws IOException { return null; } } </code></pre> <p>Following are my bean definitions:</p> <pre><code> &lt;cxf:rsServer id="rsServer" address="/{{publicAddress}}" serviceClass="a.b.cPaymentSandboxService" loggingFeatureEnabled="true"&gt; &lt;cxf:providers&gt; &lt;ref bean="jsonProvider" /&gt; &lt;ref bean="formUrlEncodeProvider" /&gt; &lt;/cxf:providers&gt; &lt;/cxf:rsServer&gt; &lt;bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider"&gt; &lt;property name="marshallAsJaxbElement" value="true" /&gt; &lt;/bean&gt; &lt;bean id="formUrlEncodeProvider" class="org.apache.cxf.jaxrs.provider.FormEncodingProvider" /&gt; </code></pre> <p>When I send a request with Content-Type 'application/json' everything works fine. But when a request is sent with the Content-Type 'application/x-www-form-urlencoded', request hits the server but it failed while converting body to the required datatype. Following is the part of log I am getting in Fuse esb log.</p> <h1>Part of Log:</h1> <pre><code>ID: 17 Address: http://cnb69:8181/cxf/paymentsandbox/2_1/payment/tel:+916309700000/transactions/amount Encoding: ISO-8859-1 Http-Method: POST Content-Type: application/x-www-form-urlencoded Headers: {Accept=[application/json], accept-encoding=[gzip,deflate], Authorization=[Basic a2FzdW5wYXlzYW5kYm94OnBANTV3MHJk], connection=[keep-alive], Content-Length=[670], content-type=[application/x-www-form-urlencoded], Host=[cnb69:8181], User-Agent=[Apache-HttpClient/4.1.1 (java 1.5)]} Payload: { "amountTransaction": { "clientCorrelator": "54321", "endUserId": "tel:+916309700000", "paymentAmount": { "chargingInformation": { "amount": "10.2662", "currency": "USD", "description": [ "Alien Invaders Game" ] }, "chargingMetaData": { "onBehalfOf": "Example Games Inc", "purchaseCategoryCode": "Game", "channel": "SMS", "taxAmount": "0" } }, "referenceCode": "REF-12345", "transactionOperationStatus": "CHARGED" } } -------------------------------------- 2013-07-05 13:44:27,477 | WARN | qtp1316166688-257 | org.apache.cxf.jaxrs.utils.JAXRSUtils | No message body reader has been found for request class AmountTransaction, ContentType : application/x-www-form-urlencoded. 2013-07-05 13:44:27,478 | INFO | qtp1316166688-257 | org.apache.cxf.interceptor.AbstractLoggingInterceptor | Outbound Message --------------------------- ID: 17 Response-Code: 415 Content-Type: text/xml Headers: {Date=[Fri, 05 Jul 2013 08:14:27 GMT], Content-Length=[0]} -------------------------------------- </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload