use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class WSDLMetadataProcessor method process.
@Override
public void process(MetadataFactory mf, WSConnection connection) throws TranslatorException {
if (this.importWSDL && connection == null) {
throw new TranslatorException(WSExecutionFactory.UTIL.gs(Event.TEIID15007, WSExecutionFactory.UTIL.gs(Event.TEIID15007)));
}
if (!importWSDL || connection.getWsdl() == null) {
return;
}
String wsdl = connection.getWsdl().toString();
try {
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader reader = wsdlFactory.newWSDLReader();
this.definition = reader.readWSDL(wsdl);
} catch (WSDLException e) {
throw new TranslatorException(e);
}
Map<QName, Service> services = this.definition.getServices();
if (services == null || services.isEmpty()) {
throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15001, connection.getServiceQName()));
}
Service service = services.get(connection.getServiceQName());
if (service == null) {
throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15001, connection.getServiceQName()));
}
Map<String, Port> ports = service.getPorts();
Port port = ports.get(connection.getPortQName().getLocalPart());
if (port == null) {
throw new TranslatorException(WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15002, connection.getPortQName(), connection.getServiceQName()));
}
getPortMetadata(mf, port);
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class WSProcedureExecution method getOutputParameterValues.
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
Object result = returnValue;
if (returnValue != null && (returnValue instanceof StAXSource) && procedure.getArguments().size() > 4 && procedure.getArguments().get(4).getDirection() == Direction.IN && Boolean.TRUE.equals(procedure.getArguments().get(4).getArgumentValue().getValue())) {
SQLXMLImpl sqlXml = new StAXSQLXML((StAXSource) returnValue);
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
} else if (returnValue != null && returnValue instanceof DOMSource) {
final DOMSource xmlSource = (DOMSource) returnValue;
SQLXMLImpl sqlXml = new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Result outputTarget = new StreamResult(outputStream);
try {
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
} catch (Exception e) {
throw new IOException(e);
}
return new ByteArrayInputStream(outputStream.toByteArray());
}
});
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
}
return Arrays.asList(result);
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class WSWSDLProcedureExecution method execute.
public void execute() throws TranslatorException {
List<Argument> arguments = this.procedure.getArguments();
XMLType docObject = (XMLType) arguments.get(0).getArgumentValue().getValue();
StAXSource source = null;
try {
source = convertToSource(docObject);
Dispatch<StAXSource> dispatch = conn.createDispatch(StAXSource.class, executionFactory.getDefaultServiceMode());
String operation = this.procedure.getProcedureName();
if (this.procedure.getMetadataObject() != null && this.procedure.getMetadataObject().getNameInSource() != null) {
operation = this.procedure.getMetadataObject().getNameInSource();
}
QName opQName = new QName(conn.getServiceQName().getNamespaceURI(), operation);
dispatch.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);
if (source == null) {
// JBoss Native DispatchImpl throws exception when the source is null
// $NON-NLS-1$
source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<none/>")));
}
this.returnValue = dispatch.invoke(source);
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (WebServiceException e) {
throw new TranslatorException(e);
} catch (XMLStreamException e) {
throw new TranslatorException(e);
} catch (IOException e) {
throw new TranslatorException(e);
} finally {
Util.closeSource(source);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class SwaggerTypeManager method formTimestamp.
static Timestamp formTimestamp(String value) throws TranslatorException {
Matcher m = timestampPattern.matcher((String) value);
if (m.matches()) {
Calendar cal = null;
String timeZone = m.group(8);
if (timeZone.equalsIgnoreCase("Z")) {
cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
} else {
cal = Calendar.getInstance(TimeZone.getTimeZone("GMT" + m.group(9)));
}
cal.set(Integer.valueOf(m.group(1)), Integer.valueOf(m.group(2)) - 1, Integer.valueOf(m.group(3)), Integer.valueOf(m.group(4)), Integer.valueOf(m.group(5)), Integer.valueOf(m.group(6)));
Timestamp ts = new Timestamp(cal.getTime().getTime());
if (m.group(7) != null) {
String fraction = m.group(7).substring(1);
ts.setNanos(Integer.parseInt(fraction));
} else {
ts.setNanos(0);
}
return ts;
} else {
throw new TranslatorException(SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28011, timestampPattern));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class TestSwaggerMetadataProcessor method getMetadata.
private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {
protected Swagger getSchema(WSConnection conn) throws TranslatorException {
File f = new File(file);
ObjectMapper objectMapper = new ObjectMapper();
try (FileInputStream fis = new FileInputStream(f)) {
JsonNode rootNode = objectMapper.readTree(fis);
return new SwaggerParser().read(rootNode, true);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
};
processor.setPreferredProduces("application/json");
processor.setPreferredConsumes("application/json");
processor.setPreferredScheme("http");
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.process(mf, null);
return mf;
}
Aggregations