XFire Aegis

1. Introduction

XFire and Aegis is very old and currently deprecated. I was used for mapping SOAP webservices.

1.1. References

What is Aegis? (Usage of minOccurs, nillable, etc.)

http://cxf.apache.org/docs/aegis-21.html


Aegis default Xfire binding method, mapping XML to POJO

https://www.programmersought.com/article/1260324758/


WebService application --- interface return parameters are problems encountered by List

https://www.programmersought.com/article/203365342/


Problem when trying to add method to a web services,

https://www.genuitec.com/forums/topic/problem-when-trying-to-add-method-to-a-web-services/


XFire, Spring and JSR181 tutorial

https://murci.wordpress.com/2006/02/02/xfire-spring-and-jsr181-tutorial/



2. WS Interface

org.myapp.service.MyService.java

public Set<ClassroomAssignmentDto> getClassroomAssignmentsO80(final String calendarCode) throws WSException;


org.myapp.model.ClassroomAssignmentDto.java

public class ClassroomAssignmentDto implements Serializable {

private String sample1;

private Set<Boolean> sample2;


private javax.xml.datatype.XMLGregorianCalendar birthDate;


public String getSample1() {

return sample1;

}


public void setSample1(String sample1) {

this.sample1 = sample1;

}


public Set<Boolean> getSample2() {

return sample2;

}


public void setSample2(Set<Boolean> sample2) {

this.sample2 = sample2;

}


public javax.xml.datatype.XMLGregorianCalendar getBirthDate() {

return this.birthDate;

}


public void setBirthDate(java.util.Date d)

throws DatatypeConfigurationException {

XMLGregorianCalendar v;

if (d == null) {

v = null;

} else {

GregorianCalendar c = new GregorianCalendar();

c.setTime(d);

v = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

}


this.birthDate = v;

}


}


2. Aegis mapping

Note that Aegis mapping files must be in the same package as the file it is mapping.


src/main/resources/org/myapp/model/MyService.aegis.xml

<method name="getClassroomAssignmentsO80">

<parameter index="0" mappedName="calendarCode"/>

<return-type mappedName="classroomAssignments" componentType="org.myapp.model.ClassroomAssignmentDto" />

</method>


src/main/resources/org/myapp/model/ClassroomAssignmentDto.aegis.xml

<?xml version="1.0" encoding="UTF-8"?>

<mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xfire.codehaus.org/schemas/1.0/mapping.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<mapping>

<property name="sample2" componentType="java.lang.Boolean" />


<property name="birthDate" type="org.codehaus.xfire.aegis.type.basic.DateType" typeName="xsd:date" />


<method name="getSample2">

<return-type componentType="java.lang.Boolean" />

</method>

</mapping>

</mappings>


Notes

a) "xsd:date" requires: xmlns:xsd="http://www.w3.org/2001/XMLSchema",

the attribute type is defined as XMLGregorianCalendar, a setter converts from hibernate java.sql.Date

and the .war maven module needs the xfire-aegis dependency for the package org.codehaus.xfire.aegis.type.basic:

<!-- XFire Spring Support -->

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-spring</artifactId>

</dependency>

<!-- XFire Aegis Binding [org.codehaus.xfire.aegis.type.basic.DateType] -->

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-aegis</artifactId>

</dependency>

<!-- XFire Java 5 Module -->

<dependency>

<groupId>org.codehaus.xfire</groupId>

<artifactId>xfire-java5</artifactId>

</dependency>

3. Hibernate to Java Bean mapping

3.1. Boolean

If, eg, Oracle table has field type varchar(1) with values {null, "N", "Y"} for representing boolean values then it can be mapped by hibernate to a Java Bean attribute of type Boolean:

<sql-query name="qryGetClassroomAssignmentsO80">

<![CDATA[

SELECT

case my_field when 'N' then 0 when 'Y' then 1 else null end AS "studentTitleTransferedToFinal"

FROM sit_repos

]]>

<return-scalar column="studentTitleTransferedToFinal" type="boolean"/>

</sql-query>



4. WebService client (XFire)

4.1. WS Client from WSDL (XFire)

XFire builds the web service client in five ways:

https://ofstack.com/Java/22664/xfire-builds-the-web-service-client-in-five-ways.html



4.2. WS client from JAR (XFire & metadata .jar)

Sample app: cat evaluationBoard

Having in pom.xml the dependency evalutation-metadata

// Declare singleton

AvaluacioService avaluacioClient;


// Method for obtaining the catEvaluationPort

/**

* Obtain catEvaluationPort for the WS of cat evaluation.

* @return The catEvaluationPort

*/

public AvaluacioService getAvaluacioClient() {

if (avaluacioClient == null) {

String uriAvaluacioService = "/avaluacio-ws/services/AvaluacioService";

String host = System.getProperty("host");


Service srvcModel = new ObjectServiceFactory()

.create(AvaluacioService.class);

XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());

try {

avaluacioClient = (AvaluacioService) factory

.create(srvcModel, host + uriAvaluacioService);

} catch (MalformedURLException e) {

log.error(e.getMessage(),e);

}


}

return avaluacioClient;

}