Search in sources :

Example 1 with ASMHelperImpl

use of org.apache.cxf.common.util.ASMHelperImpl in project cxf by apache.

the class JAXBDataBindingTest method testClassInDefaultPackage.

@Test
public void testClassInDefaultPackage() throws Exception {
    Class<?> sampleClassInDefaultPackage = Class.forName("SampleClassInDefaultPackage");
    Set<Class<?>> classes = new HashSet<>();
    Collection<Object> typeReferences = new ArrayList<>();
    Map<String, Object> props = new HashMap<>();
    Bus b = new ExtensionManagerBus();
    b.setExtension(new ASMHelperImpl(), ASMHelper.class);
    FactoryClassCreator extr = new FactoryClassProxyService(b);
    b.setExtension(extr, FactoryClassCreator.class);
    JAXBContextInitializer init = new JAXBContextInitializer(b, null, classes, typeReferences, props);
    init.addClass(sampleClassInDefaultPackage);
    assertEquals(1, classes.size());
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ASMHelperImpl(org.apache.cxf.common.util.ASMHelperImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ASMHelperImpl

use of org.apache.cxf.common.util.ASMHelperImpl in project cxf by apache.

the class JAXBDataBindingTest method doNamespaceMappingTest.

void doNamespaceMappingTest(boolean internal, boolean asm) throws Exception {
    if (internal) {
        try {
            Class.forName("com.sun.xml.internal.bind.v2.ContextFactory");
        } catch (Throwable t) {
            // on a JVM (likely IBM's) that doesn't rename the ContextFactory package to include "internal"
            return;
        }
    }
    Bus b = new ExtensionManagerBus();
    ASMHelper helper = new ASMHelperImpl();
    b.setExtension(helper, ASMHelper.class);
    FactoryClassCreator extr = new FactoryClassProxyService(b);
    b.setExtension(extr, FactoryClassCreator.class);
    try {
        if (!asm) {
            ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelperImpl.class, "badASM")).set(helper, Boolean.TRUE);
        }
        JAXBDataBinding db = createJaxbContext(internal);
        DataWriter<XMLStreamWriter> writer = db.createWriter(XMLStreamWriter.class);
        XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
        StringWriter stringWriter = new StringWriter();
        XMLStreamWriter xmlWriter = writerFactory.createXMLStreamWriter(stringWriter);
        QualifiedBean bean = new QualifiedBean();
        bean.setAriadne("spider");
        writer.write(bean, xmlWriter);
        xmlWriter.flush();
        String xml = stringWriter.toString();
        assertTrue("Failed to map namespace " + xml, xml.contains("greenland=\"uri:ultima:thule"));
    } finally {
        if (!asm) {
            ReflectionUtil.setAccessible(ReflectionUtil.getDeclaredField(ASMHelperImpl.class, "badASM")).set(helper, Boolean.FALSE);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) ASMHelperImpl(org.apache.cxf.common.util.ASMHelperImpl) ASMHelper(org.apache.cxf.common.util.ASMHelper) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QualifiedBean(org.apache.cxf.jaxb.fortest.QualifiedBean) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus)

Example 3 with ASMHelperImpl

use of org.apache.cxf.common.util.ASMHelperImpl in project cxf by apache.

the class JAXBDataBindingTest method testResursiveType.

@Test
public void testResursiveType() throws Exception {
    Set<Class<?>> classes = new HashSet<>();
    Collection<Object> typeReferences = new ArrayList<>();
    Map<String, Object> props = new HashMap<>();
    Bus b = new ExtensionManagerBus();
    b.setExtension(new ASMHelperImpl(), ASMHelper.class);
    FactoryClassCreator extr = new FactoryClassProxyService(b);
    b.setExtension(extr, FactoryClassCreator.class);
    JAXBContextInitializer init = new JAXBContextInitializer(b, null, classes, typeReferences, props);
    init.addClass(Type2.class);
    assertEquals(2, classes.size());
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ASMHelperImpl(org.apache.cxf.common.util.ASMHelperImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ASMHelperImpl

use of org.apache.cxf.common.util.ASMHelperImpl in project cxf by apache.

the class JAXBExtensionHelperTest method setUp.

@Before
public void setUp() throws Exception {
    wsdlFactory = WSDLFactory.newInstance();
    wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    registry = wsdlReader.getExtensionRegistry();
    if (registry == null) {
        registry = wsdlFactory.newPopulatedExtensionRegistry();
    }
    bus = new ExtensionManagerBus();
    bus.setExtension(new ASMHelperImpl(), ASMHelper.class);
    ExtensionClassCreator extr = new ExtensionClassGenerator(bus);
    bus.setExtension(extr, ExtensionClassCreator.class);
}
Also used : ASMHelperImpl(org.apache.cxf.common.util.ASMHelperImpl) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Before(org.junit.Before)

Aggregations

ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)4 ASMHelperImpl (org.apache.cxf.common.util.ASMHelperImpl)4 Bus (org.apache.cxf.Bus)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 ASMHelper (org.apache.cxf.common.util.ASMHelper)1 QualifiedBean (org.apache.cxf.jaxb.fortest.QualifiedBean)1 Before (org.junit.Before)1