XFire + JSR 181 Annotations + Jetty = Simple Web-Service

package xfire;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService( serviceName = "GreeterService" )
public class GreeterService
{
@WebMethod
public String greet( Person p )
{
return "Hello " + p.getName() + "!";
}
}


package xfire;

public class Person
{
private String name;

public Person()
{
}

public Person( String name )
{
this.name = name;
}


public String getName()
{
return name;
}

public void setName( String name )
{
this.name = name;
}
}


package xfire;

import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
import org.codehaus.xfire.server.http.XFireHttpServer;
import org.codehaus.xfire.service.Service;

public class ServiceServer
{
public static void main( String[] args ) throws Exception
{
XFire xfire = XFireFactory.newInstance().getXFire();
AnnotationServiceFactory factory = new AnnotationServiceFactory(
new Jsr181WebAnnotations(),
xfire.getTransportManager() );
Service service = factory.create( GreeterService.class );
xfire.getServiceRegistry().register( service );
new XFireHttpServer().start();
// http://localhost:8081/GreeterService?wsdl
}
}

package xfire;

import java.net.MalformedURLException;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class ServiceClient
{
public static void main( String[] args ) throws MalformedURLException
{
ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
Service serviceModel = serviceFactory.create( GreeterService.class );

GreeterService service = (GreeterService)
new XFireProxyFactory().create( serviceModel,
"http://localhost:8081/GreeterService" );
String s = service.greet( new Person( "Ulli" ) );
System.out.println( s );
}
}

Ähnliche Beiträge

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert