You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gabo Manuel <km...@solegysystems.com> on 2008/10/15 07:21:22 UTC

[REST][HTTP-BINDING]Service does not receive Post parameter

Hi guys,

I have a rest service using http binding as discussed in 
http://cwiki.apache.org/CXF20DOC/http-binding.html. I already have the 
retrieval working fine and any transaction that relies on the query 
string as method parameter. Below is a snippet of code:

AccountService.java
package some.package;
import org.codehaus.jra.Post;
import javax.jws.WebParam;
import javax.jws.WebService;
//there are other imports which are no longer included here for briefness

@WebService(serviceName="AccountService")
@Features(features="org.apache.cxf.feature.LoggingFeature")
public class AccountService {
//snip
   @Post
   @HttpResource(location = "/Account")
   @WebResult(name="serialNumber")
   public long insert(
           @WebParam(name="account")
           Account account
           ) {
       logger.info("Insert Received: " + account);
       return 0;
   }

beans.xml

   <jaxws:endpoint
       id="accountRestService"
       address="/rest/Accounts"
       bindingUri="http://apache.org/cxf/binding/http"
       implementor="some.package.AccountService"
       >
     <jaxws:serviceFactory>
       <bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
          <property name="wrapped" value="true" />
       </bean>
     </jaxws:serviceFactory>
   </jaxws:endpoint>

I am currently trying to access the said service with 
org.apache.commons.httpclient.HttpClient using 
org.apache.commons.httpclient.methods.PostMethod. I followed the code 
present in the samples demo.jaxrs.client.Client.java:

TestClient.java
       PostMethod method = new 
PostMethod("http://localhost:8081/cxf/services/rest/Accounts/Account/");
       method.setRequestHeader("username", "joe");

       RequestEntity entity = new FileRequestEntity(
               new File("D:/code/ws/rest/Account.txt"),
               "text/xml; charset=ISO-8859-1");

       int result = client.executeMethod(method);
       System.out.println("Transaction result: " + result);
       System.out.println("Response message is: \r\n" + 
method.getResponseBodyAsString());

Account.txt
<tns:Account xmlns:tns="http://package.some/">
<tns:accountID>someVal</tns:accountID>
<!-- other fields here -->
</Account>

The call goes through without a hitch, but the method always receives a 
null value for the parameter. I used tcpmon to check the value being sent:

POST /cxf/services/rest/Accounts/Account/ HTTP/1.1
username: joe
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8081
Content-Length: 1551
Content-Type: text/xml; charset=ISO-8859-1

<tns:Account xmlns:tns="http://account.subscriber.ws.solegy.com/">
<tns:accountID>someVal</tns:accountID>
<!-- other fields here -->
</tns:Account>

Server-side, I always get this:

[INFO ][80-2][                AccountService] | Insert Received: null

I am currently using cxf-2.1.2.jar running on apache-tomcat-6.0.13. I am 
almost certain I am missing something. Unfortunately, there is no sample 
post transaction that involves a custom object in the link mentioned above.
I also tried searching through the archive that could possibly relate to 
this, I wasn't able to find anything (or I missed it).

Thanks in advance.

Gabo Manuel


RE: [REST][HTTP-BINDING]Service does not receive Post parameter

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi Sergey,

Sergey Beryozkin-2 wrote:
> 
> Please consider moving to JAX-RS, you won't lose, and
> there's a bunch of JAX-RS implementations is available...
> 

Thanks for the reply.

Actually, I started out with CXF with jax-rs in mind. Then I encountered
several problems trying to set-up the same simple service. I followed what
was stated in the guide:
http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html

AccountService.java
----
package some.package;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;

@Path("/rest/Accounts")
@ProduceMime("application/xml")
public class AccountService {
	@GET
	@Path("/Account/{uniqueId}")
	public Account get(
			@PathParam("uniqueId")
			long uniqueId
			) {
		logger.info("get received: " + uniqueId);
		try{
			return generateAccount();
		} finally {
		}
	}
	//other methods here...
}

beans.xml as follows:
	<jaxrs:server id="accountRestService" address="/rest/Accounts">
		<jaxrs:serviceBeans>
			<ref bean="accountServiceClass" />
		</jaxrs:serviceBeans>
	</jaxrs:server>

	<bean id="accountServiceClass" class="some.package.AccountService" />

Account.java:
@XmlRootElement
public class Account {
	//fields go here
}

I fire up tomcat, nothing works. Even worse, the soap endpoint is also
inaccessible. List of services is also inaccessible. When I look at the root
directory http://localhost:8080/cxf/services/ I get the following:

java.lang.NullPointerException

org.apache.cxf.service.model.EndpointInfo.getInterface(EndpointInfo.java:54)

I could be missing something simple. Searching across the web has not helped
me for the past few days. I might consider recreating everything from
scratch again for an attempt for jax-rs implementation.

Any help on the error above would be help. Might also just start another
thread since the subject would eventually become misleading...
-- 
View this message in context: http://www.nabble.com/-REST--HTTP-BINDING-Service-does-not-receive-Post-parameter-tp19986914p19991022.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: [REST][HTTP-BINDING]Service does not receive Post parameter

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

If you do want to continue with HTTP binding then most likely you'll
have to sort out all the issues on your own, it's not actively
maintained. Please consider moving to JAX-RS, you won't lose, and
there's a bunch of JAX-RS implementations is available...

Cheers, Sergey


-----Original Message-----
From: Gabo Manuel [mailto:kmanuel@solegysystems.com] 
Sent: 15 October 2008 06:56
To: users@cxf.apache.org
Subject: Re: [REST][HTTP-BINDING]Service does not receive Post parameter


I ended up answering my own question... Still wondering if there is a
better
solution.

Got the "solution" from:

http://www.nabble.com/Restful-HTTP-Binding%3A-Wrapped-Mode---Put-Method-
td19082206.html#a19082206

I modified the client as follows:

method.setRequestBody(readFile("D:/code/ws/rest/Account.txt"));
int result = client.executeMethod(method);

I also had to modify the content of Account.txt as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<tns:insert xmlns:tns="http://account.subscriber.ws.solegy.com/">
<tns:account >
<tns:accountID>someVal</tns:accountID>
<!-- other fields go here -->
</tns:account>
</tns:insert>

"account" tag is case-sensitive and should match as stated in the wsdl.

Now, considering that the said method is deprecated, I am wondering if
there
is a solution which uses the non-deprecated methods. (now with that
irritating feeling im missing something extremely basic)

Atleast now I could move forward...
:clap:
-- 
View this message in context:
http://www.nabble.com/-REST--HTTP-BINDING-Service-does-not-receive-Post-
parameter-tp19986914p19987189.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: [REST][HTTP-BINDING]Service does not receive Post parameter

Posted by Gabo Manuel <km...@solegysystems.com>.
I ended up answering my own question... Still wondering if there is a better
solution.

Got the "solution" from:

http://www.nabble.com/Restful-HTTP-Binding%3A-Wrapped-Mode---Put-Method-td19082206.html#a19082206

I modified the client as follows:

method.setRequestBody(readFile("D:/code/ws/rest/Account.txt"));
int result = client.executeMethod(method);

I also had to modify the content of Account.txt as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<tns:insert xmlns:tns="http://account.subscriber.ws.solegy.com/">
<tns:account >
<tns:accountID>someVal</tns:accountID>
<!-- other fields go here -->
</tns:account>
</tns:insert>

"account" tag is case-sensitive and should match as stated in the wsdl.

Now, considering that the said method is deprecated, I am wondering if there
is a solution which uses the non-deprecated methods. (now with that
irritating feeling im missing something extremely basic)

Atleast now I could move forward...
:clap:
-- 
View this message in context: http://www.nabble.com/-REST--HTTP-BINDING-Service-does-not-receive-Post-parameter-tp19986914p19987189.html
Sent from the cxf-user mailing list archive at Nabble.com.