Search in sources :

Example 1 with DatabindingException

use of com.sun.xml.ws.spi.db.DatabindingException in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIBasicTest method testHelloEchoInvalidDB.

public void testHelloEchoInvalidDB() throws Exception {
    Class endpointClass = HelloImpl.class;
    Class proxySEIClass = HelloPort.class;
    DatabindingConfig srvConfig = new DatabindingConfig();
    srvConfig.setEndpointClass(endpointClass);
    srvConfig.setMetadataReader(new DummyAnnotations());
    WebServiceFeature[] f = { new DatabindingModeFeature("invalid.db") };
    srvConfig.setFeatures(f);
    DatabindingConfig cliConfig = new DatabindingConfig();
    cliConfig.setMetadataReader(new DummyAnnotations());
    cliConfig.setContractClass(proxySEIClass);
    cliConfig.setFeatures(f);
    try {
        HelloPort hp = createProxy(HelloPort.class, srvConfig, cliConfig, false);
        fail("Expected DatabindingException not thrown");
    } catch (DatabindingException e) {
    // expected exception.
    }
}
Also used : DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) DummyAnnotations(com.sun.xml.ws.base.DummyAnnotations) HelloImpl(com.sun.xml.ws.test.HelloImpl) HelloPort(com.sun.xml.ws.test.HelloPort) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) DatabindingModeFeature(com.oracle.webservices.api.databinding.DatabindingModeFeature)

Example 2 with DatabindingException

use of com.sun.xml.ws.spi.db.DatabindingException in project metro-jax-ws by eclipse-ee4j.

the class WrapperBond method marshal.

@Override
public final void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
    WrapperComposite w = (WrapperComposite) object;
    try {
        // output.writeStartElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart());
        // System.out.println(typeInfo.tagName.getNamespaceURI());
        // The prefix is to workaround an eclipselink bug
        output.writeStartElement(WrapperPrefix, typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
        output.writeNamespace(WrapperPrefix, typeInfo.tagName.getNamespaceURI());
    // output.writeStartElement("", typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
    // output.writeDefaultNamespace(typeInfo.tagName.getNamespaceURI());
    // System.out.println("======== " + output.getPrefix(typeInfo.tagName.getNamespaceURI()));
    // System.out.println("======== " + output.getNamespaceContext().getPrefix(typeInfo.tagName.getNamespaceURI()));
    // System.out.println("======== " + output.getNamespaceContext().getNamespaceURI(""));
    } catch (XMLStreamException e) {
        e.printStackTrace();
        throw new DatabindingException(e);
    }
    if (w.bridges != null)
        for (int i = 0; i < w.bridges.length; i++) {
            if (w.bridges[i] instanceof RepeatedElementBridge) {
                RepeatedElementBridge rbridge = (RepeatedElementBridge) w.bridges[i];
                for (Iterator itr = rbridge.collectionHandler().iterator(w.values[i]); itr.hasNext(); ) {
                    rbridge.marshal(itr.next(), output, am);
                }
            } else {
                w.bridges[i].marshal(w.values[i], output, am);
            }
        }
    try {
        output.writeEndElement();
    } catch (XMLStreamException e) {
        throw new DatabindingException(e);
    }
}
Also used : DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) RepeatedElementBridge(com.sun.xml.ws.spi.db.RepeatedElementBridge) XMLStreamException(javax.xml.stream.XMLStreamException) Iterator(java.util.Iterator) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite)

Example 3 with DatabindingException

use of com.sun.xml.ws.spi.db.DatabindingException in project metro-jax-ws by eclipse-ee4j.

the class JAXBContextFactory method repeatedWrapee.

private static TypeInfo repeatedWrapee(TypeInfo e, Element xmlAnn) {
    XmlElement xe = getAnnotation(e, XmlElement.class);
    if (xe != null) {
        e.type = xe.type();
    }
    if (xmlAnn != null) {
        String typeAttr = xmlAnn.getAttribute("type");
        if (typeAttr != null) {
            try {
                Class<?> cls = Class.forName(typeAttr);
                e.type = cls;
            } catch (ClassNotFoundException e1) {
                throw new DatabindingException(e1.getMessage(), e1);
            }
        }
    }
    return e;
}
Also used : DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) XmlElement(jakarta.xml.bind.annotation.XmlElement)

Example 4 with DatabindingException

use of com.sun.xml.ws.spi.db.DatabindingException in project metro-jax-ws by eclipse-ee4j.

the class JAXBContextFactory method newContext.

@Override
protected BindingContext newContext(BindingInfo bi) {
    Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
    Map<String, Object> properties = new HashMap<>();
    Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
    // chen workaround for document-literal wrapper - new feature on eclipselink API requested
    for (TypeInfo tinfo : map.keySet()) {
        WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
        if (wp != null) {
            Class<?> wrpCls = (Class) tinfo.type;
            Element javaAttributes = null;
            for (ParameterImpl p : wp.getWrapperChildren()) {
                Element xmlelem = findXmlElement(p.getTypeInfo().properties());
                if (xmlelem != null) {
                    if (javaAttributes == null) {
                        javaAttributes = javaAttributes(wrpCls, extMapping);
                    }
                    xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
                    String fieldName = getFieldName(p, wrpCls);
                    xmlelem.setAttribute("java-attribute", fieldName);
                    javaAttributes.appendChild(xmlelem);
                }
            }
            if (wrpCls.getPackage() != null)
                wrpCls.getPackage().getName();
        }
    }
    // Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
    // if (src != null){
    // TransformerFactory tf = TransformerFactory.newInstance();
    // try {
    // Transformer t = tf.newTransformer();
    // java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
    // StreamResult sax = new StreamResult(bo);
    // t.transform(src, sax);
    // System.out.println(new String(bo.toByteArray()));
    // } catch (TransformerConfigurationException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // } catch (TransformerException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // }
    // }
    HashSet<Type> typeSet = new HashSet<>();
    HashSet<TypeMappingInfo> typeList = new HashSet<>();
    for (TypeMappingInfo tmi : map.values()) {
        typeList.add(tmi);
        typeSet.add(tmi.getType());
    }
    for (Class<?> clss : bi.contentClasses()) {
        if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
            typeSet.add(clss);
            TypeMappingInfo tmi = new TypeMappingInfo();
            tmi.setType(clss);
            typeList.add(tmi);
        }
    }
    TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
    if (extMapping != null) {
        properties.put(OXM_XML_OVERRIDE, extMapping);
    }
    if (bi.getDefaultNamespace() != null) {
        properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
    }
    try {
        org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
        return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
    } catch (JAXBException e) {
        throw new DatabindingException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) XmlElement(jakarta.xml.bind.annotation.XmlElement) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) JAXBContext(jakarta.xml.bind.JAXBContext) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) HashSet(java.util.HashSet) JAXBException(jakarta.xml.bind.JAXBException) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlType(jakarta.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with DatabindingException

use of com.sun.xml.ws.spi.db.DatabindingException in project metro-jax-ws by eclipse-ee4j.

the class WrapperBond method marshal.

@Override
public final void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
    WrapperComposite w = (WrapperComposite) object;
    try {
        // output.writeStartElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart());
        // System.out.println(typeInfo.tagName.getNamespaceURI());
        // The prefix is to workaround an eclipselink bug
        output.writeStartElement(WrapperPrefix, typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
        output.writeNamespace(WrapperPrefix, typeInfo.tagName.getNamespaceURI());
    // output.writeStartElement("", typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
    // output.writeDefaultNamespace(typeInfo.tagName.getNamespaceURI());
    // System.out.println("======== " + output.getPrefix(typeInfo.tagName.getNamespaceURI()));
    // System.out.println("======== " + output.getNamespaceContext().getPrefix(typeInfo.tagName.getNamespaceURI()));
    // System.out.println("======== " + output.getNamespaceContext().getNamespaceURI(""));
    } catch (XMLStreamException e) {
        // e.printStackTrace();
        throw new DatabindingException(e);
    }
    if (w.bridges != null) {
        for (int i = 0; i < w.bridges.length; i++) {
            // System.out.println("======== bond " + w.bridges[i].getTypeInfo().tagName);
            w.bridges[i].marshal(w.values[i], output, am);
        }
    }
    try {
        output.writeEndElement();
    } catch (XMLStreamException e) {
        throw new DatabindingException(e);
    }
}
Also used : DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) XMLStreamException(javax.xml.stream.XMLStreamException) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite)

Aggregations

DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)6 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)2 WrapperComposite (com.sun.xml.ws.spi.db.WrapperComposite)2 XmlElement (jakarta.xml.bind.annotation.XmlElement)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)1 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)1 DummyAnnotations (com.sun.xml.ws.base.DummyAnnotations)1 JAXBContextFactory (com.sun.xml.ws.developer.JAXBContextFactory)1 ParameterImpl (com.sun.xml.ws.model.ParameterImpl)1 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)1 RepeatedElementBridge (com.sun.xml.ws.spi.db.RepeatedElementBridge)1 HelloImpl (com.sun.xml.ws.test.HelloImpl)1 HelloPort (com.sun.xml.ws.test.HelloPort)1 JAXBContext (jakarta.xml.bind.JAXBContext)1 JAXBException (jakarta.xml.bind.JAXBException)1 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)1 XmlType (jakarta.xml.bind.annotation.XmlType)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 GenericArrayType (java.lang.reflect.GenericArrayType)1