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

Reply via email to