Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

17 November 2016

Java dynamic proxy adding interface implementation (introducing an interface) to an object with Spring

I'm not an AOP expert and not knowing the terminology took me a while before I find the solution to the topic. The keyword appeared to be the introduction.
While knowing the keyword makes task way easier I will still share the recipe.

What we need to do

To wrap an object instance with a AOP proxy adding an interface implementation to it.

Code example is available here http://www.java2s.com/Code/Java/Spring/SpringAspectIntroductionExample.htm

10 February 2014

MalformedUrlException o_O

...
Caused by:
java.net.MalformedURLException
        at java.net.URL.(URL.java:601)
        at java.net.URL.(URL.java:464)
        at java.net.URL.(URL.java:413)
        at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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 org.apache.xalan.templates.StylesheetRootProxy.(Unknown Source)
OR
...
java.net.MalformedURLException
 at java.net.URL.(URL.java:601)
 at java.net.URL.(URL.java:464)
 at java.net.URL.(URL.java:413)
 at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:649)
 at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
 at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)


...may just mean that you pushed a null InputSteam into parser.

For example this piece of code would produce such exception trace:

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(new InputSource((InputStream) null), new DefaultHandler());

It also may be done in less explicit way, for example with an XSLT parser being given XSLT source with null InputSteam inside (which actually was the issue I originally faced).

24 September 2012

Using multiple input documents for XSLT transformation

I believe I'm not alone when I need to use couple of input documents for a XSLT transformation. It's rather common case to have input data from multiple sources, to process it and to return a single result. Should XSLT be an exception? Not this time.
If we look at data type mapping it obvious that we could accept and return Nodes, NodeLists, etc. We could do the same with transformer parameters as well. Here is an example:

Document doc = ...; // direct input for transformer
Document anotherDoc = ...; // second document to be passed as parameter

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsl);
transformer.setParameter("anotherDoc", anotherDoc);
transformer.transform(new DOMSource(doc), new StreamResult(System.out));

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="xsl">

  <xsl:param name="anotherDoc" />

  <xsl:variable name="inputDoc" select="/" />

  <xsl:template match="/">
    <xsl:apply-templates select="$anotherDoc/anotherRoot" />
  </xsl:template>


  <xsl:template match="nodeOfAnotherDoc">
    <xsl:value-of select="text()" />
    <xsl:value-of select="$inputDoc/root/@attr" />
  </xsl:template>

</xsl:stylesheet>

That's all the trick, we could operate of another document just on regular xsl:variable containing a node-set.
Just one hint: it may be useful to have a variable referencing input document root (inputDoc in example), because inside context of xsl:template that matched anotherDoc you may have trouble accessing nodes of input document.

07 June 2012

DSRA0080E Data Store Adapter exception on IBM WebSphere EJB client

More like a hint for myself :)


Exception like this:

...
Caused by: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: com/ibm/websphere/rsadapter/DataStoreHelper.doConnectionSetupPerGetConnection(Ljava/sql/Connection;ZLjava/lang/Object;)Z.
  at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.getConnection(WSRdbManagedConnectionImpl.java:3503)
  at com.ibm.ws.rsadapter.spi.WSDefaultConnectionManagerImpl.allocateConnection(WSDefaultConnectionManagerImpl.java:91)
  at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:646)
  ... 22 more
Caused by: java.lang.AbstractMethodError: com/ibm/websphere/rsadapter/DataStoreHelper.doConnectionSetupPerGetConnection(Ljava/sql/Connection;ZLjava/lang/Object;)Z
  at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.getConnection(WSRdbManagedConnectionImpl.java:3482)
  ... 24 more

may be caused by running EJB client application with different (e.g. non-IBM) Java VM.

02 April 2012

Meaningful error message from IBM WebSphere

Seeing this on your WebSphere application server startup?
00000000 ContainerHelp E   WSVR0501E: Error creating component com.ibm.ws.cluster.runtime.ProcessRuntimeImpl
java.lang.NoClassDefFoundError: com.ibm.websphere.cluster.topography.DescriptionManagerFactory (initialization failure)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
        at com.ibm.ws.cluster.runtime.ProcessRuntimeImpl.initialize(ProcessRuntimeImpl.java:366)
        at com.ibm.ws.runtime.component.ContainerHelper.initWsComponent(ContainerHelper.java:1166)
        at com.ibm.ws.runtime.component.ContainerHelper.initializeComponent(ContainerHelper.java:1073)
        at com.ibm.ws.runtime.component.ContainerHelper.initializeComponents(ContainerHelper.java:874)
        at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:780)
        at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:754)
        at com.ibm.ws.runtime.component.ServerImpl.initialize(ServerImpl.java:350)
        at com.ibm.ws.runtime.WsServerImpl.bootServerContainer(WsServerImpl.java:280)
        at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:214)
        at com.ibm.ws.runtime.WsServerImpl.main(WsServerImpl.java:666)
        at com.ibm.ws.runtime.WsServer.main(WsServer.java:59)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:599)
        at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:213)
        at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:93)
        at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:74)
        at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:599)
        at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
        at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
        at org.eclipse.core.launcher.Main.run(Main.java:981)
        at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:330)
        at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:108)
Caused by: java.lang.IllegalStateException: java.lang.NullPointerException
        at com.ibm.ws.util.ImplFactory.loadImplFromClass(ImplFactory.java:354)
        at com.ibm.ws.util.ImplFactory.loadImplFromKey(ImplFactory.java:328)
        at com.ibm.ws.util.ImplFactory.loadImplFromKey(ImplFactory.java:332)
        at com.ibm.ws.wlm.Factory$4.run(Factory.java:141)
        at java.security.AccessController.doPrivileged(AccessController.java:251)
        at com.ibm.ws.wlm.Factory.loadImpl(Factory.java:139)
        at com.ibm.websphere.cluster.topography.DescriptionManagerFactory.(DescriptionManagerFactory.java:50)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
        at com.ibm.ws.cluster.service.ClusterManagementImpl.(ClusterManagementImpl.java:119)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:45)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:515)
        at com.ibm.wsspi.cluster.ClusterManagementFactory.(ClusterManagementFactory.java:62)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
        at com.ibm.ws.cluster.runtime.WLMDiagnosticModule.ffdcDumpDefaultClusterManagement(WLMDiagnosticModule.java:422)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:599)
        at com.ibm.ws.ffdc.DiagnosticModule.getDataForDirective(DiagnosticModule.java:305)
        at com.ibm.ws.ffdc.DiagnosticModule.getDataForDirectives(DiagnosticModule.java:279)
        at com.ibm.ws.ffdc.DiagnosticModule.dumpComponentData(DiagnosticModule.java:144)
        at com.ibm.ws.ffdc.impl.DMAdapter.processDM(DMAdapter.java:123)
        at com.ibm.ws.ffdc.impl.DMAdapter.formatTo(DMAdapter.java:114)
        at com.ibm.ffdc.util.provider.IncidentLogger.writeIncidentTo(IncidentLogger.java:63)
        at com.ibm.ws.ffdc.impl.FfdcProvider.logIncident(FfdcProvider.java:135)
        at com.ibm.ws.ffdc.impl.FfdcProvider.logIncident(FfdcProvider.java:92)
        at com.ibm.ffdc.util.provider.FfdcProvider.log(FfdcProvider.java:232)
        at com.ibm.ws.ffdc.impl.FfdcProvider.log(FfdcProvider.java:100)
        at com.ibm.ffdc.util.provider.IncidentEntry.log(IncidentEntry.java:96)
        at com.ibm.ffdc.util.provider.Ffdc.log(Ffdc.java:90)
        at com.ibm.ws.ffdc.FFDCFilter.processException(FFDCFilter.java:114)
        at com.ibm.ws.cluster.ProcessProperties.(ProcessProperties.java:281)
        at com.ibm.ws.cluster.ProcessProperties.(ProcessProperties.java:234)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
        at com.ibm.ws.cluster.runtime.ProcessRuntimeImpl.initialize(ProcessRuntimeImpl.java:307)
        ... 31 more
Caused by: java.lang.NullPointerException
        at com.ibm.ws.cluster.WLMCustomPropertyUtility.getBBCallbacksEnableWLMThreads(WLMCustomPropertyUtility.java:384)
        at com.ibm.ws.cluster.propagation.bulletinboard.BBDescriptionManager.(BBDescriptionManager.java:165)
        at java.lang.J9VMInternals.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1325)
        at com.ibm.ws.util.ImplFactory.loadImplFromClass(ImplFactory.java:349)
        ... 70 more

This should probably mean that your PC's hostname couldn't be resolved.

17 September 2010

Partial fix for tomcat hot redeploy

Adding the following to CATALINA_OPTS makes tomcat survive across much more redeploy iterations then by default :)
-Xmx1024m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m