INCLUDE_DATA

 
»
S
I
D
E
B
A
R
«
aquisto cialis levitra svizzera tadalafil bestellen viagra prix acheter du viagra acquista levitra cialis sur internet citrate de sildenafil compro viagra levitra ricetta kamagra pharmaceuticals cialis vente libre cialis suisse levitra italia vente de cialis viagra suisse kamagra gel viagra quanto costa cialis 20 mg prix cialis 10mg viagra verkauf cialis moins cher viagra prezzo levitra kopen acheter tadalafil acheter kamagra tadalafil generico impuissance sexuelle cialis preco levitra donna viagra 100 mg comprar cialis generico comprar levitra cialis a vendre procurer du cialis generische cialis vardenafil generico vardenafil generika levitra sur internet generische viagra acheter cialis generique acquista viagra achat cialis viagra 100 mg cialis generico kamagra en france viagra ordonnance acheter viagra achat vardenafil pastilla levitra viagra cialis differenze impotenza sessuale venta viagra medicament cialis curare impotenza kamagra te koop achat cialis 20mg levitra pharmacie cialis receta acquisto viagra net cialis en ligne achat de viagra cialis generique acheter acheter du cialis cialis 20 mg vardenafil 10 mg viagra alternativo citrate de sildenafil cialis sin receta viagra kopen acheter cialis en pharmacie kamagra bestellen comprar viagra pela internet viagra prescrizione levitra donne vente cialis venta de sildenafil achete levitra acheter cialis france venta de levitra viagra kosten cialis marche pas comprar vardenafil disfunzione erettile rimedi vardenafil generique viagra recensioni cialis generico prezzo viagra versand cialis europe viagra venta libre impotenza rimedi cialis rezeptfrei acheter kamagra france levitra ohne rezept acquisto viagra in contrassegno prix de cialis cialis prescrizione viagra acquisto online achat viagra pildoras cialis kamagra generique cialis prezzo cialis inde cialis sur le net acheter cialis en espagne levitra ordonnance viagra naturel cialis 10 mg acquistare levitra procurer du viagra acquisto viagra senza ricetta viagra controindicazioni levitra 20 mg compra viagra impuissance erection acheter cialis pharmacie prezzi levitra viagra ohne rezept kamagra apcalis comprar viagra commander du cialis cialis ricetta medica sildenafil 50 mg sildenafil venta viagra italia pilule levitra sildenafil generico viagra prijs
Creating a Ruby Web Service Client from a WSDL
Feb 5th, 2009 by Jason

Remember the Java JAX-WS Web Service discussed what seems like long ago? Currently there is an have an instance of it running on this hosting server (got to love SSH). Experimenting with Ruby has led me to find the simplicity of creating a web service client. The duck typing of the language allows you to not need to generate a bunch of classes to pull in a WSDL (although it is possible using wsdl2r).

require 'soap/wsdlDriver'

URL = 'http://jstaten.com:7070/MathExample/MathService?wsdl'

begin
   driver = SOAP::WSDLDriverFactory.new(URL).create_rpc_driver
   p driver.addInts({:arg0 =>2, :arg1 => 4}).return
rescue => err
   p err.message
end

Steping through this code, you’re simply requiring the soap.wsdlDriver library and setting the URL of the WSDL to be read in. The begin statement is for error handling incase something goes wrong. Inside that, you create a new rpc driver using the WSDLDriverFactory. The “driver” within this code is the instance which contains methods pointing to the web service’s exposed operations. After creating the driver, we call a method on it. Because it requires two parameters (the two integers to be added), we pass it a map. The return field from running that method contains the value of the response. Finally, we rescue by printing the error message. If you’d like to test this against the web service in the code, feel free. Just please don’t abuse it.

Creating a Java Web Service Client from a WSDL
Dec 2nd, 2008 by Jason

In my previous post, I discussed the creation of a web service. That’s all good and dandy, but can be rather boring because we can’t do anything with it other than touch it with a web browser and see a bunch of XML.  Although this example is very specific to the web service created prior,  the concepts can be applied to most web services.

Generating Classes from a WSDL

This project is different than some because it starts with a build.xml. Within it is the necessary task to generate *.java files we will use later for communicating with the web service.

<?xml version="1.0" encoding="UTF-8"?>
<!--build.xml WebService Client Example by Jason Staten-->
<project basedir="." default="client" name="MathServiceExample">

    <property environment="env"/>
    <property name="lib.home" value="${env.JAXWS_HOME}/lib"/>
    <property name="build.home" value="${basedir}/build"/>
    <property name="build.classes.home" value="${build.home}/classes"/>

    <path id="jaxws.classpath">
        <pathelement location="${java.home}/../lib/tools.jar"/>
        <fileset dir="${lib.home}">
            <include name="*.jar"/>
            <exclude name="j2ee.jar"/>
        </fileset>
    </path>

	<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
        <classpath refid="jaxws.classpath"/>
    </taskdef>

    <target name="setup">
        <mkdir dir="${build.home}"/>
        <mkdir dir="${build.classes.home}"/>
    </target>

	    <target name="generate-client">

        <wsimport
                debug="true"
                verbose="${verbose}"
                keep="true"
                sourcedestdir="${basedir}/src"
                package="com.jstaten.webService.client.generated"
                wsdl="http://localhost:7070/MathExample/MathService?wsdl"
				xnocompile="true"
				>
        </wsimport>
    </target>

    <target name="client" depends="generate-client,setup">
        <javac
                fork="true"
                srcdir="${basedir}/src"
                destdir="${build.classes.home}"
                includes="**/client/**,**/common/**">
            <classpath refid="jaxws.classpath"/>
        </javac>
    </target>

    <target name="clean">
        <delete dir="${build.home}" includeEmptyDirs="true"/>
    </target>

</project>


There are two key parts to this build file, the taskdef that declares what the wsimport tag actually is and the task generate-client that uses wsimport to generate the java that provides an interface to the webservice.

If you look within your src directory, you will now notice that there are now *.java files for use with your own code. Let’s get to using it.

Writing the Client

package com.jstaten.webService.client;
import com.jstaten.webService.client.generated.*;

public class MathClient {
	public static void main(String[] args)
	{
		MathExampleImpl port = new MathExampleImplService().getMathExampleImplPort();

		int addA = 10;
		int addB = 20;
		float multiplyA = 30;
		float multiplyB = 20.59f;
		System.out.println(addA + " + " + addB + " =");
		System.out.println(port.addInts(addA, addB));
		System.out.println(multiplyA + " * " + multiplyB + " =");
		System.out.println(port.multiplyFloats(multiplyA,multiplyB));

	}
}


The code is relatively straightforward. We make an import call to the generated classes. Next we create a new MathExampleImpl object that is our interface to the webservice. Finally, we run a few test methods on it and return the result to the console so we can see the result.

Build the Client

    <target name="client" depends="generate-client,setup">
        <javac
                fork="true"
                srcdir="${basedir}/src"
                destdir="${build.classes.home}"
                includes="**/client/**,**/common/**">
            <classpath refid="jaxws.classpath"/>
        </javac>
    </target>

Adding the above into your build file within the project element will allow you to build the client. Essentially it’s just a javac call with some arguments. Having it in the build file allows you to not have to type all that stuff into the command line every time you compile – much more convenient.

Run the compiled client and you should now see the results you printed to the console. Next time, doing the same thing via .NET in C#.

Creating a simple web service using JAX-WS and no container
Nov 20th, 2008 by Jason

Web services are something new for me. I’ve heard all about them and the popularity of them, but taking the task upon myself to create one was something that I’d never done. The WSDLs looked somewhat complicated and I just had no motivation until yesterday. However, to my surprise, I found that the process is not really too complicated at all. In this article I’ll show you how to make a simple web service that adds and multiplies.

The Webservice


//MathExampleImpl.java -- WebService Example by Jason Staten

package com.jstaten.webService.server;

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

@WebService
public class MathExampleImpl {
@WebMethod(operationName="addInts")
public int addInts(int a, int b)
{
return a + b;
}
@WebMethod(operationName="multiplyFloats")
public float multiplyFloats(float a, float b)
{
return a * b;
}
}

The service is very straightforward. Essentially you create a class with the operations that will show up in the WSDL. This class has two, addInts and multiplyFloats which will add integers and multiply floats, respectively. The annotations @WebService and @WebMethod are later parsed when building this application.

The Server


//MathService.java -- WebService Example by Jason Staten

package com.jstaten.webService.server;

import javax.xml.ws.Endpoint;

public class MathService {
private Endpoint endpoint = null;
public MathService()
{
endpoint = Endpoint.create(new MathExampleImpl());
}
private void publish()
{

endpoint.publish("http://localhost:7070/MathExample/MathService");
}
public static void main(String[] args)
{
MathService hws = new MathService();
hws.publish();
System.out.println("Waiting");
}
}

The server relies on one key component, the Endpoint class. Endpoints are used to publish a webservice to a specific address. In this very simple example, we take a new instance of our MathExampleImpl class that we created earlier and publish it to http://localhost:7070/MathExample/MathService which will be where we direct any webservice calls to from a client. Finally, we give the “Waiting” message to know that the server has started and is waiting for a connection.

The Build File

<?xml version="1.0" encoding="UTF-8"?>
<!--build.xml WebService Example by Jason Staten-->
<project basedir="." default="build-server" name="MathServiceExample">

    <property environment="env"/>
    <property name="lib.home" value="${env.JAXWS_HOME}/lib"/>
    <property name="build.home" value="${basedir}/build"/>
    <property name="build.classes.home" value="${build.home}/classes"/>

    <path id="jaxws.classpath">
        <pathelement location="${java.home}/../lib/tools.jar"/>
        <fileset dir="${lib.home}">
            <include name="*.jar"/>
            <exclude name="j2ee.jar"/>
        </fileset>
    </path>

    <taskdef name="apt" classname="com.sun.tools.ws.ant.Apt">
        <classpath refid="jaxws.classpath"/>
    </taskdef>

    <target name="setup">
        <mkdir dir="${build.home}"/>
        <mkdir dir="${build.classes.home}"/>
    </target>

    <target name="build-server" depends="setup">
        <apt
                fork="true"
                debug="true"
                verbose="${verbose}"
                destdir="${build.classes.home}"
                sourcedestdir="${build.classes.home}"
                sourcepath="${basedir}/src">
            <classpath>
                <path refid="jaxws.classpath"/>
                <pathelement location="${basedir}/src"/>
            </classpath>
            <option key="r" value="${build.home}"/>
            <source dir="${basedir}/src">
                <include name="**/server/*.java"/>
                <include name="**/common/*.java"/>
            </source>
        </apt>
    </target>

    <target name="clean">
        <delete dir="${build.home}" includeEmptyDirs="true"/>
    </target>

The build file is where a lot of the magic is done. At first glace it may seem a little confusing, but broken down, it is actually quite simple. Lets step through it.

    <property environment="env"/>
    <property name="lib.home" value="${env.JAXWS_HOME}/lib"/>
    <property name="build.home" value="${basedir}/build"/>
    <property name="build.classes.home" value="${build.home}/classes"/>

The first section is properties that will be used throughout the rest of the build file describing the location of JAX-WS and the location to place compiled files.

    <path id="jaxws.classpath">
        <pathelement location="${java.home}/../lib/tools.jar"/>
        <fileset dir="${lib.home}">
            <include name="*.jar"/>
            <exclude name="j2ee.jar"/>
        </fileset>
    </path>

This section defines the classpath of JAX-WS for usage within the build file.

    <taskdef name="apt" classname="com.sun.tools.ws.ant.Apt">
        <classpath refid="jaxws.classpath"/>
    </taskdef>

Within this element, we declare apt which is what does the actual parsing of the annotations within your source files. We will use it as an element later on in the build file.

<target name="build-server" depends="setup">
        <apt
                fork="true"
                debug="true"
                verbose="${verbose}"
                destdir="${build.classes.home}"
                sourcedestdir="${build.classes.home}"
                sourcepath="${basedir}/src">
            <classpath>
                <path refid="jaxws.classpath"/>
                <pathelement location="${basedir}/src"/>
            </classpath>
            <option key="r" value="${build.home}"/>
            <source dir="${basedir}/src">
                <include name="**/server/*.java"/>
                <include name="**/common/*.java"/>
            </source>
        </apt>
    </target>

The build-server target is the main operation within the build file. It utilizes apt like we declared earlier and tells it where to place the compiled code as well as the generated source. Using the properties we declared earlier, we can essentially just fill in the blanks. destdir is the location of the compiled code, sourcedestdir is the placement of generated source code(from parsing the attributes), and sourcepath is the path to the source files that you created earlier.

    <target name="clean">
        <delete dir="${build.home}" includeEmptyDirs="true"/>
    </target>

Finally, the clean target removes old compiled code. This can be run by using ant clean

After compiling a simple java com.jstaten.webService.server.MathService will start the server and a quick pointing of your browser to http://localhost:7070/MathExample/MathService?wsdl will result in receiving a WSDL.

In a later article I will discuss the creation of a client to use this service a within both Java and C#.

»  Substance: WordPress   »  Style: Ahren Ahimsa Blog Flux Local - Utah
© Jason Staten 2009