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.
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations