title: Appcelerator Titanium - Need Java WebService to receive JavaScript/JSON object and return JSON/XML
body: <p>I need a <strong>Java</strong> WebService that can be used with <strong>Appcelerator Titanium</strong>.</p>
  
  <p>I need to be able to <strong>send</strong> a JavaScript or JSON object and <strong>receive</strong> a JSON object or XML.</p>
  
  <p>I've tried Jax-WS, Jax-RS and Axis2 but no luck. However, if you know how to make it work with any of them, maybe I did something wrong and could use the help to make it work.</p>
  
  <p>Otherwise, does anyone know of a good option?</p>
  
  <p>Thanks in advance.</p>
  
  <p>--- EDIT ---
  @pace</p>
  
  <p>Here's what I tried using JAX-RS but I <strong>can't receive</strong> a <strong>JSON object</strong> from a <strong>POST</strong> method with it.</p>
  
  <pre><code>   @Path("/getUserByName")
     @POST
     @Consumes("application/json")
     @Produces("application/json")
     public Person getUserByName(@PathParam("name")String name, @PathParam("lastname")String lastname) {
         return new Person(name, 23, lastname);
     }
  </code></pre>
  
  <p>I'm calling the WS with HTTPRequest but that doesn't allow me to send a JSON object.
  Any ideas?</p>
  
  <p>--- EDIT 2 ---</p>
  
  <pre><code>var xhr = Titanium.Network.createHTTPClient();
  xhr.setRequestHeader('Content-Type', 'application/json');
  var url = 'http://10.0.0.114:8080/ClippingExpressMobileWS-JaxRS/usuario/getUsuarioPorNome';
  var method = 'POST';
  
  xhr.open('POST', url);
  
  xhr.onload = function() { 
  
      var json = this.responseText;
  
      //This is just a printf() or a System.out.println()
      Ti.API.info(json);
  }
  xhr.onerror = function(e) { 
  
      alert(e); 
  }
  
  var obj = {name: 'Roger', abe: 22, lastname: 'Waters'};
  
  //Then I've tried this:
  xhr.send(obj); //This doesn't give any errors on the WS, but the xhr.onerror function is called.
  //And this:
  xhr.send(JSON.stringify(obj)); //This gives the error blow.
  </code></pre>
  
  <p>-- Error thrown by xhr.send(JSON.stringify(obj))</p>
  
  <pre><code>A message body reader for Java class br.com.clippingexpressmobilews.entidades.Pessoa, and Java type class br.com.clippingexpressmobilews.entidades.Pessoa, and MIME media type application/octet-stream was not found.
  The registered message body readers compatible with the MIME media type are:
  [1/20/12 2:17:59 PM] Natália Oliveira: Jan 20, 2012 2:11:29 PM com.sun.jersey.spi.container.ContainerRequest getEntity
  SEVERE: A message body reader for Java class br.com.clippingexpressmobilews.entidades.Pessoa, and Java type class br.com.clippingexpressmobilews.entidades.Pessoa, and MIME media type application/octet-stream was not found.
  The registered message body readers compatible with the MIME media type are:
  application/octet-stream -&gt;
    com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
    com.sun.jersey.core.impl.provider.entity.FileProvider
    com.sun.jersey.core.impl.provider.entity.InputStreamProvider
    com.sun.jersey.core.impl.provider.entity.DataSourceProvider
    com.sun.jersey.core.impl.provider.entity.RenderedImageProvider
  */* -&gt;
    com.sun.jersey.core.impl.provider.entity.FormProvider
    com.sun.jersey.core.impl.provider.entity.StringProvider
    com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
    com.sun.jersey.core.impl.provider.entity.FileProvider
    com.sun.jersey.core.impl.provider.entity.InputStreamProvider
    com.sun.jersey.core.impl.provider.entity.DataSourceProvider
    com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
    com.sun.jersey.core.impl.provider.entity.ReaderProvider
    com.sun.jersey.core.impl.provider.entity.DocumentProvider
    com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
    com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
    com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
    com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
    com.sun.jersey.core.impl.provider.entity.EntityHolderReader
    com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
    com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
    com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy
  </code></pre>
  
  <p>Again, any ideas? 
  And thanks very much for the assistance! </p>