Index: pom.xml =================================================================== --- pom.xml (revision 27881) +++ pom.xml (working copy) @@ -9,7 +9,7 @@ Petals ESB :: JBI descriptor library petals-jbi-descriptor org.ow2.petals - 2.0.4 + 2.0.5-SNAPSHOT The JBI descriptor data binding jar Index: src/main/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilder.java =================================================================== --- src/main/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilder.java (revision 27881) +++ src/main/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilder.java (working copy) @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.StringWriter; import java.net.URL; @@ -253,7 +254,10 @@ * @throws JBIDescriptorException * The exception raised during the marshaller creation or the exception * raised during the build of the XML string. + * + * @deprecated Because of an encoding problem, use {@link #writeJBIdescriptor(Jbi, OutputStream)} */ + @Deprecated public static String buildXmlStringJBIdescriptor(final Jbi jbiDescriptorClass) throws JBIDescriptorException { @@ -270,6 +274,32 @@ "Failed to build XML binding from JBI descriptor Java classes", e); } } + + /** + *

Write the JBI descriptor XML into an output stream.

+ *

Note: The output stream is not close by this method.

+ * + * @param jbiDescriptorClass + * The JBI Descriptor root class + * @param jbiDescrOutputStream + * The output stream where the JBI descriptor will be written + * @throws JBIDescriptorException + * The exception raised during the marshaller creation or the + * exception raised during the build of the XML string. + */ + public static void writeJBIdescriptor(final Jbi jbiDescriptorClass, final OutputStream jbiDescrOutputStream) + throws JBIDescriptorException { + + try { + // The default Xerces marshaller is not thread safe + synchronized (marshallerSync) { + getMarshaller().marshal(jbiDescriptorClass, jbiDescrOutputStream); + } + } catch (JAXBException e) { + throw new JBIDescriptorException( + "Failed to build XML binding from JBI descriptor Java classes", e); + } + } /** * Get the unmarshaller instance. Index: src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java =================================================================== --- src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java (revision 0) +++ src/test/java/org/ow2/petals/jbi/descriptor/original/JBIDescriptorBuilderTestCase.java (revision 0) @@ -0,0 +1,83 @@ +package org.ow2.petals.jbi.descriptor.original; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import junit.framework.TestCase; + +import org.ow2.petals.jbi.descriptor.JBIDescriptorException; +import org.ow2.petals.jbi.descriptor.original.generated.Component; +import org.ow2.petals.jbi.descriptor.original.generated.Identification; +import org.ow2.petals.jbi.descriptor.original.generated.Jbi; + +public class JBIDescriptorBuilderTestCase extends TestCase { + + private final static String BCSOAP_JBI_DESC = "bcsoap.jbi.xml"; + + /** + * Read a valid JBI descriptor, next save it, and finally read the saved + * version. + * + * @throws JBIDescriptorException + * @throws IOException + */ + public void testBuildXmlStringJBIDescriptor_000() throws JBIDescriptorException, IOException { + + // 1 - Read the original JBI descriptor + final InputStream jbiDescriptorStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(BCSOAP_JBI_DESC); + final Jbi bcSoapJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(jbiDescriptorStream); + + // 2 - Temporary saved an instance of the read JBI descriptor + final String strJbiDescr = JBIDescriptorBuilder.buildXmlStringJBIdescriptor(bcSoapJbiDesc); + final File tempJbiDescr = File.createTempFile("bcsoap", "jbi.xml"); + final OutputStream os = new FileOutputStream(tempJbiDescr); + os.write(strJbiDescr.getBytes()); + os.close(); + + // 3 - Read the temporary JBI descriptor + final InputStream is = new FileInputStream(tempJbiDescr); + final Jbi tempJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(is); + + assertNotNull(tempJbiDesc); + + } + + /** + * Read a valid JBI descriptor, update it with characters with accent, next save it, and finally read the saved + * version. + * + * @throws JBIDescriptorException + * @throws IOException + */ + public void testBuildXmlStringJBIDescriptor_001() throws JBIDescriptorException, IOException { + + // 1 - Read the original JBI descriptor + final InputStream jbiDescriptorStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(BCSOAP_JBI_DESC); + final Jbi bcSoapJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(jbiDescriptorStream); + + // 2 - Update the read JBI descriptor with special character (with french accent) + final Component comp = bcSoapJbiDesc.getComponent(); + assertNotNull(comp); + final Identification ident = comp.getIdentification(); + assertNotNull(ident); + ident.setDescription("My french characters: [éèçàù€ïîê]"); + + // 3 - Temporary saved an instance of the read JBI descriptor + final File tempJbiDescr = File.createTempFile("bcsoap", "jbi.xml"); + final OutputStream os = new FileOutputStream(tempJbiDescr); + JBIDescriptorBuilder.writeJBIdescriptor(bcSoapJbiDesc, os); + os.close(); + + // 4 - Read the temporary JBI descriptor + final InputStream is = new FileInputStream(tempJbiDescr); + final Jbi tempJbiDesc = JBIDescriptorBuilder.buildJavaJBIDescriptor(is); + + assertNotNull(tempJbiDesc); + + } + +} Index: src/test/resources/bcsoap.jbi.xml =================================================================== --- src/test/resources/bcsoap.jbi.xml (revision 0) +++ src/test/resources/bcsoap.jbi.xml (revision 0) @@ -0,0 +1,35 @@ + + + + + petals-bc-soap + The SOAP Binding Component (based on Axis2 + Jetty) + + org.ow2.petals.binding.soap.SoapComponent + + org.ow2.petals.binding.soap.SoapBootstrap + + + 5 + 10 + DONE_AND_ERROR_IGNORED + + false + 1 + org.ow2.petals.binding.soap.listener.outgoing.JBIListener + org.ow2.petals.binding.soap.listener.incoming.SoapExternalListener + + 8084 + + true + petals + services + 2 + 50 + 4 + +