You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by imiten <im...@yahoo.com> on 2012/04/26 14:01:07 UTC

form post to restful service not finding matching method

Hi,

I have below method defined so I can use form post to Restful webmethod. 
But the service cannot map the path to any matching method.  Other methods
which are not form consumers work fine.

does not work for url in form action:
"/mkyong_webapp/services/rest/product/product_id".  I have even tried
changing to @Path("/form/product_id") and corresponding action to
"/mkyong_webapp/services/rest/product/form/product_id" but they do not match
any method.  am I missing some thing ?

@Path("/product_id")
@POST
@Produces("application/xml")
@Consumes("application/x-www-form-unrlencoded")
public Product getProductForm(@FormParam("product_id") int id) {
	// TODO Auto-generated method stub
	return productBo.getProduct(id);
}


example working method is for url
http://localhost:8080/mkyong_webapp/services/rest/product/list:
@GET
@Path("/list")
@Produces("application/xml")
public ProductContainer getProducts() {
	// TODO Auto-generated method stub
	ProductContainer pc = new ProductContainer();
	pc.p = productBo.getProducts();
	return pc;
}


Regards,

Miten.



--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667389.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

I am basic from web page itself.

<form method="post"
action="/mkyong_webapp/services/rest/product/product_id">
  <label>Product Id: </label><input type="text" name="product_id"
size="32"/>
  <input type="submit" value="submit"/>
</form>


Regards,

Miten.



--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667532.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

I am using application/x-www-form-urlencoded as mentioned on the @Consumes
annotation.  I was not able to quite understand what you tried to mean.

Regards,

Miten.

--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667514.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by Voß, Marko <Ma...@fiz-Karlsruhe.de>.
Hello Miten,

I would guess, that your form is using a different enctype than defined at the @Consumes annotation.

Please take a look here: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

Does your enctype equals "application/x-www-form-urlencoded" or "multipart/form-data"?


best regards,
Marko

Am 26.04.2012 14:01, schrieb imiten:
> Hi,
>
> I have below method defined so I can use form post to Restful webmethod.
> But the service cannot map the path to any matching method.  Other methods
> which are not form consumers work fine.
>
> does not work for url in form action:
> "/mkyong_webapp/services/rest/product/product_id".  I have even tried
> changing to @Path("/form/product_id") and corresponding action to
> "/mkyong_webapp/services/rest/product/form/product_id" but they do not match
> any method.  am I missing some thing ?
>
> @Path("/product_id")
> @POST
> @Produces("application/xml")
> @Consumes("application/x-www-form-unrlencoded")
> public Product getProductForm(@FormParam("product_id") int id) {
> 	// TODO Auto-generated method stub
> 	return productBo.getProduct(id);
> }
>
>
> example working method is for url
> http://localhost:8080/mkyong_webapp/services/rest/product/list:
> @GET
> @Path("/list")
> @Produces("application/xml")
> public ProductContainer getProducts() {
> 	// TODO Auto-generated method stub
> 	ProductContainer pc = new ProductContainer();
> 	pc.p = productBo.getProducts();
> 	return pc;
> }
>
>
> Regards,
>
> Miten.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667389.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Marko Voß
ePublishing & eScience
Development & Applied Research
Phone +49 7247 808-744
Fax +49 7247 808-133
marko.voss@fiz-karlsruhe.de


FIZ Karlsruhe - Leibniz Institute for Information Infrastructure
Hermann-von-Helmholtz-Platz 1
76344 Eggenstein-Leopoldshafen, Germany

www.fiz-karlsruhe.de


-------------------------------------------------------

Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische Information mbH. 
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 101892. 
Geschäftsführerin: Sabine Brünger-Weilandt. 
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.



Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

The SingleConnectionFactory exception has been resolved. DKulp guided that
it was due to shared location jars.  I removed cxf 2.5.2 in tomcat shared
libs and it resloved.

Regards,

Miten.

--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5670580.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi Sergey,

Sorry about the silly mistake and causing you to work through it.  This is
one think I dislike about config data - no compile type checks.

Well I do have the @FormParam web method working though I have run into
another issue related to jms.  Its probably related incorrect jars on
classpath.

java.lang.IllegalArgumentException: Cannot convert value of type
[org.springframework.jms.connection.SingleConnectionFactory] to required
type [javax.jms.ConnectionFactory] for property 'connectionFactory': no
matching editors or conversion strategy found


I searched web for issue but did not find any good solution. 

can you guide ?

Also, the web method was returning int which I was hoping to present as xml
but it was not doing so.  can you guide what annotation I can use to send it
as xml.

Regards,

Miten.

--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5670264.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 27/04/12 05:48, imiten wrote:
> Hi,
>
> Here is
> http://mama.indstate.edu/users/mehta/public_html/mkyong_webapp_sergy.jar
> link  to maven project created with just one method having @PostParam.  In
> project you also see the log.txt showing my run output.  Apart from this I
> want to know why my mvn tomcat:deploy/undeploy/redeploy fails.  It complains
> like application already exists.  I run tomcat 7.0.27 from within eclipse
> and maven from command line on win7.  I have jdk1.7.
>
> Please excuse my misspelling your name in project artifact.
>
Not a problem :-).
However, you did misspelled the value of @Consumes, note an extra 'n' in 
the 'urlnencoded' subtype.

Took me a bit of time to figure it out, but it was definitely not the 
lost time, given I found a bug in the JAXRSInInterceptor code which, 
fortunately, gets self-rectified by the code below which does a sanity 
check on the calculated accept types...

The other thing which I have not tested is that you return 'int' and 
have @Produces("application/xml") - the JAX-RS runtime would not 
auto-wrap the primitive types, it would probably work meaning the plain 
id value will be returned but the browser will complain...

Cheers, Sergey

> Regards,
>
> Miten.
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5669246.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

Here is 
http://mama.indstate.edu/users/mehta/public_html/mkyong_webapp_sergy.jar
link  to maven project created with just one method having @PostParam.  In
project you also see the log.txt showing my run output.  Apart from this I
want to know why my mvn tomcat:deploy/undeploy/redeploy fails.  It complains
like application already exists.  I run tomcat 7.0.27 from within eclipse
and maven from command line on win7.  I have jdk1.7.

Please excuse my misspelling your name in project artifact.

Regards,

Miten. 

--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5669246.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I'm not able to reproduce this issue in my local snapshot.
I've modified the existing test, here is the output:

Address: 
http://localhost:9002/mkyong_webapp/services/rest/product/product_id
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/x-www-form-urlencoded
Headers: 
{Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,], 
Cache-Control=[no-cache], connection=[keep-alive], Content-Length=[7], 
content-type=[application/x-www-form-urlencoded], Host=[localhost:9002], 
Pragma=[no-cache], User-Agent=[Apache CXF 2.6.1-SNAPSHOT]}
Payload: id=MyId

--------------------------------------
MyId
26-Apr-2012 22:09:47 org.apache.cxf.interceptor.LoggingOutInterceptor
INFO: Outbound Message
---------------------------
ID: 1
Response-Code: 204
Content-Type: text/xml
Headers: {Date=[Thu, 26 Apr 2012 21:09:47 GMT], Content-Length=[0]}
--------------------------------------
26-Apr-2012 22:09:47 
org.eclipse.jetty.server.handler.ContextHandler$Context log
INFO: Closing Spring root WebApplicationContext
26-Apr-2012 22:09:47 org.eclipse.jetty.server.handler.ContextHandler doStop
INFO: stopped 
o.e.j.w.WebAppContext{/mkyong_webapp,file:/home/sberyozkin/work/apache/cxf/trunk/systests/jaxrs/target/test-classes/jaxrs_soap_rest/},/home/sberyozkin/work/apache/cxf/trunk/systests/jaxrs/target/test-classes/jaxrs_soap_rest

where the test method is typed exactly the way you type it, with the 
context name, CXFServlet pattern, jaxrs:server/@address, root resource 
and method having the same path values.

I guess you have a slightly different case, probably Tomcat and the form 
is submitted from the HTML page, but to be honest it just has to work, I 
have few demos accepting form payloads...

Any chance you can create a simple Maven-based project for me to try ?

Sergey

On 26/04/12 14:03, imiten wrote:
> Hi,
>
> As I mentioned other urls are invoking methods fine.  Just the one with
> @FormParam is having this issue.
>
> CXFServlet urlpattern:
> <servlet-mapping>
>      <servlet-name>cxf</servlet-name>
>      <url-pattern>/services/*</url-pattern>
>    </servlet-mapping>
>
>
> cxf-servlet.xml server:
> <jaxrs:server id="myProductRest" address="/rest">
>      <jaxrs:serviceBeans>
>        <ref bean="myRestService" />
>      </jaxrs:serviceBeans>
>    </jaxrs:server>
>
> My Rest Web Service:
> @Path("/product")
> @Features(features = "org.apache.cxf.feature.LoggingFeature")
> public class ProductWebRest {
>
> Regards,
>
> Miten.
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667558.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

As I mentioned other urls are invoking methods fine.  Just the one with
@FormParam is having this issue.

CXFServlet urlpattern:
<servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>


cxf-servlet.xml server:
<jaxrs:server id="myProductRest" address="/rest">
    <jaxrs:serviceBeans>
      <ref bean="myRestService" />
    </jaxrs:serviceBeans>
  </jaxrs:server>
  
My Rest Web Service:
@Path("/product")
@Features(features = "org.apache.cxf.feature.LoggingFeature") 
public class ProductWebRest {

Regards,

Miten.


--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667558.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Can you confirm please you use jaxrs:server endpoints ?
let me know the URI pattern in CXFServlet and the jaxrs:server/address value

Thanks, Sergey
On 26/04/12 13:51, imiten wrote:
> Hi,
>
> Here is debug output.  I tried even without webapp context mkyong_webapp but
> it will then fail to even invoke the web service.
>
> INFO: Server startup in 14660 ms
> Apr 26, 2012 6:18:12 PM org.apache.cxf.interceptor.LoggingInInterceptor
> INFO: Inbound Message
> ----------------------------
> ID: 1
> Address:
> http://localhost:8080/mkyong_webapp/services/rest/product/product_id
> Encoding: ISO-8859-1
> Http-Method: POST
> Content-Type: application/x-www-form-urlencoded
> Headers:
> {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8],
> accept-encoding=[gzip, deflate], accept-language=[en-us,en;q=0.5],
> connection=[keep-alive], Content-Length=[13],
> content-type=[application/x-www-form-urlencoded],
> cookie=[csrftoken=dd2961f73dd7cee250b29c08d8a81827], host=[localhost:8080],
> referer=[http://localhost:8080/mkyong_webapp/product_id.html],
> user-agent=[Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101
> Firefox/12.0]}
> Payload: product_id=20
> --------------------------------------
> Apr 26, 2012 6:18:12 PM org.apache.cxf.jaxrs.utils.JAXRSUtils
> findTargetMethod
> WARNING: No operation matching request path
> "/mkyong_webapp/services/rest/product/product_id" is found, Relative Path:
> /product_id, HTTP Method: POST, ContentType:
> application/x-www-form-urlencoded, Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,. Please
> enable FINE/TRACE log level for more details.
> Apr 26, 2012 6:18:12 PM org.apache.cxf.interceptor.LoggingOutInterceptor
> INFO: Outbound Message
> ---------------------------
> ID: 1
> Response-Code: 415
> Content-Type: text/xml
> Headers: {Date=[Thu, 26 Apr 2012 12:48:12 GMT], Content-Length=[0]}
> --------------------------------------
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667509.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: form post to restful service not finding matching method

Posted by imiten <im...@yahoo.com>.
Hi,

Here is debug output.  I tried even without webapp context mkyong_webapp but
it will then fail to even invoke the web service.

INFO: Server startup in 14660 ms
Apr 26, 2012 6:18:12 PM org.apache.cxf.interceptor.LoggingInInterceptor
INFO: Inbound Message
----------------------------
ID: 1
Address:
http://localhost:8080/mkyong_webapp/services/rest/product/product_id
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/x-www-form-urlencoded
Headers:
{Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8],
accept-encoding=[gzip, deflate], accept-language=[en-us,en;q=0.5],
connection=[keep-alive], Content-Length=[13],
content-type=[application/x-www-form-urlencoded],
cookie=[csrftoken=dd2961f73dd7cee250b29c08d8a81827], host=[localhost:8080],
referer=[http://localhost:8080/mkyong_webapp/product_id.html],
user-agent=[Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101
Firefox/12.0]}
Payload: product_id=20
--------------------------------------
Apr 26, 2012 6:18:12 PM org.apache.cxf.jaxrs.utils.JAXRSUtils
findTargetMethod
WARNING: No operation matching request path
"/mkyong_webapp/services/rest/product/product_id" is found, Relative Path:
/product_id, HTTP Method: POST, ContentType:
application/x-www-form-urlencoded, Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,. Please
enable FINE/TRACE log level for more details.
Apr 26, 2012 6:18:12 PM org.apache.cxf.interceptor.LoggingOutInterceptor
INFO: Outbound Message
---------------------------
ID: 1
Response-Code: 415
Content-Type: text/xml
Headers: {Date=[Thu, 26 Apr 2012 12:48:12 GMT], Content-Length=[0]}
--------------------------------------

--
View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667509.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: form post to restful service not finding matching method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On 26/04/12 13:01, imiten wrote:
> Hi,
>
> I have below method defined so I can use form post to Restful webmethod.
> But the service cannot map the path to any matching method.  Other methods
> which are not form consumers work fine.
>
> does not work for url in form action:
> "/mkyong_webapp/services/rest/product/product_id".  I have even tried
> changing to @Path("/form/product_id") and corresponding action to
> "/mkyong_webapp/services/rest/product/form/product_id" but they do not match
> any method.  am I missing some thing ?

Probably to do with setting '/mkyong_webapp' in the form action value, 
not sure.
Try adding a CXF Logging Feature (within jaxrs:features block), that 
will give you the info about the request. Setting it log level to DEBUG 
would also provide all the info, but the logging feature is less verbose 
by default

Cheers, Sergey

>
> @Path("/product_id")
> @POST
> @Produces("application/xml")
> @Consumes("application/x-www-form-unrlencoded")
> public Product getProductForm(@FormParam("product_id") int id) {
> 	// TODO Auto-generated method stub
> 	return productBo.getProduct(id);
> }
>
>
> example working method is for url
> http://localhost:8080/mkyong_webapp/services/rest/product/list:
> @GET
> @Path("/list")
> @Produces("application/xml")
> public ProductContainer getProducts() {
> 	// TODO Auto-generated method stub
> 	ProductContainer pc = new ProductContainer();
> 	pc.p = productBo.getProducts();
> 	return pc;
> }
>
>
> Regards,
>
> Miten.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/form-post-to-restful-service-not-finding-matching-method-tp5667389p5667389.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com