Skip to content

Commit

Permalink
undating Smooks to 2.0.0-M3
Browse files Browse the repository at this point in the history
  • Loading branch information
maeste authored and asoldano committed Jul 5, 2021
1 parent 1c1257f commit 2813995
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 101 deletions.
7 changes: 5 additions & 2 deletions core/pom.xml
Expand Up @@ -79,8 +79,11 @@
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>

<dependency>
<groupId>org.smooks</groupId>
<artifactId>smooks-core</artifactId>
</dependency>
<!--<dependency>
<groupId>org.milyn</groupId>
<artifactId>milyn-smooks-core</artifactId>
</dependency>
Expand All @@ -98,7 +101,7 @@
<dependency>
<groupId>org.milyn</groupId>
<artifactId>milyn-smooks-validation</artifactId>
</dependency>
</dependency>-->

<dependency>
<groupId>net.jcip</groupId>
Expand Down
Expand Up @@ -24,7 +24,8 @@
import net.jcip.annotations.ThreadSafe;

import org.jboss.wise.core.wsextensions.EnablerDelegate;
import org.milyn.Smooks;
import org.smooks.Smooks;


/**
* This is the Wise core class responsible to invoke the JAX-WS tools that handles wsdl retrieval &amp; parsing. It is used to
Expand Down
Expand Up @@ -30,7 +30,8 @@
import org.jboss.wise.core.exception.WiseRuntimeException;
import org.jboss.wise.core.wsextensions.EnablerDelegate;
import org.jboss.wise.core.wsextensions.EnablerDelegateProvider;
import org.milyn.Smooks;
import org.smooks.Smooks;


/**
* This is the Wise core, i.e. the JAX-WS client that handles wsdl retrieval &amp; parsing, invocations, etc.
Expand Down
34 changes: 17 additions & 17 deletions core/src/main/java/org/jboss/wise/core/handlers/SmooksHandler.java
Expand Up @@ -49,18 +49,18 @@
import org.jboss.wise.core.client.WSDynamicClient;
import org.jboss.wise.core.exception.WiseRuntimeException;
import org.jboss.wise.core.mapper.SmooksMapper;
import org.milyn.Smooks;
import org.milyn.SmooksUtil;
import org.milyn.cdr.SmooksResourceConfiguration;
import org.milyn.cdr.SmooksResourceConfigurationList;
import org.milyn.cdr.XMLConfigDigester;
import org.milyn.container.ExecutionContext;
import org.milyn.event.report.HtmlReportGenerator;
import org.milyn.javabean.context.BeanContext;
import org.milyn.profile.DefaultProfileSet;
import org.milyn.profile.ProfileStore;
import org.milyn.profile.UnknownProfileMemberException;
import org.milyn.resource.URIResourceLocator;
import org.smooks.Smooks;
import org.smooks.api.ExecutionContext;
import org.smooks.api.bean.context.BeanContext;
import org.smooks.api.profile.ProfileStore;
import org.smooks.api.profile.UnknownProfileMemberException;
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.config.ResourceConfigSeq;
import org.smooks.engine.profile.DefaultProfileSet;
import org.smooks.engine.report.HtmlReportGenerator;
import org.smooks.engine.resource.config.XMLConfigDigester;
import org.smooks.resource.URIResourceLocator;
import org.smooks.support.SmooksUtil;
import org.jboss.wise.core.i18n.Messages;

/**
Expand Down Expand Up @@ -108,15 +108,15 @@ public SmooksHandler(String smooksResource, Map<String, Object> beans, WSDynamic

synchronized (SmooksMapper.class) {
// Register the message flow within the Smooks context....
SmooksUtil.registerProfileSet(DefaultProfileSet.create(Integer.toString(this.hashCode()), new String[] {}),
SmooksUtil.registerProfileSet(new DefaultProfileSet(Integer.toString(this.hashCode()), new String[] {}),
smooks);
}
}
SmooksResourceConfigurationList list = XMLConfigDigester.digestConfig(smooksResourceStream, "wise");
ResourceConfigSeq list = XMLConfigDigester.digestConfig(smooksResourceStream, "wise");
for (int i = 0; i < list.size(); i++) {
SmooksResourceConfiguration smookResourceElement = list.get(i);
ResourceConfig smookResourceElement = list.get(i);
smookResourceElement.setTargetProfile(Integer.toString(this.hashCode()));
SmooksUtil.registerResource(smookResourceElement, smooks);
smooks.addConfiguration(smookResourceElement);
}

this.smooksReport = smooksReport;
Expand Down Expand Up @@ -162,7 +162,7 @@ public boolean handleMessage(SOAPMessageContext smc) {
ExecutionContext executionContext = smooks.createExecutionContext(Integer.toString(this.hashCode()));
if (smooksReport != null) {
try {
executionContext.setEventListener(new HtmlReportGenerator(smooksReport));
executionContext.getContentDeliveryRuntime().addExecutionEventListener(new HtmlReportGenerator(smooksReport));
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(Messages.MESSAGES.errorDuringLoading(smooksReport, e.getMessage()));
Expand Down
36 changes: 18 additions & 18 deletions core/src/main/java/org/jboss/wise/core/mapper/SmooksMapper.java
Expand Up @@ -38,20 +38,20 @@
import org.jboss.wise.core.client.WSDynamicClient;
import org.jboss.wise.core.exception.MappingException;
import org.jboss.wise.core.exception.WiseRuntimeException;
import org.milyn.Smooks;
import org.milyn.SmooksUtil;
import org.milyn.cdr.SmooksResourceConfiguration;
import org.milyn.cdr.SmooksResourceConfigurationList;
import org.milyn.cdr.XMLConfigDigester;
import org.milyn.container.ExecutionContext;
import org.milyn.event.report.HtmlReportGenerator;
import org.milyn.payload.JavaResult;
import org.milyn.payload.JavaSource;
import org.milyn.profile.DefaultProfileSet;
import org.milyn.profile.ProfileStore;
import org.milyn.profile.UnknownProfileMemberException;
import org.milyn.resource.URIResourceLocator;
import org.jboss.wise.core.i18n.Messages;
import org.smooks.Smooks;
import org.smooks.api.ExecutionContext;
import org.smooks.api.profile.ProfileStore;
import org.smooks.api.profile.UnknownProfileMemberException;
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.config.ResourceConfigSeq;
import org.smooks.engine.profile.DefaultProfileSet;
import org.smooks.engine.report.HtmlReportGenerator;
import org.smooks.engine.resource.config.XMLConfigDigester;
import org.smooks.io.payload.JavaResult;
import org.smooks.io.payload.JavaSource;
import org.smooks.resource.URIResourceLocator;
import org.smooks.support.SmooksUtil;

/**
* A WiseMapper based on smooks
Expand Down Expand Up @@ -86,15 +86,15 @@ public SmooksMapper(String smooksResource, String smooksReport, WSDynamicClient

synchronized (SmooksMapper.class) {
// Register the message flow within the Smooks context....
SmooksUtil.registerProfileSet(DefaultProfileSet.create(Integer.toString(this.hashCode()), new String[] {}),
SmooksUtil.registerProfileSet(new DefaultProfileSet(Integer.toString(this.hashCode()), new String[] {}),
smooks);
}
}
SmooksResourceConfigurationList list = XMLConfigDigester.digestConfig(smooksResourceStream, "wise");
ResourceConfigSeq list = XMLConfigDigester.digestConfig(smooksResourceStream, "wise");
for (int i = 0; i < list.size(); i++) {
SmooksResourceConfiguration smookResourceElement = list.get(i);
ResourceConfig smookResourceElement = list.get(i);
smookResourceElement.setTargetProfile(Integer.toString(this.hashCode()));
SmooksUtil.registerResource(smookResourceElement, smooks);
smooks.addConfiguration(smookResourceElement);
}
// smooks.addConfigurations(Integer.toString(this.hashCode()), new
// URIResourceLocator().getResource(smooksResource));
Expand All @@ -113,7 +113,7 @@ public SmooksMapper(String smooksResource, String smooksReport, WSDynamicClient
ExecutionContext executionContext = smooks.createExecutionContext(Integer.toString(this.hashCode()));
if (smooksReport != null) {
try {
executionContext.setEventListener(new HtmlReportGenerator(smooksReport));
executionContext.getContentDeliveryRuntime().addExecutionEventListener(new HtmlReportGenerator(smooksReport));
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(Messages.MESSAGES.errorDuringLoading(smooksReport, e.getMessage()));
Expand Down
Expand Up @@ -24,29 +24,27 @@
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
import org.milyn.javabean.DataDecodeException;
import org.milyn.javabean.DataDecoder;
import org.milyn.javabean.DecodeType;
import org.milyn.javabean.decoders.DateDecoder;
import org.smooks.api.bean.repository.*;
import org.smooks.api.converter.TypeConverter;
import org.smooks.api.converter.TypeConverterException;

/**
* {@link javax.xml.datatype.Duration} data decoder.
*
* Decodes the supplied string into a {@link javax.xml.datatype.Duration} String value is supposed to be milliseconds
* representing this Duration
*/
@DecodeType(Duration.class)
public class DurationDecoder extends DateDecoder implements DataDecoder {
public class DurationDecoder implements TypeConverter <String, Duration> {

@Override
public Object decode(String data) throws DataDecodeException {
Object result = null;
public Duration convert(String data) throws TypeConverterException {
Duration result = null;
try {
result = DatatypeFactory.newInstance().newDuration(Long.parseLong(data));
} catch (DatatypeConfigurationException e) {
throw new DataDecodeException("Error decoding Duration data value '" + data, e);
throw new TypeConverterException("Error decoding Duration data value '" + data, e);
} catch (NumberFormatException e) {
throw new DataDecodeException("Error decoding Duration data value '" + data, e);
throw new TypeConverterException("Error decoding Duration data value '" + data, e);
}

return result;
Expand Down
Expand Up @@ -21,13 +21,15 @@
*/
package org.jboss.wise.smooks.decoders;

import java.util.Properties;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.milyn.cdr.SmooksConfigurationException;
import org.milyn.cdr.SmooksResourceConfiguration;
import org.milyn.javabean.DataDecodeException;
import org.milyn.javabean.DataDecoder;
import org.milyn.javabean.DecodeType;

import org.smooks.api.SmooksConfigException;
import org.smooks.api.converter.TypeConverter;
import org.smooks.api.converter.TypeConverterException;
import org.smooks.api.resource.config.Configurable;

/**
* {@link javax.xml.datatype.Duration} data decoder.
Expand All @@ -36,21 +38,28 @@
* IOW what it does under the wood is: new JAXBElement&lt;String&gt;(new QName(nameSpaceURI, localPart), String.class, String
* data);
*/
@DecodeType(JAXBElement.class)
public class JAXBElementDecoder implements DataDecoder {

public class JAXBElementDecoder implements TypeConverter <String, JAXBElement>, Configurable {
String nameSpaceURI = null;

String localPart = null;

public void setConfiguration(SmooksResourceConfiguration resourceConfig) throws SmooksConfigurationException {
nameSpaceURI = resourceConfig.getStringParameter("namespaceURI");
localPart = resourceConfig.getStringParameter("localPart");
Properties properties;

public void setConfiguration(Properties properties) throws SmooksConfigException {
this.properties = properties;
nameSpaceURI = properties.getProperty("namespaceURI");
localPart = properties.getProperty("localPart");
if (nameSpaceURI == null || localPart == null) {
throw new SmooksConfigurationException("Decoder must specify a QName namespaceURI and a localPart parameter.");
throw new SmooksConfigException("Decoder must specify a QName namespaceURI and a localPart parameter.");
}
}

public Object decode(String data) throws DataDecodeException {
public Properties getConfiguration() {
return properties;
}

public JAXBElement convert(String data) throws TypeConverterException {
return new JAXBElement<String>(new QName(nameSpaceURI, localPart), String.class, data);
}
}
Expand Up @@ -27,10 +27,9 @@
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.milyn.javabean.DataDecodeException;
import org.milyn.javabean.DataDecoder;
import org.milyn.javabean.DecodeType;
import org.milyn.javabean.decoders.DateDecoder;
import org.smooks.api.converter.TypeConverter;
import org.smooks.api.converter.TypeConverterException;
import org.smooks.engine.converter.StringToDateConverterFactory.StringToDateConverter;

/**
* {@link javax.xml.datatype.XMLGregorianCalendar} data decoder.
Expand All @@ -46,21 +45,19 @@
*
* @author <a href="mailto:stefano.maestri@javalinux.it">stefano.maestri@javalinux.it</a>
*/
@DecodeType(XMLGregorianCalendar.class)
public class XMLGregorianCalendarDecoder extends DateDecoder implements DataDecoder {
public class XMLGregorianCalendarDecoder implements TypeConverter<String, XMLGregorianCalendar> {

@Override
public Object decode(String data) throws DataDecodeException {
Date date = (Date) super.decode(data);
public XMLGregorianCalendar convert(String data) throws TypeConverterException {
Date date = (Date) new StringToDateConverter().convert(data);

Object result = null;
XMLGregorianCalendar result = null;
try {
GregorianCalendar gregCal = new GregorianCalendar();
gregCal.setTime(date);
result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
} catch (DatatypeConfigurationException e) {
throw new DataDecodeException("Error decoding XMLGregorianCalendar data value '" + data + "' with decode format '"
+ format + "'.", e);
throw new TypeConverterException("Error decoding XMLGregorianCalendar data value '" + data, e);
}
return result;
}
Expand Down
Expand Up @@ -50,7 +50,8 @@
import org.jboss.wise.core.exception.ResourceNotAvailableException;
import org.junit.Before;
import org.junit.Test;
import org.milyn.Smooks;
import org.smooks.Smooks;


/**
* This is the Wise core, i.e. the JAX-WS client that handles wsdl retrieval & parsing, invocations, etc.
Expand Down
Expand Up @@ -43,8 +43,8 @@
import org.jboss.wise.core.mapper.mappingObject.ExternalObject;
import org.jboss.wise.core.mapper.mappingObject.InternalObject;
import org.junit.Test;
import org.milyn.Smooks;
import org.milyn.container.ExecutionContext;
import org.smooks.Smooks;
import org.smooks.api.ExecutionContext;

/**
* @author stefano.maestri@javalinux.it
Expand Down Expand Up @@ -132,9 +132,9 @@ public void shouldHaveDifferentContentDeliveryConfigurationPerxecutionContext()
ExecutionContext context2 = mapper2.initExecutionContext(null);
ExecutionContext context3 = mapper3.initExecutionContext(null);

assertThat(context.getDeliveryConfig(), not(is(context2.getDeliveryConfig())));
assertThat(context.getDeliveryConfig(), not(is(context3.getDeliveryConfig())));
assertThat(context2.getDeliveryConfig(), not(is(context3.getDeliveryConfig())));
assertThat(context.getContentDeliveryRuntime(), not(is(context2.getContentDeliveryRuntime())));
assertThat(context.getContentDeliveryRuntime(), not(is(context3.getContentDeliveryRuntime())));
assertThat(context2.getContentDeliveryRuntime(), not(is(context3.getContentDeliveryRuntime())));

}
}
Expand Up @@ -25,20 +25,20 @@
import static org.junit.Assert.assertThat;
import javax.xml.datatype.Duration;
import org.junit.Test;
import org.milyn.javabean.DataDecodeException;
import org.smooks.api.converter.TypeConverterException;

public class DurationDecoderTest {

@Test(expected = DataDecodeException.class)
@Test(expected = TypeConverterException.class)
public void shouldThrowExceptionIfDatIsNotANumber() {
DurationDecoder decoder = new DurationDecoder();
decoder.decode("aa");
decoder.convert("aa");
}

@Test
public void shouldReturnDurationAccordingCOnfig() {
DurationDecoder decoder = new DurationDecoder();
assertThat(((Duration) decoder.decode("1000")).getSeconds(), equalTo(1));
assertThat(((Duration) decoder.convert("1000")).getSeconds(), equalTo(1));
}

}

0 comments on commit 2813995

Please sign in to comment.