title: Post request from Android application failing + RestEasy + Jackson
body: <p>I am trying to send a POST request from my Android application and I get a MediaType conflict error or at least that's what I think. I want to send some data with the request and it should work but I think I am missing something. I am using Jackson and RestEasy as they come with the Wildfly server.</p>
  
  <p>Here is my error log from my server:</p>
  
  <pre><code>15:18:20,790 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-6) Failed executing POST /posts/post: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: domains.Post of media type: application/octet-stream
          at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:427) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.6.Final.jar:]
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_51]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_51]
          at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_51]
  </code></pre>
  
  <p>Here is my postRequest() method: </p>
  
  <pre><code>public static void postRequest(String serviceUrl, Post post) {
          HttpURLConnection conn;
  
          try {
              URL url = new URL(serviceUrl);
              conn = (HttpURLConnection)url.openConnection();
              conn.setRequestMethod("POST");
              conn.setRequestProperty("Content-Type", "application/json");
              conn.setDoInput(true);
  
              ObjectMapper mapper = new ObjectMapper();
              DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
              mapper.writeValue(wr, post);
  
              wr.flush();
              wr.close();
  
              int responseCode = conn.getResponseCode();
              System.out.println("\nSending 'POST' request to url " + url);
              System.out.println("Response Code: " + responseCode);
  
              BufferedReader in = new  BufferedReader(new InputStreamReader(conn.getInputStream()));
  
              String inputLine;
              StringBuffer response = new StringBuffer();
  
              while((inputLine = in.readLine()) != null) {
                  response.append(inputLine);
              }
              in.close();
  
              System.out.println(response.toString());
  
          } catch(MalformedURLException e) {
              e.printStackTrace();
          } catch(IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Here is error log from my client:</p>
  
  <pre><code>04-06 09:18:18.634: I/System.out(1479): Sending 'POST' request to url http://10.0.2.2:8080/IslamicPostsWS/rest/posts/post
  04-06 09:18:18.634: I/System.out(1479): Response Code: 500
  04-06 09:18:18.665: W/System.err(1479): java.io.FileNotFoundException: http://10.0.2.2:8080/IslamicPostsWS/rest/posts/post
  04-06 09:18:18.755: W/System.err(1479):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
  04-06 09:18:18.755: W/System.err(1479):     at services.JSONRequest.postRequest(JSONRequest.java:96)
  04-06 09:18:18.755: W/System.err(1479):     at com.example.slidingmenu.AddPostFragment$RequestItemsServiceTask.doInBackground(AddPostFragment.java:65)
  04-06 09:18:18.755: W/System.err(1479):     at com.example.slidingmenu.AddPostFragment$RequestItemsServiceTask.doInBackground(AddPostFragment.java:1)
  04-06 09:18:18.827: W/System.err(1479):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
  04-06 09:18:18.827: W/System.err(1479):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  04-06 09:18:18.835: W/System.err(1479):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  04-06 09:18:18.867: W/System.err(1479):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  04-06 09:18:18.935: W/System.err(1479):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  04-06 09:18:18.935: W/System.err(1479):     at java.lang.Thread.run(Thread.java:841)
  </code></pre>
  
  <p><strong>EDIT</strong> -- Server side code:</p>
  
  <pre><code>package api;
  import java.util.List;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Response;
  
  import database_wrappers.PostWrapper;
  import domains.Post;
  
  @Path("/posts")
  public class PostAPI {
      PostWrapper postWrapper = new PostWrapper();
  
      @GET
      @Path("/get")
      @Produces("application/json; charset=UTF-8")
      public List&lt;Post&gt; getPosts() {
          List&lt;Post&gt; posts = postWrapper.getPosts();  
          return posts;
      }
  
      @POST
      @Path("/post")
      @Consumes("application/json; charset-UTF-8")
      public Response insertPost(Post post) {
          postWrapper.insertPost(post);
          return Response.status(200).entity(post).build();
      }
  }
  </code></pre>
  
  <p>And my PostWrapper:</p>
  
  <pre><code>public void insertPost(Post post) {
  
          try {
              Context initContext = new InitialContext();
              Context context = (Context) initContext.lookup("java:comp/env");
  
              dataSource = (DataSource) context.lookup("jdbc/myJdbc");
              con = dataSource.getConnection();
              String query = "INSERT INTO islamic_posts (post_title, post_content) VALUES" + "(?, ?)";
              stmt = con.prepareStatement(query);
              stmt.setString(1, post.getPostTitle());
              stmt.setString(2, post.getPostContent());
              stmt.executeUpdate();
  
              con.close();
  
          } catch(SQLException e) {
              e.printStackTrace();
          } catch (NamingException e) {
              e.printStackTrace();
          }
      }
  </code></pre>