JNDI Context Initialization error while migration from WAS to liberty - jms

The WsnInitialContextFactory class not found exception. Liberty does not support this class, then how can I remove jndi.properties default settings. This property file contain this class name for InitialContext.
Properties:
INITIAL_CONTEXT_FACTORY = "com.ibm.websphere.naming.WsnInitialContextFactory"
CC_PROVIDER_URL = "iiop://localhost.svr.us.xxxxxxx.net:41516"
InitialContext Lookup:
try {
Hashtable params = new Hashtable();
params.put(Context.INITIAL_CONTEXT_FACTORY, ADProperties.WS_INITIAL_CONTEXT_FACTORY);
params.put(Context.PROVIDER_URL, ADProperties.AD_PROVIDER_URL);
Context ctx = new InitialContext(params);
try {
ds = (DataSource) ctx.lookup("java:comp/env/" + jndiName);
} catch (Exception ex) {
LogUtil.debugException("DBConnectionManager", "Exception in init: Resource reference DataSource lookup Error.", "init()", ex, "");
try {
ds = (DataSource) ctx.lookup("jdbc/" + jndiName);
} catch (Exception exp) {
LogUtil.debugException("DBConnectionManager", "Exception in init: Datasource lookup Error.", "init()", exp, "");
}
}
Exception:
[INFO] [err] java.lang.NoClassDefFoundError: Could not initialize class com.ibm.websphere.naming.WsnInitialContextFactory
[INFO] [err] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[INFO] [err] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[INFO] [err] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[INFO] [err] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[INFO] [err] at com.ibm.ws.jndi.internal.WASInitialContextFactoryBuilder.createInitialContextFactory(WASInitialContextFactoryBuilder.java:57)
[INFO] [err] at [internal classes]
[INFO] [err] at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:730)
[INFO] [err] at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
[INFO] [err] at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
[INFO] [err] at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:184)

Liberty does not support the WsnInitialContextFactory class. You can just do this (and it'll work in WebSphere traditional as well):
try {
Context ctx = new InitialContext(new Hashtable());
try {
ds = (DataSource) ctx.lookup("java:comp/env/" + jndiName);
} catch (Exception ex) {
LogUtil.debugException("DBConnectionManager", "Exception in init: Resource reference DataSource lookup Error.", "init()", ex, "");
try {
ds = (DataSource) ctx.lookup("jdbc/" + jndiName);
} catch (Exception exp) {
LogUtil.debugException("DBConnectionManager", "Exception in init: Datasource lookup Error.", "init()", exp, "");
}
}

Related

#Controller Kafka Listener exception not catched by Exception handler #ControllerAdvice

I have a Kafka Listener marked with #Controller:
#KafkaListener(topics = "${binlookup.kafka.topic.insert}")
public BinInfoJsonDTO listenAndInsert(String binInfoJson, Acknowledgment ack) {
log.debug("Kafka server: {}", bootstrapServers);
log.info("Kafka inserting: {}", binInfoJson);
ObjectMapper mapper = new ObjectMapper();
BinInfoJsonDTO dto;
BinLookupError error;
String responseError;
try {
dto = mapper.readValue(binInfoJson, BinInfoJsonDTO.class); // <--- exception happens here
log.debug("The converted DTO: {}", dto);
ResponseEntity<BinInfoJsonDTO> response = controller.insertBIN(Utilities.jsonDtoToEntity(dto));
log.debug("BIN inserted by Kafka. {}", response);
if (response.getStatusCodeValue() == HttpStatus.OK.value() ||
response.getStatusCodeValue() == HttpStatus.CREATED.value()) {
ack.acknowledge(); // manual acknowledge.
log.debug("Acknowledged.");
} else {
responseError = "Unexpected response status code: " + response.getStatusCodeValue();
log.error(responseError);
error = new BinLookupError(responseError);
error.setErrorType(ErrorTypeEnum.UNEXPECTED_STATUS_CODE);
throw new BinLookupException(error);
}
} catch (JsonProcessingException e) {
log.error("Cannot parse Kafka incoming JSON. ", e);
error = new BinLookupError(e.getMessage());
error.setErrorType(ErrorTypeEnum.KAFKA_JSON_FAILURE);
throw new BinLookupException(error);
} catch (IOException e1) {
log.error("I/O exception in Kafka. ", e1);
error = new BinLookupError(e1.getMessage());
error.setErrorType(ErrorTypeEnum.IO_EXCEPTION);
throw new BinLookupException(error);
}
return dto;
}
And, I have an exception handler marked with #ControllerAdvice:
#Slf4j
#ControllerAdvice
public class BinLookupExceptionHandler extends ResponseEntityExceptionHandler {
#ExceptionHandler(value = {BinLookupException.class})
protected ResponseEntity<BinLookupError> handleBinLookupException(BinLookupException ex) {
BinLookupError error = ex.getError();
log.error("Exception handler: {}", error.getOriginalMsg());
...
}
Now, when I run the application and enter wrongly formatted JSON into the producer, the exception will occur but not catched by the exception handler. The exception is com.fasterxml.jackson.core.JsonParseException.
[NODE=Shenmue3] [ENV=dev] [SRC=UNDEFINED] [TRACE=] [SPAN=] [2018-09-13T09:38:21.035Z] [INFO] [MSG=[org.springframework.kafka.KafkaListenerEndpointContainer#1-0-C-1] c.p.binlookup.kafka.BinInfoConsumer - Kafka inserting: {{{{{ ]
[NODE=Shenmue3] [ENV=dev] [SRC=UNDEFINED] [TRACE=] [SPAN=] [2018-09-13T09:38:21.119Z] [ERROR] [MSG=[org.springframework.kafka.KafkaListenerEndpointContainer#1-0-C-1] c.p.binlookup.kafka.BinInfoConsumer - Cannot parse Kafka incoming JSON. com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (String)"{{{{{"; line: 1, column: 3]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:561)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddName(ReaderBasedJsonParser.java:1757)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:682)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2992)
at com.xxx.binlookup.kafka.BinInfoConsumer.listenAndInsert(BinInfoConsumer.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:248)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:80)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:51)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1071)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:1051)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:998)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:866)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:724)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
]
[NODE=Shenmue3] [ENV=dev] [SRC=UNDEFINED] [TRACE=] [SPAN=] [2018-09-13T09:38:21.122Z] [ERROR] [MSG=[org.springframework.kafka.KafkaListenerEndpointContainer#1-0-C-1] o.s.k.listener.LoggingErrorHandler - Error while processing: ConsumerRecord(topic = insert, partition = 0, offset = 0, CreateTime = 1536831499778, serialized key size = -1, serialized value size = 5, headers = RecordHeaders(headers = [], isReadOnly = false), key = null, value = {{{{{) org.springframework.kafka.listener.ListenerExecutionFailedException: Listener method 'public com.xxx.binlookup.dto.BinInfoJsonDTO com.xxx.binlookup.kafka.BinInfoConsumer.listenAndInsert(java.lang.String,org.springframework.kafka.support.Acknowledgment)' threw exception; nested exception is BinLookupException [error=BinLookupError(originalMsg=Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (String)"{{{{{"; line: 1, column: 3], fields=[], errorType=Cannot parse Kafka incoming JSON)]
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:267)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:80)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:51)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1071)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:1051)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:998)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:866)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:724)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.xxx.binlookup.exception.BinLookupException: Original message is: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (String)"{{{{{"; line: 1, column: 3]
at com.xxx.binlookup.kafka.BinInfoConsumer.listenAndInsert(BinInfoConsumer.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:248)
... 10 common frames omitted
]
"Exception handler: {}", as part of the log in the handler, is not there.
What more should I do to make it aware of my exception thrown? Thanks.

com.mysql.jdbc.Driver not resolved in ApiFest

Here is what my pom.xml looks like :
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
Code where i am trying to get jdbc connection :
public static Connection getConnection() {
String url = "jdbc:mysql://localhost:3306/";
String dbName = "dbname” ";
String userName = "userName";
String password = "password";
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url + dbName, userName, password);
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
} catch (Exception e) {
System.out.println("Inside exception");
e.printStackTrace();
}
System.out.println("Returning connection >>> " + connection);
return connection;
}
I am running ApiFest server using command :
java -Dproperties.file=apifest-oauth.properties -Dlog4j.configuration=file:log4j.xml -jar target/apifest-oauth20-0.2.0-SNAPSHOT-jar-with-dependencies.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:789)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
Also tried downloading com.mysql.jdbc_5.1.5.jar and added it to class path but no help.

Custom Liquibase Change error when integrating with Spring: Unknown Liquibase extension. Are you missing a jar from your classpath?

As part of the database upgrade for an existing application, a custom Liquibase change which extends AbstractChange has been created:
#DatabaseChange(name = "springBeanChange", description = "Runs a spring bean custom change", priority = ChangeMetaData.PRIORITY_DEFAULT)
public class SpringBeanChange extends AbstractChange {
private String beanName;
private String changeClass;
#DatabaseChangeProperty(description = "Spring bean name (optional)")
public String getBeanName() {
return this.beanName;
}
public void setBeanName(final String beanName) {
this.beanName = beanName;
}
#DatabaseChangeProperty(description = "Spring bean class")
public String getChangeClass() {
return this.changeClass;
}
public void setChangeClass(final String changeClass) {
this.changeClass = changeClass;
}
private CustomTaskChange bean;
#Override
public boolean generateStatementsVolatile(final Database database) {
return true;
}
#Override
public String getConfirmationMessage() {
return findBean().getConfirmationMessage();
}
#Override
public SqlStatement[] generateStatements(final Database database) {
try {
findBean().execute(database);
} catch (CustomChangeException e) {
throw new UnexpectedLiquibaseException(e);
}
return new SqlStatement[0];
}
#SuppressWarnings("unchecked")
private CustomTaskChange findBean() {
Class<CustomTaskChange> requiredType = CustomTaskChange.class;
if (this.changeClass != null) {
try {
Class<?> requestedType = Class.forName(this.changeClass);
if (CustomTaskChange.class.isAssignableFrom(requestedType)) {
requiredType = (Class<CustomTaskChange>) requestedType;
} else {
throw new UnexpectedLiquibaseException(
"Specified changeClass " + this.changeClass
+ " was not an instance of "
+ CustomTaskChange.class);
}
} catch (ClassNotFoundException e) {
throw new UnexpectedLiquibaseException(
"Could not create change class", e);
}
}
if (this.bean == null) {
if (getBeanName() == null) {
this.bean = SpringContextHolder.getInstance().getContext()
.getBean(requiredType);
} else {
this.bean = SpringContextHolder.getInstance().getContext()
.getBean(getBeanName(), requiredType);
}
}
return this.bean;
}
#Override
public ValidationErrors validate(final Database database) {
try {
return findBean().validate(database);
} catch (NullPointerException p_exception) {
return new ValidationErrors()
.addError("Exception thrown calling validate():"
+ p_exception.getMessage());
} catch (UnexpectedLiquibaseException p_exception) {
return new ValidationErrors()
.addError("Exception thrown calling validate():"
+ p_exception.getMessage());
} catch (NoSuchBeanDefinitionException p_exception) {
return new ValidationErrors()
.addError("Exception thrown calling validate():"
+ p_exception.getMessage());
} catch (BeanNotOfRequiredTypeException p_exception) {
return new ValidationErrors()
.addError("Exception thrown calling validate():"
+ p_exception.getMessage());
} catch (BeansException p_exception) {
return new ValidationErrors()
.addError("Exception thrown calling validate():"
+ p_exception.getMessage());
}
}
}
This is then configured in the database change log XML file as follows:
<changeSet id="15" author="theauthor">
<XXX:springBeanChange
changeClass="XXX.XXX.XXX.upgrade.tasks.TaskUpgrade" />
</changeSet>
Where TaskUpgrade implements CustomTaskChange and is the class that is returned get the call to getBean in SpringBeanChange.
The database change log file also contains many 'normal' liquibase commands such as addColumn.
A custom Java class has then been written which actually performs the upgrade (the following lines show the important lines of code which actually do the upgrade). This Java program is manually executed after the application has been deployed onto the server:
Liquibase liquibase =
new Liquibase(getChangeLogFile(), new ClassLoaderResourceAccessor(), new JdbcConnection(conn));
if ("update".equalsIgnoreCase(command)) {
liquibase.update(contexts);
} else {
throw new IllegalArgumentException("Unknown command " + command);
}
This works fine and executes the database upgrade.
I'm looking to avoid the need to use the custom Java program to perform the upgrade and actually do it when the application starts up. The app already uses Spring so it makes sense to to the upgrade when the Spring context is initialising.
To do this, I've added the following to the applicationContext file:
<bean id="myLiquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="dataSource" />
<property name="changeLog" value="classpath:databaseChangeLog.xml" />
<property name="contexts" value="test, production" />
</bean>
However, when the application starts up, I get the following exception:
2014-03-25 13:02:16,097 [main] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myLiquibase' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Invalid Migration File: Unknown Liquibase extension: springBeanChange. Are you missing a jar from your classpath?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at XXX.XXX.XXX.demo.YYYDemo.main(YYYDemo.java:47)
Caused by: liquibase.exception.ChangeLogParseException: Invalid Migration File: Unknown Liquibase extension: springBeanChange. Are you missing a jar from your classpath?
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:133)
at liquibase.Liquibase.update(Liquibase.java:129)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:291)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:258)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 22 more
Caused by: org.xml.sax.SAXException: Unknown Liquibase extension: springBeanChange. Are you missing a jar from your classpath?
at liquibase.parser.core.xml.XMLChangeLogSAXHandler.startElement(XMLChangeLogSAXHandler.java:495)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:99)
... 27 more
Caused by: org.xml.sax.SAXException: Unknown Liquibase extension: springBeanChange. Are you missing a jar from your classpath?
at liquibase.parser.core.xml.XMLChangeLogSAXHandler.startElement(XMLChangeLogSAXHandler.java:359)
... 39 more
I can't find anything on the Liquibase site or anywhere else which provides any help as to what JAR I'm missing (if indeed I am missing one) or if anything else is missing/not defined.
Does anyone have any ideas?
Thanks in advance.
The jar that contains the custom extension is what is missing from your classpath. I don't use Spring, so I don't know how it sets up the classpath, but you probably need to either put the jar in a standard location so Spring can find it or else configure the Spring classpath.

Migrate AbstractLobType to Hibernate 4 and Spring 3.2

I am currently using Hibernate 3 and Spring 3.0. I want to migrate to Hibernate 4 and Spring 3.2. I am using a subclass of AbstractLobType to implement a UserType that maps from an InputStream to the database (MySQL LONGBLOB):
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.orm.hibernate3.support.AbstractLobType;
public class BlobUserType extends AbstractLobType {
public int[] sqlTypes() {
return new int[] { Types.BLOB };
}
public Class returnedClass() {
return InputStream.class;
}
#Override
protected Object nullSafeGetInternal(ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
throws SQLException, HibernateException {
return lobHandler.getBlobAsBinaryStream(rs, names[0]);
}
#Override
protected void nullSafeSetInternal(PreparedStatement ps, int index, Object value, LobCreator lobCreator)
throws SQLException, HibernateException {
if (value != null) {
lobCreator.setBlobAsBinaryStream(ps, index, (InputStream) value, -1);
} else {
lobCreator.setBlobAsBytes(ps, index, null);
}
}
}
Since AbstractLobType is in the hibernate3, I should not use it anymore, but what is the alternative?
I did read this JIRA issue on the spring project, but it does not help me at all.
This is the hibernate mapping:
<class name="SoundNotification" table="SoundNotification" entity-name="SoundNotificationWithData">
<id name="m_id" type="int" column="id" unsaved-value="-1">
<generator class="native"/>
</id>
<property name="m_name" column="name" unique="true" not-null="true"/>
<property name="m_data" column="data"
type="com.mycompany.server.common.service.persistence.impl.hibernate.usertype.BlobUserType"
not-null="true"/>
<property name="m_size" formula="OCTET_LENGTH(data)"/>
<property name="m_inUse"
formula="(select count(1) from EventTypeConfiguration etc where etc.soundNotification=id)"/>
</class>
And the Java class:
public class SoundNotification extends IntegerEntity
{
private String m_name;
private transient InputStream m_data;
private boolean m_inUse;
private long m_size;
// getters and setters ...
}
UPDATE with MaterializedBlobType:
My TrafficMap.hbm.xml:
<class name="TrafficMapImage" table="TrafficMapImage" entity-name="TrafficMapImageWithData">
<id name="m_id" column="id" type="int" unsaved-value="-1">
<generator class="native"/>
</id>
<property name="m_created" column="created" type="org.jadira.usertype.dateandtime.joda.PersistentDateTime"
not-null="true"/>
<property name="m_image" column="image"
type="org.hibernate.type.MaterializedBlobType"
not-null="true"/>
<property name="m_type" column="type" not-null="true">
<type name="com.traficon.tmsng.server.common.service.persistence.impl.hibernate.usertype.EnumUserType">
<param name="enumClass">com.traficon.domain.map.TrafficMapImageType</param>
</type>
</property>
</class>
The sessionFactory bean in my Spring context:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
hibernate.show_sql=${hibernate.show_sql}
hibernate.jdbc.batch_size=50
hibernate.jdbc.use_streams_for_binary=true
hibernate.current_session_context_class=com.traficon.tmsng.server.common.spring.TransactionAwareSessionContext
</value>
</property>
<property name="mappingResources">
<list>
<value>hibernate/authentication.hbm.xml</value>
<value>hibernate/SystemPrefs.hbm.xml</value>
<value>hibernate/Detector.hbm.xml</value>
<value>hibernate/filters.hbm.xml</value>
<value>hibernate/EventTypeConfiguration.hbm.xml</value>
<value>hibernate/Scenario.hbm.xml</value>
<value>hibernate/RunningScenario.hbm.xml</value>
<value>hibernate/StorePoint.hbm.xml</value>
<value>hibernate/OfflineNetwork.hbm.xml</value>
<value>hibernate/Characteristics.hbm.xml</value>
<value>hibernate/EventType.hbm.xml</value>
<value>hibernate/EventStore.hbm.xml</value>
<value>hibernate/IntervalDataMessage.hbm.xml</value>
<value>hibernate/IntegrationPeriodConstraints.hbm.xml</value>
<value>hibernate/Media.hbm.xml</value>
<value>hibernate/TrafficMap.hbm.xml</value>
<value>hibernate/CommentLibrary.hbm.xml</value>
<value>hibernate/CommentHistory.hbm.xml</value>
<value>hibernate/Dashboard.hbm.xml</value>
</list>
</property>
<property name="entityInterceptor">
<bean class="com.traficon.tmsng.server.common.service.persistence.impl.hibernate.RollbackReintializerInterceptor"
scope="prototype"/>
</property>
</bean>
The logging output:
[WARNING] [talledLocalContainer] INFO: Initializing Spring root WebApplicationContext
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:10,525 [main] INFO hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:10,537 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {4.2.7.Final}
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:10,544 [main] INFO org.hibernate.cfg.Environment - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.jdbc.use_streams_for_binary=true, hibernate.bytecode.use_reflection_optimizer=false}
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:10,545 [main] INFO org.hibernate.cfg.Environment - HHH000407: Using java.io streams to persist binary types
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:10,546 [main] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
[INFO] [talledLocalContainer] 13 Dec 2013 13:54:12,302 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
....
[INFO] [talledLocalContainer] 13 Dec 2013 14:06:12,136 [http-8080-4] INFO hibernate.event.internal.DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.PropertyAccessException: could not set a field value by reflection setter of com.traficon.domain.map.TrafficMapImage.m_image
[WARNING] [talledLocalContainer] Dec 13, 2013 2:06:12 PM org.apache.catalina.core.StandardWrapperValve invoke
[WARNING] [talledLocalContainer] SEVERE: Servlet.service() for servlet mediaServlet threw exception
[WARNING] [talledLocalContainer] java.lang.IllegalArgumentException: Can not set java.io.InputStream field com.traficon.domain.map.TrafficMapImage.m_image to [B
[WARNING] [talledLocalContainer] at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
[WARNING] [talledLocalContainer] at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
[WARNING] [talledLocalContainer] at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
[WARNING] [talledLocalContainer] at java.lang.reflect.Field.set(Field.java:741)
[WARNING] [talledLocalContainer] at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:139)
[WARNING] [talledLocalContainer] at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:710)
[WARNING] [talledLocalContainer] at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:379)
[WARNING] [talledLocalContainer] at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4523)
[WARNING] [talledLocalContainer] at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:186)
[WARNING] [talledLocalContainer] at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1108)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.processResultSet(Loader.java:964)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.doQuery(Loader.java:911)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:312)
[WARNING] [talledLocalContainer] at org.hibernate.loader.Loader.loadEntity(Loader.java:2121)
[WARNING] [talledLocalContainer] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
[WARNING] [talledLocalContainer] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
[WARNING] [talledLocalContainer] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3941)
[WARNING] [talledLocalContainer] at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:460)
[WARNING] [talledLocalContainer] at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:429)
[WARNING] [talledLocalContainer] at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206)
[WARNING] [talledLocalContainer] at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:246)
[WARNING] [talledLocalContainer] at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
[WARNING] [talledLocalContainer] at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1098)
[WARNING] [talledLocalContainer] at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:175)
[WARNING] [talledLocalContainer] at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2482)
[WARNING] [talledLocalContainer] at org.hibernate.internal.SessionImpl.get(SessionImpl.java:998)
[WARNING] [talledLocalContainer] at com.traficon.tmsng.server.common.service.persistence.impl.hibernate.HibernateTrafficMapRepository.getTrafficMapImageWithData_aroundBody6(HibernateTrafficMapRepository.java:176)
[WARNING] [talledLocalContainer] at com.traficon.tmsng.server.common.service.persistence.impl.hibernate.HibernateTrafficMapRepository$AjcClosure7.run(HibernateTrafficMapRepository.java:1)
[WARNING] [talledLocalContainer] at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96cproceed(AbstractTransactionAspect.aj:59)
[WARNING] [talledLocalContainer] at org.springframework.transaction.aspectj.AbstractTransactionAspect$AbstractTransactionAspect$1.proceedWithInvocation(AbstractTransactionAspect.aj:65)
[WARNING] [talledLocalContainer] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
[WARNING] [talledLocalContainer] at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
[WARNING] [talledLocalContainer] at com.traficon.tmsng.server.common.service.persistence.impl.hibernate.HibernateTrafficMapRepository.getTrafficMapImageWithData(HibernateTrafficMapRepository.java:173)
[WARNING] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[WARNING] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[WARNING] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[WARNING] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:606)
[WARNING] [talledLocalContainer] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
[WARNING] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
[WARNING] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
[WARNING] [talledLocalContainer] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
[WARNING] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
[WARNING] [talledLocalContainer] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
[WARNING] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
[WARNING] [talledLocalContainer] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
[WARNING] [talledLocalContainer] at com.sun.proxy.$Proxy39.getTrafficMapImageWithData(Unknown Source)
[WARNING] [talledLocalContainer] at com.traficon.tmsng.server.web.mvc.DownloadTrafficMapImageController.onSubmit(DownloadTrafficMapImageController.java:40)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:272)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
[WARNING] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
[WARNING] [talledLocalContainer] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
[WARNING] [talledLocalContainer] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
[WARNING] [talledLocalContainer] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[WARNING] [talledLocalContainer] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
[WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[WARNING] [talledLocalContainer] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
[WARNING] [talledLocalContainer] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
[WARNING] [talledLocalContainer] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
[WARNING] [talledLocalContainer] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
[WARNING] [talledLocalContainer] at java.lang.Thread.run(Thread.java:744)
[WARNING] [talledLocalContainer]
In theory you should use the hibernate provided MaterializedBlobType if you want to use InputStreams for your Blob then add the following property to you hibernate configuration
hibernate.jdbc.use_streams_for_binary=true
This will instruct the MaterializedBlobType to use an InputStream instead of a byte[].
I ended up creating my own UserType that converts between Blob and InputStream:
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.usertype.UserType;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
public class BlobUserType implements UserType
{
// ------------------------ INTERFACE METHODS ------------------------
// --------------------- Interface UserType ---------------------
#Override
public int[] sqlTypes()
{
return new int[]{Types.BLOB};
}
#Override
public Class returnedClass()
{
return InputStream.class;
}
#Override
public boolean equals( Object x, Object y ) throws HibernateException
{
boolean result;
if (x == y)
{
result = true;
}
else if (x == null || y == null)
{
result = false;
}
else
{
result = x.equals( y );
}
return result;
}
#Override
public int hashCode( Object x ) throws HibernateException
{
return x.hashCode();
}
#Override
public Object nullSafeGet( ResultSet rs, String[] names, SessionImplementor session, Object owner ) throws HibernateException, SQLException
{
return rs.getBlob( names[0] ).getBinaryStream();
}
#Override
public void nullSafeSet( PreparedStatement st, Object value, int index, SessionImplementor session ) throws HibernateException, SQLException
{
if( value != null )
{
InputStream inputStream = (InputStream)value;
st.setBlob( index, inputStream );
}
else
{
st.setNull( index, Types.BLOB );
}
}
#Override
public Object deepCopy( Object value ) throws HibernateException
{
return value;
}
#Override
public boolean isMutable()
{
return false;
}
#Override
public Serializable disassemble( Object value ) throws HibernateException
{
return null;
}
#Override
public Object assemble( Serializable cached, Object owner ) throws HibernateException
{
return null;
}
#Override
public Object replace( Object original, Object target, Object owner ) throws HibernateException
{
return original;
}
}
Seems to be working fine loading and saving my entity from/to the database.
You should not use AbstractLobType because it is in the hibernate 3 as you said.
You can create your own UserType to convert between Blob and InputStream. However, if you are migrating existing data from Hibernate 3 to 4, your code will not work:
The format of BlobSerializableType has header's information in addition which is something like this:
’ t{"userServices":[{"accountStatus":"PendingTermsAndConditions","serviceIdentifier":"SNG"}]...}]}
Your code will working (reading, writing) to the format without header:
{"userServices":[{"accountStatus":"PendingTermsAndConditions","serviceIdentifier":"SNG"}]...}]}
My personal solution is to simulate the Hibernate 3 to write and read Blob data as below:
package com.newbay.acs.domain.hibernate;
import org.apache.commons.io.IOUtils;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.usertype.UserType;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
/**
* Created by qale0001 on 21/06/2016.
*/
public class CustomMaterializedBlobType implements UserType
{
private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZE = 1024;
#Override
public int[] sqlTypes()
{
return new int[]{Types.BLOB};
}
#Override
public Class returnedClass()
{
return String.class;
}
#Override
public boolean equals(Object x, Object y) throws HibernateException {
boolean result;
if (x == y)
{
result = true;
}
else if (x == null || y == null)
{
result = false;
}
else
{
result = x.equals( y );
}
return result;
}
#Override
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
#Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
java.sql.Blob blob = rs.getBlob( names[0] );
InputStream is = blob.getBinaryStream();
if (is != null) {
try {
ObjectInputStream ois = new ObjectInputStream(is);
try {
return ois.readObject();
} catch (ClassNotFoundException ex) {
throw new HibernateException("Could not deserialize BLOB contents", ex);
} finally {
ois.close();
}
} catch (IOException ex) {
throw new HibernateException("Could not deserialize BLOB contents", ex);
}
}
else {
return null;
}
}
#Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if( value != null )
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE);
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
try {
oos.writeObject(value);
oos.flush();
InputStream is = new ByteArrayInputStream(baos.toByteArray());
st.setBlob(index, is);
}
finally {
oos.close();
}
} catch (IOException ex) {
throw new HibernateException("Could not serialize BLOB contents", ex);
}
}
else
{
st.setNull( index, Types.BLOB );
}
}
#Override
public Object deepCopy(Object value) throws HibernateException {
return value;
}
#Override
public boolean isMutable() {
return false;
}
#Override
public Serializable disassemble(Object value) throws HibernateException {
return null;
}
#Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return null;
}
#Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
}
}

Unknown SMTP host: smtp.outlook.com

I made an application which requires to send emails. It worked before, but when I wanted to run it today, it threw an java.net.UnknownHostException: smtp.outlook.com. It used to work friday, did something change in the outlook configuration?
This is my code:
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smpt.host", "smtp.outlook.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props, null);
try {
transport = session.getTransport("smtp");
try {
transport.connect("smtp.outlook.com", username, wachtwoord);
} catch (MessagingException ex) {
ex.printStackTrace();
}
} catch (NoSuchProviderException ex) {
ex.printStackTrace();
}
It throws the following error:
javax.mail.MessagingException: Unknown SMTP host: smtp.outlook.com;
nested exception is:
java.net.UnknownHostException: smtp.outlook.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1932)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at retourberichten.VerstuurEmail.SendEmail.VerstuurTest(SendEmail.java:143)
at retourberichten.StartApplicatie.App.main(App.java:46)
Caused by: java.net.UnknownHostException: smtp.outlook.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
... 5 more
java.lang.IllegalStateException: Not connected
Any help is really appreciated,
Thanks!
The SMTP server should be smtp.live.com rather than smtp.outlook.com
http://www.groovypost.com/howto/outlook.com-settings-pop3-smtp-imap/

Resources