java - Unable to pass @FormParam to jersey server with jersey 1.x and spring 4 -


i getting java.lang.illegalargumentexception: error parsing media type 'application/json, application/x-www-form-urlencoded' when trying pass x-www-form-urlencoded resource class

stack trace

javax.ws.rs.webapplicationexception: java.lang.illegalargumentexception: error parsing media type 'application/json, application/x-www-form-urlencoded'     @ com.sun.jersey.server.impl.model.httphelper.clienterror(httphelper.java:265)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:91)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:77)     @ com.sun.jersey.spi.container.containerrequest.getmediatype(containerrequest.java:646)     @ com.sun.jersey.spi.container.servlet.webcomponent.filterformparameters(webcomponent.java:832)     @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:407)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:538)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:716)     @ javax.servlet.http.httpservlet.service(httpservlet.java:820)     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:652)     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:445)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137)     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:556)     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:227)     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1044)     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:372)     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:189)     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:978)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135)     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255)     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154)     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116)     @ org.eclipse.jetty.server.server.handle(server.java:367)     @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:486)     @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:937)     @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:998)     @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:861)     @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:240)     @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82)     @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:628)     @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52)     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608)     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543)     @ java.lang.thread.run(thread.java:745) caused by: java.lang.illegalargumentexception: error parsing media type 'application/json, application/x-www-form-urlencoded'     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:79)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:53)     @ javax.ws.rs.core.mediatype.valueof(mediatype.java:119)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:89)     ... 32 more caused by: java.text.parseexception: expected separator ';' instead of ','     @ com.sun.jersey.core.header.reader.httpheaderreader.nextseparator(httpheaderreader.java:117)     @ com.sun.jersey.core.header.reader.httpheaderreader.readparameters(httpheaderreader.java:239)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.valueof(mediatypeprovider.java:97)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:77)     ... 35 more caused by:  java.lang.illegalargumentexception: error parsing media type 'application/json, application/x-www-form-urlencoded'     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:79)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:53)     @ javax.ws.rs.core.mediatype.valueof(mediatype.java:119)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:89)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:77)     @ com.sun.jersey.spi.container.containerrequest.getmediatype(containerrequest.java:646)     @ com.sun.jersey.spi.container.servlet.webcomponent.filterformparameters(webcomponent.java:832)     @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:407)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:538)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:716)     @ javax.servlet.http.httpservlet.service(httpservlet.java:820)     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:652)     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:445)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137)     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:556)     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:227)     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1044)     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:372)     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:189)     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:978)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135)     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255)     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154)     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116)     @ org.eclipse.jetty.server.server.handle(server.java:367)     @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:486)     @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:937)     @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:998)     @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:861)     @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:240)     @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82)     @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:628)     @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52)     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608)     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543)     @ java.lang.thread.run(thread.java:745) caused by: java.text.parseexception: expected separator ';' instead of ','     @ com.sun.jersey.core.header.reader.httpheaderreader.nextseparator(httpheaderreader.java:117)     @ com.sun.jersey.core.header.reader.httpheaderreader.readparameters(httpheaderreader.java:239)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.valueof(mediatypeprovider.java:97)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:77)     ... 35 more caused by:  java.text.parseexception: expected separator ';' instead of ','     @ com.sun.jersey.core.header.reader.httpheaderreader.nextseparator(httpheaderreader.java:117)     @ com.sun.jersey.core.header.reader.httpheaderreader.readparameters(httpheaderreader.java:239)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.valueof(mediatypeprovider.java:97)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:77)     @ com.sun.jersey.core.impl.provider.header.mediatypeprovider.fromstring(mediatypeprovider.java:53)     @ javax.ws.rs.core.mediatype.valueof(mediatype.java:119)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:89)     @ com.sun.jersey.server.impl.model.httphelper.getcontenttype(httphelper.java:77)     @ com.sun.jersey.spi.container.containerrequest.getmediatype(containerrequest.java:646)     @ com.sun.jersey.spi.container.servlet.webcomponent.filterformparameters(webcomponent.java:832)     @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:407)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:538)     @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:716)     @ javax.servlet.http.httpservlet.service(httpservlet.java:820)     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:652)     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:445)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137)     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:556)     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:227)     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1044)     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:372)     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:189)     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:978)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135)     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255)     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154)     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116)     @ org.eclipse.jetty.server.server.handle(server.java:367)     @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:486)     @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:937)     @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:998)     @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:861)     @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:240)     @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82)     @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:628)     @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52)     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608)     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543)     @ java.lang.thread.run(thread.java:745) 

java resource class code:

@path("/initiate")   @post   @consumes({mediatype.application_form_urlencoded})   public void initiate(@formparam("id") string transactionid) throws ioexception {     logger.info("transactionid : " + transactionid);     // logic    } 

pom.xml dependencies:

<!-- jersey dependencies -->     <dependency>       <groupid>com.sun.jersey</groupid>       <artifactid>jersey-server</artifactid>       <version>1.13</version>     </dependency>     <dependency>       <groupid>com.sun.jersey</groupid>       <artifactid>jersey-bundle</artifactid>       <version>1.13</version>     </dependency>     <dependency>       <groupid>com.sun.jersey</groupid>       <artifactid>jersey-json</artifactid>       <version>1.13</version>     </dependency>     <dependency>       <groupid>com.sun.jersey</groupid>       <artifactid>jersey-client</artifactid>       <version>1.13</version>       <scope>test</scope>     </dependency>      <!-- jersey spring -->     <dependency>       <groupid>com.sun.jersey.contribs</groupid>       <artifactid>jersey-spring</artifactid>       <version>1.13</version>       <exclusions>         <exclusion>           <groupid>com.sun.jersey</groupid>           <artifactid>jersey-server</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring-core</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring-beans</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring-context</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring-web</artifactid>         </exclusion>         <exclusion>           <groupid>org.springframework</groupid>           <artifactid>spring-aop</artifactid>         </exclusion>       </exclusions>     </dependency>       <!-- spring framework dependencies -->    <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-context</artifactid>       <version>4.2.1.release</version>     </dependency>     <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-webmvc</artifactid>       <version>4.2.1.release</version>     </dependency>     <dependency>       <groupid>org.springframework</groupid>       <artifactid>spring-orm</artifactid>       <version>4.2.1.release</version>       <type>jar</type>       <scope>compile</scope>     </dependency> 

i did lot of google search unable find similar question , new spring , jersey. please help.

i had pre-saved content-type:application/json. because of content-type: application/json, application/x-www-form-urlencoded getting passed content-type. fixed that. working fine now.


Comments