title: JAXB, REST to send XML object to remote URL
body: <p>There seem to be so many versions out there. Here is what I am doing. I have a RESTful webservice, and am trying to marshall a Java object into JAXB and send it over the wire to a webservice. Here is my client side code</p>
  
  <pre><code> private static void performPost(JAXBObject obj) {
       String url ="http://www.example.com/test?xml=";
  
  
       HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
       urlConnection.setRequestMethod("POST");
       urlConnection.setDoOutput(true);
       urlConnection.setRequestProperty("accept-charset", charset);
       urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
       urlConnection.setRequestProperty("accept", jsonContentType);
  
       JAXBContext jaxbContext = JAXBContext.newInstance(JAXBObject.class);
       Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
       jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
       jaxbMarshaller.marshal(obj, urlConnection.getOutputStream());  
       int rspCode = urlConnection.getResponseCode();
       ...
   }
  </code></pre>
  
  <p>The webservice code is </p>
  
  <pre><code>@POST   
  @Produces("application/json")
  @Path("test")
  public String doIt(@QueryParam("xml") String str) {
      int ret = doSomething(str);
      return new Gson().toJson(ret);
  }
  </code></pre>
  
  <p>The program is reaching doIt, but nothing is coming through in String str.
  What am I doing wrong?</p>