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 Invoking JAX-WS method from browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Invoking JAX-WS method from browser" Watch "Invoking JAX-WS method from browser" New topic
Author

Invoking JAX-WS method from browser

Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
Hi all
Is it possible to invoke from the browser Jax-Ws method who's signature is :





Thank you
Sharon
Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
Additional info:
The Ws engine is CXF running on Tomcat (JAX-WS implementation)
http://incubator.apache.org/cxf/
http://tomcat.apache.org/

Thank you!!!

Sharon
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
The simple answer is No. (At least not if it is exposed as a SOAP web service)

SOAP web services were never designed to be directly accessed via a browser. There always has been the expectation that the client application would build a SOAP request and place that request inside of an HTTP request - browsers were never designed to do that, they simply issue HTTP requests.

That being said it is always possible to have browser-based client-side scripting (e.g. JavaScript) build that HTTP/SOAP Request, parse the HTTP/SOAP response and use the content to modify the browser document object model.
Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
Why not?
In order to invoke method with 2 params, one can write:



Sharon
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Originally posted by Sharon whipple:
In order to invoke method with 2 params, one can write:



IF the WS is written in a RESTful style, and recognizes HTTP parameters. But as Peer said, in the general case -where a SOAP request is expected- this won't work.


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
However, note that with JavaScript in the browser you can create a normal SOAP request in XML format and POST it to the service and get back the XML formatted response.

Really thats the basis for the whole AJAX thing so it is done all the time.

Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Ulf Dittmer:
IF the WS is written in a RESTful style, and recognizes HTTP parameters.


Even that is debatable with the example given. In the Richardson/Ruby philosophy the HTTP parameters are part of the URI that names a linkable resource. Now that does work if a response is returned pretty snappily from the URI - even if it is sooooo RPC. However if a response can be so quickly "calculated" (rather than retrieved) then there must be some question whether this functionality actually classifies (in terms of granularity) as a service. A more general REST implementation might have you
  • POST the parameter data to http://www.example.com/user/myusername/processname and return a URI for your results (a new resource).
  • GET the result at (e.g.) http://www.example.com/user/myusername/processname/results/12345678. You would then get a 204 ("No Content") code if processing wasn't yet complete or a 200 ("OK") with the result representation.


  • Also a RESTful web service may use the full range of HTTP methods including PUT and DELETE which aren't usually supported by browsers. So to support manipulation-by-browser a properly designed RESTful web service may have to support a URI kludge (HTTP method tunneling in the query string or entity body):
  • When the browser issues: POST /user/myusername/processname/results/12345678?_method=delete
  • The service interprets it as: DELETE /user/myusername/processname/results/12345678


  • The good news it that a RESTful web service can be designed to serve multiple representations of the same resource.
    A browser might request:

    and then get a nice human readable html page of the result. An application on the other hand could request:

    and an XML version of the same results is returned in the HTTP response.

    Properly designed RESTful web services use a broader range of HTTP protocol features than most browsers and for the time being the RESTful developer has to have a pretty good understanding of the HTTP protocol even more so than what would be expected of a competent web component developer (as web components serve their results only to browsers).

    If you are interested in implementing a RESTful web service then I would recommend that you set JAX-WS aside for the moment and that you have a look at Restlet.
    JAX-WS focuses primarily on SOAP web services - REST web services were only of secondary importance when JAX-WS was defined. So it wouldn't surprise me at all if it would be simpler to build a proper RESTful web service (along the lines of RESTful Web Services (amazon US)) with Restlet which is dedicated to implementing RESTful web services rather than JAX-WS.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Invoking JAX-WS method from browser