use of javax.resource.ResourceException in project teiid by teiid.
the class ExcelMetadataProcessor method process.
public void process(MetadataFactory mf, FileConnection conn) throws TranslatorException {
if (this.excelFileName == null) {
// $NON-NLS-1$
throw new TranslatorException(ExcelPlugin.Event.TEIID23004, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23004, "importer.ExcelFileName"));
}
try {
File xlsFile = conn.getFile(this.excelFileName);
if (xlsFile.isDirectory()) {
File[] files = xlsFile.listFiles();
if (files.length > 0) {
xlsFile = files[0];
}
}
if (xlsFile.isDirectory() || !xlsFile.exists()) {
throw new TranslatorException(ExcelPlugin.Event.TEIID23005, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23005, xlsFile.getName()));
}
String extension = getFileExtension(xlsFile);
FileInputStream xlsFileStream = new FileInputStream(xlsFile);
try {
Workbook workbook = null;
if (extension.equalsIgnoreCase("xls")) {
// $NON-NLS-1$
workbook = new HSSFWorkbook(xlsFileStream);
} else if (extension.equalsIgnoreCase("xlsx")) {
// $NON-NLS-1$
workbook = new XSSFWorkbook(xlsFileStream);
}
int sheetCount = workbook.getNumberOfSheets();
for (int i = 0; i < sheetCount; i++) {
Sheet sheet = workbook.getSheetAt(i);
addTable(mf, sheet, xlsFile.getName(), this.excelFileName);
}
} finally {
xlsFileStream.close();
}
} catch (ResourceException e) {
throw new TranslatorException(e);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class FileExecutionFactory method createProcedureExecution.
// @Override
public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Connection conn) throws TranslatorException {
if (conn instanceof VirtualFileConnection) {
return new VirtualFileProcedureExecution(command, (VirtualFileConnection) conn);
}
final FileConnection fc = (FileConnection) conn;
if (command.getProcedureName().equalsIgnoreCase(SAVEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
Object file = command.getArguments().get(1).getArgumentValue().getValue();
if (file == null || filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Saving", filePath);
InputStream is = null;
try {
if (file instanceof SQLXML) {
is = ((SQLXML) file).getBinaryStream();
} else if (file instanceof Clob) {
is = new ReaderInputStream(((Clob) file).getCharacterStream(), encoding);
} else if (file instanceof Blob) {
is = ((Blob) file).getBinaryStream();
} else {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("unknown_type"));
}
ObjectConverterUtil.write(is, fc.getFile(filePath));
} catch (IOException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (SQLException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
} else if (command.getProcedureName().equalsIgnoreCase(DELETEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
if (filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Deleting", filePath);
try {
File f = fc.getFile(filePath);
if (!f.exists()) {
if (exceptionIfFileNotFound) {
// $NON-NLS-1$
throw new TranslatorException(DataPlugin.Util.gs("file_not_found", filePath));
}
} else if (!f.delete()) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("error_deleting"));
}
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_deleting"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
}
return new FileProcedureExecution(command, fc);
}
use of javax.resource.ResourceException in project teiid by teiid.
the class FtpManagedConnectionFactory method createClient.
protected FTPClient createClient() throws IOException, ResourceException {
FTPClient client = createClientInstance();
beforeConnectProcessing(client);
client.connect(this.host, this.port);
if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
// $NON-NLS-1$
throw new ResourceException(UTIL.getString("ftp_connect_failed", this.host, this.port));
}
if (!client.login(this.username, this.password)) {
// $NON-NLS-1$
throw new IllegalStateException(UTIL.getString("ftp_login_failed", client.getReplyString()));
}
afterConnectProcessing(client);
return client;
}
use of javax.resource.ResourceException in project teiid by teiid.
the class ConnectorManager method buildCapabilities.
private BasicSourceCapabilities buildCapabilities(ExecutionFactory<Object, Object> translator) throws TranslatorException {
if (translator.isSourceRequiredForCapabilities()) {
Object connection = null;
Object connectionFactory = null;
try {
connectionFactory = getConnectionFactory();
if (connectionFactory != null) {
connection = translator.getConnection(connectionFactory, null);
}
if (connection == null) {
// $NON-NLS-1$);
throw new TranslatorException(QueryPlugin.Event.TEIID31108, QueryPlugin.Util.getString("datasource_not_found", getConnectionName()));
}
if (connection instanceof WrappedConnection) {
try {
connection = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, getConnectionName()));
}
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Initializing the capabilities for", translatorName);
synchronized (executionFactory) {
executionFactory.initCapabilities(connection);
}
} finally {
if (connection != null) {
translator.closeConnection(connection, connectionFactory);
}
}
}
BasicSourceCapabilities resultCaps = CapabilitiesConverter.convertCapabilities(translator, id);
return resultCaps;
}
use of javax.resource.ResourceException in project teiid by teiid.
the class LDAPConnectionImpl method initializeLDAPContext.
/**
* Setup a standard initial LDAP context using JNDI's context factory.
* This method may be extended to support Sun-specific and AD-specific
* contexts, in order to support the different paging implementations they provide.
* @return the initial LDAP Context
*/
private InitialLdapContext initializeLDAPContext() throws ResourceException {
// Create the root context.
InitialLdapContext initContext;
Hashtable connenv = new Hashtable();
connenv.put(Context.INITIAL_CONTEXT_FACTORY, this.config.getLdapContextFactory());
connenv.put(Context.PROVIDER_URL, this.config.getLdapUrl());
connenv.put(Context.REFERRAL, LDAP_REFERRAL_MODE);
String userName = this.config.getLdapAdminUserDN();
String password = this.config.getLdapAdminUserPassword();
String authType = this.config.getLdapAuthType();
// if security-domain is specified and caller identity is used; then use
// credentials from subject
Subject subject = ConnectionContext.getSubject();
if (subject != null) {
userName = ConnectionContext.getUserName(subject, this.config, userName);
password = ConnectionContext.getPassword(subject, this.config, userName, password);
}
connenv.put(Context.SECURITY_AUTHENTICATION, authType);
if (!authType.equals("none")) {
if (userName == null) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPConnection.adminUserDNPropNotFound");
throw new ResourceException(msg);
}
if (password == null) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPConnection.adminUserPassPropNotFound");
throw new ResourceException(msg);
}
connenv.put(Context.SECURITY_PRINCIPAL, userName);
connenv.put(Context.SECURITY_CREDENTIALS, password);
}
if (this.config.getLdapTxnTimeoutInMillis() != null && this.config.getLdapTxnTimeoutInMillis() != -1) {
// $NON-NLS-1$
connenv.put("com.sun.jndi.ldap.connect.timeout", this.config.getLdapTxnTimeoutInMillis().toString());
}
// Enable connection pooling for the Initial context.
// $NON-NLS-1$ //$NON-NLS-2$
connenv.put("com.sun.jndi.ldap.connect.pool", "true");
// $NON-NLS-1$ //$NON-NLS-2$
connenv.put("com.sun.jndi.ldap.connect.pool.debug", "fine");
try {
initContext = new InitialLdapContext(connenv, null);
} catch (NamingException ne) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPConnection.directoryNamingError", ne.getExplanation());
throw new ResourceException(msg, ne);
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Successfully obtained initial LDAP context.");
return initContext;
}
Aggregations