Maven: Unable to find the mojo ‘org.apache.axis2:axis2-wsdl2code-maven-plugin:1.4:wsdl2code’

Java, Maven, Open Source, Programación, Web Services 9 de March del 2010

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

La verdad es que no entiendo por que me daba la siguiente exception:

1
2
3
4
5
6
ERROR]BUILD ERROR
 Internal error in the plugin manager executing goal 
'org.apache.axis2:axis2-wsdl2code-maven-plugin:1.4:wsdl2code': 
Unable to find the mojo 'org.apache.axis2:axis2-wsdl2code-maven-plugin:1.4:wsdl2code' in the plugin 
'org.apache.axis2:axis2-wsdl2code-maven-plugin' org.apache.axis2.wsdl.codegen.CodeGenerationException
 For more information, run Maven with the -e switch

pero ya después de un rato me puse a verificar los jars que se necesitan y así quedo el pom.xml y con esto me funciono muy bien…

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
...
<dependency>
 
                  <groupId>org.apache.axis2</groupId>
 
                  <artifactId>axis2-java2wsdl</artifactId>
 
                  <version>1.4.1</version>
 
                  <exclusions>
 
                        <exclusion>
 
                              <groupId>org.apache.ws.commons.axiom</groupId>
 
                              <artifactId>axiom-dom</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.ws.commons.axiom</groupId>
 
                              <artifactId>axiom-api</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.ws.commons.axiom</groupId>
 
                              <artifactId>axiom-impl</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.ant</groupId>
 
                              <artifactId>ant</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.httpcomponents</groupId>
 
                              <artifactId>httpcore</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.httpcomponents</groupId>
 
                              <artifactId>httpcore-nio</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>junit</groupId>
 
                              <artifactId>junit</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>commons-fileupload</groupId>
 
                              <artifactId>commons-fileupload</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.geronimo.specs</groupId>
 
                              <artifactId>geronimo-jms_1.1_spec</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>javax.mail</groupId>
 
                              <artifactId>mail</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>com.ibm.icu</groupId>
 
                              <artifactId>icu4j</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>xom</groupId>
 
                              <artifactId>xom</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.geronimo.specs</groupId>
 
                              <artifactId>geronimo-javamail_1.4_spec</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>commons-io</groupId>
 
                              <artifactId>commons-io</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>jaxen</groupId>
 
                              <artifactId>jaxen</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>annogen</groupId>
 
                              <artifactId>annogen</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.woden</groupId>
 
                              <artifactId>woden-impl-dom</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>xerces</groupId>
 
                              <artifactId>xmlParserAPIs</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.woden</groupId>
 
                              <artifactId>woden-api</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>xalan</groupId>
 
                              <artifactId>xalan</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>xerces</groupId>
 
                              <artifactId>xercesImpl</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.codehaus.woodstox</groupId>
 
                              <artifactId>wstx-asl</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>javax.servlet</groupId>
 
                              <artifactId>servlet-api</artifactId>
 
                        </exclusion>
 
                        <exclusion>
 
                              <groupId>org.apache.geronimo.specs</groupId>
 
                              <artifactId>geronimo-stax-api_1.0_spec</artifactId>
 
                        </exclusion>
                  <exclusions>
<dependency>
....

Exception axis2: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0]

Java, Programación, Web Services 26 de February del 2010

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Estaba creando un cliente con Acxist2 y es que no sabía por que me estaba dando esta exception,  chencando por Internet y sobre todo revidando las cabeceras (Headers) y con la confirmación de algunas páginas, me encontré que hay un poco de problemas de comunicación (SOAP) entre un servidor de web Services que esta en IIS y un cliente que esta en Axis2 1.4.1, después de darle muchas vueltas, y con un poco de ayuda, resolví esta exeption: de la siguiente manera:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- OMException in getSOAPBuilder
 
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 
 at [row,col {unknown-source}]: [1,0]
      at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
      at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:156)
      at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:105)
      at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:677)
      at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:182)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
      at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
      at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
      at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

Se puede solucionar cambiando las cabeceras (NUNCA HAY QUE TOCAS LAS CLASES AUTO GENERADAS), después de llamar al STUB:

1
2
Options options = stub._getServiceClient().getOptions();
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

claro, si estas usando SOAP1 de lo contrario sólo hay que cambiar la constante a SOAP2… y listo!!! con esto se quita la anterior exception….

3 Parte – Hessian: Crear un test con Junit para probar la respuesta del Web Services…

Java, Programación, Spring, Web Services 31 de January del 2010

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

La verdad es que es un mundo hacer un test para realizar pruebas unitarias de nuestras aplicaciones web, hay veces que no los hacemos por que no sabemos, no queremos, consumen más tiempo, etc. mil pretextos, pero la verdad es que son muy importantes, mejor dicho deberían ser indispensables pero eso es otro tema que debe resolver cada uno.

Continuando con el pequeño ejemplo de “1 Parte – Hessian: Un ejemplo de creación de un Web Services con Hessian en Java ejecutándolo con GlassFish” púes habíamos creado un test usando un main, pero ahora les dejo un ejemplo de test utilizando Junit, la verdad es que no es difícil y sólo hay que:

1.- Creamos nuestra clase de prueba
2.- Importamos el jar de Junit en caso de que no lo tengamos. (como estoy utilizando Netbeans al crear el proyecto me crea todo lo necesario para poder desarrollar los test además que me importa el jar de junit).

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
package test.serunix;
 
import com.serunix.bean.User;
import com.serunix.services.UserServices;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
/**
 *
 * @author serunix.com
 */
public class UserServicesImplTest {
 
    private static final Logger log = Logger.getLogger(UserServicesImplTest.class);
    /**
     *
     */
    protected UserServices userservices;
 
    /**
     * Se ejecuta antes de probar los test, para que pueda cargar el contexto y hacer
     * la llamada al Web Services.
     *
     * @throws Exception
     */
    @Before
    public void init() throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test/serunix/remoting-servlet-client.xml");
        userservices = (UserServices) context.getBean("userService");
    }
 
    /**
     * Es para probar que podemos obetenr un lista de los usarios
     *
     * @throws Exception
     */
    @Test
    public void ObtainListUsers() throws Exception {
        List users = userservices.ObtainListUsers();
 
        Iterator ite = users.iterator();
        while (ite.hasNext()) {
            User user = (User) ite.next();
            user.getName();
            user.getLasName();
            user.getEmail();
        }
 
    }
}

3.- Después los ejecutamos, en mi caso solo tengo que seleccionar la clase del test y dar click derecho ->Test File
4.- Nos muestra los resultados del test ya sea que hayan fallado o que hay ido todo Ok.

Test - Junit

Test - Junit

Podríamos seguir haciendo diferentes tipos de prueba, pero eso depende del nivel y detalle que queramos, este test es muy sencillo y ojala les sirva de ejemplo.

2 Parte – Hessian: Integración de Hessian con Spring Framework…

Java, Programación, Spring, Web Services 26 de January del 2010

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Bueno, como he dicho antes con un poco de práctica y sobre todo, con mucho interés se pueden saber las cosas que uno quiere… después de mucha lectura sobre como crear un Web Services con Hessian integrándolo con Spring púes he conseguido levantar el cliente y el servidor, pero me encontré con muchos problemas que principalmente fueron de versiones, y como he leído en muchos foros, no se puede obtener una respuesta correcta por parte del servidor en spring 2.5.xx así que tuve que download la versión 3.0.0 release:

Tomamos como ejemplo el proyecto que creamos en el post “1 Parte – Hessian… ” y sólo hay que crear:

1.- remoting-servlet.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
 
 
    <bean id="userServices"   class="com.serunix.services.impl.UserServicesImpl" />
 
   <bean name="/userService"   class="org.springframework.remoting.caucho.HessianServiceExporter">
        <property name="service"  ref="userServices"/>
        <property name="serviceInterface" value="com.serunix.services.UserServices"/>
    </bean>
 
</beans>

2.- Modificamos nuestro web.xml y agregamos esto.

1
2
3
4
5
6
7
8
9
10
11
12
...
    <servlet>
        <servlet-name>remoting</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>remoting</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>
   ...

3.- Y quitar que la clase UserServicesImp ya no extienda de HessianServlet

1
       ... extends HessianServlet ...

4.- Esto tendría que ser suficiente para el servidor y por parte del cliente, sólo hay que agregar:

5.- remoting-servlet-client.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
 
 
    <bean id="userService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl" value="http://localhost:8080/EJEMPLOHESSIAN/remoting/userService"/>
        <property name="serviceInterface" value="com.serunix.services.UserServices"/>
    </bean>
 
</beans>

6.- Y para obtener la llamada sólo hay que hacer la petición a la Url que configuramos en el servidor /userService

1
2
3
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test/serunix/remoting-servlet-client.xml");
        UserServices userservices = (UserServices) context.getBean("userService");
        List users = userservices.ObtainListUsers();

7.- Así que esto sería todo, aquí les dejo un screenshot de como quedo mi proyecto incluyendo los jars…

Web services con Hessian y Spring

Web services con Hessian y Spring

1 Parte – Hessian: Un ejemplo de creación de un Web Services con Hessian en Java ejecutándolo con GlassFish

Java, Programación, Web Services 24 de January del 2010

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Hace mucho tiempo que había trabajado con Hessian, y la verdad es que me había gustado mucho:

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.

Y recordando un poco por que se me olvida 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:

  • Se puede implementar en  muchisimos lenguajes como:
    • Java
    • Ruby
    • Python
    • PHP
    • .NET C#
    • y muchos más
  • Nos olvidamos de definición de esquemas, SOAP, WSDL, CORBA IDL, etc
  • Soporta cifrado, compresión (es indispensable para no saturar el Ancho de Banda), autenticación, etc.
  • Es muy sencillo de implementarlo, y más

Este es un ejemplo muy pero muy básico, así que lo que quisimos hacer es obtener la lista de usuarios x.
Para crear el Servidor lo primero que hay que hacer es:

1.- Necesitamos crear un Proyecto Web, el cual sera el servidor que va estar escuchando todas las peticiones. (en mi caso utilice NetBeans)
2.- Después creamos nuestras clases (yo quiero regresar una lista con usuarios de tipo User que tiene como atributo userId, name, lasname, email)

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
 
package com.serunix.bean;
 
/**
 *
 * @author serunix.com
 */
public class User  implements java.io.Serializable {
 
    private int userId;
    private String name;
    private String lasName;
    private String email;
 
    /**
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }
 
    /**
     * @param userId the userId to set
     */
    public void setUserId(int userId) {
        this.userId = userId;
    }
 
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
 
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
 
    /**
     * @return the lasName
     */
    public String getLasName() {
        return lasName;
    }
 
    /**
     * @param lasName the lasName to set
     */
    public void setLasName(String lasName) {
        this.lasName = lasName;
    }
 
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
 
    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
}

3.- Creamos nuestros métodos disponibles

1
2
3
4
5
6
7
8
9
10
11
12
13
 
package com.serunix.services;
 
import java.util.List;
 
/**
 *
 * @author serunix.com
 */
public interface UserServices {
 
    List ObtainListUsers();
}

4.- Creamos la implementación, la cual tendrá toda la lógica

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
 
package com.serunix.services.impl;
 
import com.caucho.hessian.server.HessianServlet;
import com.serunix.bean.User;
import com.serunix.services.UserServices;
import java.util.ArrayList;
import java.util.List;
 
/**
 *
 * @author serunix.com
 */
public class UserServicesImpl extends HessianServlet implements UserServices {
 
    public List ObtainListUsers() {
     List list = new ArrayList();
 
        User users = new User();
        users.setUserId(1);
        users.setName("sergio");
        users.setLasName("Salazar");
        users.setEmail("admin@serunix.com");
        list.add(users);
        users = new User();
        users.setUserId(1);
        users.setName("sergio2");
        users.setLasName("López2");
        users.setEmail("admin@serunix.com");
        list.add(users);
 
        return list;
    }
 
}

5.- Y por último modificamos nuestro web.xml y levantamos el server que en este caso estoy utilizando GlassFish

1
2
3
4
5
6
7
8
<servlet>
        <servlet-name>UserServicesImpl</servlet-name>
        <servlet-class>com.serunix.services.impl.UserServicesImpl</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>UserServicesImpl</servlet-name>
        <url-pattern>/UserServicesImpl</url-pattern>
    </servlet-mapping>

6.- Y creamos nuestro cliente.

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
package test.serunix;
 
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 {
 
    public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
 
        String url = "http://localhost:8080/EJEMPLOHESSIAN/UserServicesImpl";
 
        HessianProxyFactory factory = new HessianProxyFactory();
        UserServices userservices = (UserServices) factory.create(url);
        List users = userservices.ObtainListUsers();
 
        Iterator ite = users.iterator();
        while (ite.hasNext()) {
            User user = (User) ite.next();
            System.out.print("*******************  \n");
            System.out.print("Name: " + user.getName() + "  \n");
            System.out.print("LasName: " + user.getLasName() + "  \n");
            System.out.print("Email: " + user.getEmail() + "  \n");
        }
    }
}

7.- Y listo!!!!

La verdad es que es muy fácil, aquí les dejo el proyecto entero. Si me quieren dejar un feedback no duden en hacerlo.

http://www.wikio.es BlogESfera - Directorio de Blogs Hispanos blogarama - the blog directory Mi Ping en TotalPing.com
Internet blogs Programming Blogs - Blog Catalog Blog Directory Internet blogs Buzzear (ES) Publicidad por tu blog con Boosterblog directorio de blogs
Agregar Web - Directorio de webs Directorio webs Directorio Web