Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:05+00:00 2026-06-18T02:28:05+00:00

@Path(/hello) public class Hello { @POST @Path({id}) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public JSONObject sayPlainTextHello(@PathParam(id)JSONObject inputJsonObj) {

  • 0
@Path("/hello")
public class Hello {

    @POST
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public JSONObject sayPlainTextHello(@PathParam("id")JSONObject inputJsonObj) {

        String input = (String) inputJsonObj.get("input");
        String output="The input you sent is :"+input;
        JSONObject outputJsonObj = new JSONObject();
        outputJsonObj.put("output", output);

        return outputJsonObj;
    }
} 

This is my webservice (I am using Jersey API). But I could not figure out a way to call this method from a java rest client to send and receive the json data. I tried the following way to write the client

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
JSONObject inputJsonObj = new JSONObject();
inputJsonObj.put("input", "Value");
System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).entity(inputJsonObj).post(JSONObject.class,JSONObject.class));

But this shows the following error

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.Class, and MIME media type, application/octet-stream, was not found
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:28:05+00:00Added an answer on June 18, 2026 at 2:28 am

    Your use of @PathParam is incorrect. It does not follow these requirements as documented in the javadoc here. I believe you just want to POST the JSON entity. You can fix this in your resource method to accept JSON entity.

    @Path("/hello")
    public class Hello {
    
      @POST
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public JSONObject sayPlainTextHello(JSONObject inputJsonObj) throws Exception {
    
        String input = (String) inputJsonObj.get("input");
        String output = "The input you sent is :" + input;
        JSONObject outputJsonObj = new JSONObject();
        outputJsonObj.put("output", output);
    
        return outputJsonObj;
      }
    }
    

    And, your client code should look like this:

      ClientConfig config = new DefaultClientConfig();
      Client client = Client.create(config);
      client.addFilter(new LoggingFilter());
      WebResource service = client.resource(getBaseURI());
      JSONObject inputJsonObj = new JSONObject();
      inputJsonObj.put("input", "Value");
      System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).post(JSONObject.class, inputJsonObj));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have pretty simple JAX-RS WS: @Stateless @Path(/foo) public class FooFacadeBean { @GET @Produces(MediaType.TEXT_HTML)
As a example: public class Hello { public static void main(String[] args) { try
public class LineNum1 extends Thread{ public synchronized void run() { try { Hello.main(null); System.out.println(Stack
I am trying to write a RESTFul Webservice using Jersey. package sample.hello.resources; @Path(/hello) public
I wrote a simple implementation class: public interface MyRemote extends Remote { public String
Hello - Debug uses an invalid compiler. Probably the toolchain path within the compiler
So I have a main.py file inside /home/richard/projects/hello-python directory: import sys sys.path.append('/home/richard/projects/hello-python') from Encode
I have a simple Class package chapter10; public class CompilationTest { public static void
Is it by spec that, given a MyClass.java file containing package com.mycorp.foo; public class
hello i m working with PHP and i want to include a class.php file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.