File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes First JAX-WS webservice results in UnsupportedMediaException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "First JAX-WS webservice results in UnsupportedMediaException" Watch "First JAX-WS webservice results in UnsupportedMediaException" New topic
Author

First JAX-WS webservice results in UnsupportedMediaException

Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hello Ranchers,

I'm quite new to the webservices world and try to create my first JAX-WS webservice. I've documented all the steps that I've done:
My Steps

I think that my Service Provider works correctly, because I can succesfull test it over the Glassfish Console (slide 11). When I run my service client (slide 17) then I get an UnsupportedMediaException:


I've looked at several places, but I'm not able to figure out how I can solve this problem. Any ideas?

Best regards,
Christian


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I would suspect that instead of accessing the web service, your client accesses a web page - thus the text/html content type.
To determine if this is indeed the case, use a packet sniffer like Wireshark or the TCP monitor that is built-into Eclipse to look at the data passed between the client and the web service.
Nicely written notes, by the way! :-)
Best wishes!
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hello Ivan,

thank you for your answer. Your idea with accessing a webpage is comprehensible, but after tracing the request with the "TCP/IP Monitor" view it seams obvious that my client tries to access the wsdl-file. Here is the header of my client-request:

GET /HelloWorldServiceProvider/HelloWorldService/HelloWorldImplService.wsdl HTTP/1.1
User-Agent: Java/1.6.0_13
Host: localhost:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


My server then responds with the wsdl-file:
HTTP/1.1 200 OK
X-Powered-By: Servlet/2.5
Server: Sun GlassFish Enterprise Server v2.1
ETag: W/"1728-1268489995281"
Last-Modified: Sat, 13 Mar 2010 14:19:55 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1728
Date: Mon, 15 Mar 2010 18:58:50 GMT



And then my Java-Client throws the lower exception.

I'm asking my self why my client tries to access the wsdl on not the service?

By the way, Ivan I'm happy for the feedback of my slides. I'll try to continue working on this "brain-friendly" stuff. I've also read nearly the half of your study guide. It is a huge help. Thank you for this.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
It is normal that the client accesses the WSDL. What is not normal is that the content type of the WSDL is text/html.
I just checked with a web service I have deployed to GlassFish and, using Firefox, retrieved the WSDL while monitoring with Wireshark.
The content type of the WSDL I retrieved is text/xml.
I need to take a closer look at how you develop your web service and then get back to you.
Best wishes!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I know what the cause of your problem is.
You generate a WSDL file that you store in the HelloWorldService directory in the web contents directory. This way you are making the WSDL accessible as a web resource, which cause the type to be text/html.
If a web service has any WSDL file(s), then the WSDL files must be placed in the WEB-INF/wsdl directory.
Since you already have my SCDJWS Study notes, please refer to section 4.7 for an example on how to create a web service with a generated WSDL.
In your case, I would not recommend generating a WSDL yourself - this is taken care of by GlassFish when you deploy the web service.
Best wishes!
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hello Ivan,

thank you very much for this tremendous support . I've tried out your suggestions and so I've made a few changes to my existing application:
  • I've deleted the WSDL of my Service Provider
  • I've published my new service provider to Glassfish
  • Over the Glassfish console I've looked that Glassfish had generated the required WSDL and copied the URL of the WSDL
  • I've changed the URL of the WSDL file in my Ant-Script of the wsimport
  • I've executed the wsimport Ant-Script again
  • I've executed my standalone Java client

  • In the next days I'll update my slides and try to continue working on this stuff.
    With best regards, Christian
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: First JAX-WS webservice results in UnsupportedMediaException