We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to build a Java web service that receive data via HTTP Post

zuzzi2
zuzzi2 asked
on
Medium Priority
227 Views
Last Modified: 2012-06-27
As above. Thanks.

Regards,
Rachel
Comment
Watch Question

Principal Technologist
CERTIFIED EXPERT
Commented:
Hi Rachel, start with the tutorial: http://java.sun.com/webservices/docs/1.6/tutorial/doc/ 

- Mayank.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
There are also some code samples here:

http://java.sun.com/developer/codesamples/webservices.html
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
 
public class Example1_client {
 
  public static void main (String[] args)
       throws Exception {
 
    System.out.println("\n\nCalling the SOAP Server to say hello\n\n");      
    URL url = new URL (args[0]);
    String name = args[1];
 
    Call call = new Call (  );
    call.setTargetObjectURI("urn:Example1");
    call.setMethodName("sayHello");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC;);
    Vector params = new Vector (  );
    params.addElement (new Parameter("name", String.class, name, null));
    call.setParams (params);
 
    System.out.print("The SOAP Server says: ");
 
    Response resp = call.invoke(url, "");
 
    if (resp.generatedFault (  )) {
      Fault fault = resp.getFault (  );
      System.out.println ("\nOuch, the call failed: ");
      System.out.println ("  Fault Code   = " + fault.getFaultCode (  ));
      System.out.println ("  Fault String = " + fault.getFaultString (  ));
    } else {
      Parameter result = resp.getReturnValue (  );
      System.out.print(result.getValue (  ));
      System.out.println(  );
    }
  }
}

for a better understanding look at -> http://www.oreilly.com/catalog/progwebsoap/chapter/ch03.html#62464
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
That's only the client :) the Q is about developing the web-service itself. The client could be developed in anything, be it Java or .NET for example.
Leo EikelmanDirector, IT and Business Development
Commented:
well if you are going to use HTTP Post to send data to your web service I suggest building a document style web service (as oppose to an RPC style one)

A web service is basically a public interface with an manual to tell it how to run (the WSDL file)

you can start by looking here
http://java.sun.com/webservices/docs/1.6/tutorial/doc/

http://www.roseindia.net/javacertification/wsd-guide/wsdl_implementation.shtml

I recently completed a document style web service in BEA Weblogic and it is quite easy to create one, as Weblogic creates the WSDL file for you.  

If you are programming in Weblogic you can start by looking here:

http://edocs.bea.com/wls/docs81/webserv/index.html

Cheers
Leo EikelmanDirector, IT and Business Development

Commented:
that's fine with me

Leo
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.