Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: com.sun.jersey.api.MessageException

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    46
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default com.sun.jersey.api.MessageException

    Hello,

    Today i tried to build my first Client REST WEB Serviece (using Jersey), i make very simple example, but some how to get a error every time
    public class Location {
     
    	private int locationId;
    	private String ort;
    	private String PLZ;
    	private String strasse;
    	private String country;
    //Setters und Getters
    }
    package inventory;
     
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
     
    import beans.Location;
     
    @Path("/location/plz")
    public class LocationService {
     
    	@GET
    	@Path("/get")
    	@Produces("text/html")
    	public Location getLocationInHTML() {
     
    		Location loc = new Location();
     
    		loc.setCountry("Deutschland");
    		loc.setLocationId(1);
    		loc.setOrt("Berlin");
    		loc.setPLZ("01019");
    		loc.setStrasse("Augustusplatz 13");
     
    		return loc; 
    	} 
    }
    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.ClientResponse;
    import com.sun.jersey.api.client.WebResource;
     
    public class LocationClientGet {
     
    	// http://localhost:8080/StammDaten/eumonis/location/plz/get
     
    	public static void main(String[] args) {
     
    		try {
     
    			Client client = Client.create();
     
    			WebResource webResource = client.resource("http://localhost:8080/StammDaten/eumonis/location/plz/get");
     
    			ClientResponse response = webResource.accept("text/html").get(ClientResponse.class);
     
    			if (response.getStatus() != 200) {
    			   throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    			}
     
    			String output = response.getEntity(String.class);
     
    			System.out.println("Output from Server .... \n");
    			System.out.println(output);
     
    		  } catch (Exception e) {
     
    			e.printStackTrace();
     
    		  }
    	}
     
    }

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
      <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
          <param-name>com.sun.jersey.config.property.packages</param-name>
          <param-value>inventory;test</param-value>
        </init-param>
        <init-param>
          <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
          <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/eumonis/*</url-pattern>
      </servlet-mapping>
      <session-config>
        <session-timeout>30</session-timeout>
      </session-config>
    </web-app>
    I added every Jar for this Project, but get error:
    HTML Code:
    javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class beans.Location, 
    and Java type class beans.Location, and MIME media type text/html was not found
    what the Problem, and how can i solve it?

  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: com.sun.jersey.api.MessageException

    I guess whenever you post its going to be a given that you've cross-posted without referencing the crosspost.

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/80883-com-sun-jersey-api-messageexception.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. java sun speech api
    By zulqar in forum AWT / Java Swing
    Replies: 1
    Last Post: November 2nd, 2010, 01:35 AM