1

I made a web project in Java, using Java-WS. How can I invoke service methods through HTTP only. I don't want to generate (or worse write) any java web clients, and similar stuff. I'd just like to invoke the method with a HTTP request. And parse the result (manually) from response.

In .NET web services I invoke methods just with:

http://serviceUrl/serviceName.asmx/operationName?parametars=...

How to do the same thing in java + tomcat?

Edit: Let me rephrase my question. So this is what I have done so far:

  • Created a web application (btw. using NetBeans IDE)
  • Added all the necessary source files
  • Added web service classes with WebMethods defined

I deploy the app on tomcat and it deploys fine. Now, what do I need to do to be able to invoke my WebMethods via HTTP?

Typing:

http://localhost:8084/MyService/MyMethod

doesn't work.

Sorry if this is a stupid question, but I'm not really a Java guru, I've been working mostly on .NET.

ZolaKt
  • 4,683
  • 8
  • 43
  • 66

4 Answers4

0

Multiple possibilities:

  • use new URL(url).openConnection().getInputStream()
  • use apache http components
  • use a REST client (if you invoke restful services), like http://code.google.com/p/rest-client/">this, or these. Or spring's RestTemplate
Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Hmmm, rally no simple solution? So, if I get this right, I have to make a client on the server, which will act as a proxy to the real client? – ZolaKt Nov 17 '10 at 12:47
  • what is "the real client". What is simpler than getting the response as an input stream (the first option) ? – Bozho Nov 17 '10 at 12:48
  • The "real client" is a C++ mobile application. Can you give me some more details about the first solution? As I understood this code goes into the client. But the client has nothing to do with java. Basically I'd just like to call the URL from the client, get XML in response, and parse it manually – ZolaKt Nov 17 '10 at 12:51
  • Or better yet nevermind the c++ client. How can I get the method response from a browser? – ZolaKt Nov 17 '10 at 12:53
  • well, I've listed the options. All these give you the output. The first option is even almost all you have to do. With Http Components you have to look at their getting started guide. – Bozho Nov 17 '10 at 15:34
0

In this case, if you want to do an HTTP Web Service that returns an HTTP 200 Web Response, why not look at doing a RESTFul application?

JavaWorld briefly explains the role/use of REST. There's been similar questions on REST tutorials in SO. I hope this helps you.

Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • There isn't much difference between standard WS and REST. Pretty much the same thing, except WS are more used for invoking services (which is what I need) and REST for accessing data. Either way, I just want to be able to call the method form HTTP request. Thanks for advice, but your link doesn't say anything on how to develop REST in java+tomcat – ZolaKt Nov 17 '10 at 14:05
  • And additionally I'd prefer a standard WS. Although I don't need it for my client, I would like to have an open possibly to auto generate the proxy in some other language. In case I ever decide to write a client for another platform – ZolaKt Nov 17 '10 at 14:10
  • @ZolaKt, you don't need to do one for REST, as the client will understand data as XML, JSON, plain text, byte array (depending on choice). So, you know it fits for every language whereas WSDL, you will have to have the language to incorporate WS and plus there's overhead as everything is marshalled to XML for transport. – Buhake Sindi Nov 17 '10 at 14:12
0

Apache CXF has a 'plain http binding', but we recommend that people write JAX-RS services, instead. They are very, very, simple. However, the plain HTTP binding is there and supports GET.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
0

I generate a RESTful Web Service in NetBeans by clicking on "Generate SOAP-over-HTTP Wrapper" in my service context menu. It generated successfully, compiles and deploys fine. But I still can't figure out how to make a HTTP invoke

ZolaKt
  • 4,683
  • 8
  • 43
  • 66
  • Nevermind. Got it working. Have to send request to http://localhost:8084/resources/MyService/MyMethod – ZolaKt Nov 17 '10 at 19:29