<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog de sergio &#187; Web Services</title>
	<atom:link href="http://www.serunix.com/tag/web-services/feed" rel="self" type="application/rss+xml" />
	<link>http://www.serunix.com</link>
	<description>"...si lo puedes soñar, lo puedes hacer"</description>
	<lastBuildDate>Sun, 24 Jan 2010 15:29:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>1 Parte &#8211; Hessian:  Un ejemplo de creación de un Web Services con Hessian en Java ejecutándolo con GlassFish</title>
		<link>http://www.serunix.com/2010/01/24/1-parte-hessian-un-ejemplo-de-creacion-de-un-web-services-con-hessian-en-java-ejecutandolo-con-glassfish</link>
		<comments>http://www.serunix.com/2010/01/24/1-parte-hessian-un-ejemplo-de-creacion-de-un-web-services-con-hessian-en-java-ejecutandolo-con-glassfish#comments</comments>
		<pubDate>Sun, 24 Jan 2010 15:09:24 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=637</guid>
		<description><![CDATA[ ]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Hace mucho tiempo que había trabajado con <a href="http://hessian.caucho.com/">Hessian</a>, y la verdad es que me había gustado mucho:<br />
<em><br />
<strong>The Hessian binary web service protocol makes web services usable without requiring a large framework, and without learning yet another alphabet soup of protocols. Because it is a binary protocol, it is well-suited to sending binary data without any need to extend the protocol with attachments</strong>.</em></p>
<p style="text-align: justify;">Y recordando <del>un poco por que se me olvida</del> aquí les dejo un ejemplo de un Web Services con Hessian,  es una de las maneras más fáciles de implementar un Web Services ya que es:</p>
<ul style="text-align: justify;">
<li> Se puede implementar en  muchisimos lenguajes como:
<ul>
<li> Java</li>
<li>Ruby</li>
<li>Python</li>
<li>PHP</li>
<li>.NET C#</li>
<li>y muchos más</li>
</ul>
</li>
<li>Nos olvidamos de definición de esquemas, SOAP, WSDL, CORBA IDL, etc</li>
<li>Soporta cifrado, compresión (es indispensable para no saturar el Ancho de Banda), autenticación, etc.</li>
<li style="text-align: justify;">Es muy sencillo de implementarlo, y más</li>
</ul>
<p>Este es un ejemplo muy pero muy básico, así que lo que quisimos hacer es obtener la lista de usuarios x.<br />
Para crear el Servidor lo primero que hay que hacer es:</p>
<p>1.- <strong>Necesitamos crear un Proyecto Web, el cual sera el <strong>servidor</strong> que va estar escuchando todas las peticiones. (en mi caso utilice NetBeans)</strong><br />
2.- <strong>Después creamos nuestras clases (yo quiero regresar una lista con usuarios de tipo User que tiene como atributo userId, name, lasname, email)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">&nbsp;
package com.serunix.bean;
&nbsp;
/**
 *
 * @author serunix.com
 */
public class User  implements java.io.Serializable {
&nbsp;
    private int userId;
    private String name;
    private String lasName;
    private String email;
&nbsp;
    /**
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }
&nbsp;
    /**
     * @param userId the userId to set
     */
    public void setUserId(int userId) {
        this.userId = userId;
    }
&nbsp;
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
&nbsp;
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
&nbsp;
    /**
     * @return the lasName
     */
    public String getLasName() {
        return lasName;
    }
&nbsp;
    /**
     * @param lasName the lasName to set
     */
    public void setLasName(String lasName) {
        this.lasName = lasName;
    }
&nbsp;
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
&nbsp;
    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
}</pre></td></tr></table></div>

<p>3.- <strong>Creamos nuestros métodos disponibles </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">&nbsp;
package com.serunix.services;
&nbsp;
import java.util.List;
&nbsp;
/**
 *
 * @author serunix.com
 */
public interface UserServices {
&nbsp;
    List ObtainListUsers();
}</pre></td></tr></table></div>

<p>4.- <strong>Creamos la implementación, la cual tendrá toda la lógica</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">&nbsp;
package com.serunix.services.impl;
&nbsp;
import com.caucho.hessian.server.HessianServlet;
import com.serunix.bean.User;
import com.serunix.services.UserServices;
import java.util.ArrayList;
import java.util.List;
&nbsp;
/**
 *
 * @author serunix.com
 */
public class UserServicesImpl extends HessianServlet implements UserServices {
&nbsp;
    public List ObtainListUsers() {
     List list = new ArrayList();
&nbsp;
        User users = new User();
        users.setUserId(1);
        users.setName(&quot;sergio&quot;);
        users.setLasName(&quot;Salazar&quot;);
        users.setEmail(&quot;admin@serunix.com&quot;);
        list.add(users);
        users = new User();
        users.setUserId(1);
        users.setName(&quot;sergio2&quot;);
        users.setLasName(&quot;López2&quot;);
        users.setEmail(&quot;admin@serunix.com&quot;);
        list.add(users);
&nbsp;
        return list;
    }
&nbsp;
}</pre></td></tr></table></div>

<p>5.- <strong>Y por último modificamos nuestro <em>web.xml</em> y levantamos el <em>server</em> que en este caso estoy utilizando GlassFish</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;servlet&gt;</span>
        <span style="color: #009900;">&lt;servlet-name&gt;</span>UserServicesImpl<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>servlet-name&gt;</span>
        <span style="color: #009900;">&lt;servlet-class&gt;</span>com.serunix.services.impl.UserServicesImpl<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>servlet-class&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>servlet&gt;</span>
    <span style="color: #009900;">&lt;servlet-mapping&gt;</span>
        <span style="color: #009900;">&lt;servlet-name&gt;</span>UserServicesImpl<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>servlet-name&gt;</span>
        <span style="color: #009900;">&lt;url-pattern&gt;</span>/UserServicesImpl<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>url-pattern&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>servlet-mapping&gt;</span></pre></td></tr></table></div>

<p>6.- <strong>Y creamos nuestro cliente. </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package test.serunix;
&nbsp;
import com.caucho.hessian.client.HessianProxyFactory;
import com.serunix.bean.User;
import com.serunix.services.UserServices;
import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;
/**
 *
 * @author sergio
 */
public class testHessian {
&nbsp;
    public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
&nbsp;
        String url = &quot;http://localhost:8080/EJEMPLOHESSIAN/UserServicesImpl&quot;;
&nbsp;
        HessianProxyFactory factory = new HessianProxyFactory();
        UserServices userservices = (UserServices) factory.create(url);
        List users = userservices.ObtainListUsers();
&nbsp;
        Iterator ite = users.iterator();
        while (ite.hasNext()) {
            User user = (User) ite.next();
            System.out.print(&quot;*******************  \n&quot;);
            System.out.print(&quot;Name: &quot; + user.getName() + &quot;  \n&quot;);
            System.out.print(&quot;LasName: &quot; + user.getLasName() + &quot;  \n&quot;);
            System.out.print(&quot;Email: &quot; + user.getEmail() + &quot;  \n&quot;);
        }
    }
}</pre></td></tr></table></div>

<p>7.- Y listo!!!!</p>
<p>La verdad es que es muy fácil, <a onclick="javascript: pageTracker._trackPageview ('/outgoing/proyecto_hessian');" href="http://www.serunix.com/wp-content/uploads/EJEMPLO.zip">aquí</a> les dejo el proyecto entero. Si me quieren dejar un feedback no duden en hacerlo. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2010/01/24/1-parte-hessian-un-ejemplo-de-creacion-de-un-web-services-con-hessian-en-java-ejecutandolo-con-glassfish/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
