OSGI expose An "ClassNotFoundException: org.w3c.dom.***" Error when release - osgi

I only wrote the following codes in Activator.start() function
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Node node = new Node() {
#Override
public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
// TODO Auto-generated method stub
return null;
}
#Override
public void setTextContent(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setPrefix(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setNodeValue(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node removeChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public void normalize() {
// TODO Auto-generated method stub
System.out.println("normalize 方法调用");
}
#Override
public String lookupPrefix(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String lookupNamespaceURI(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean isSupported(String arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isSameNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isEqualNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isDefaultNamespace(String arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean hasChildNodes() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean hasAttributes() {
// TODO Auto-generated method stub
return false;
}
#Override
public Object getUserData(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getTextContent() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getPreviousSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getParentNode() {
// TODO Auto-generated method stub
return null;
}
#Override
public Document getOwnerDocument() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNodeValue() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public short getNodeType() {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getNodeName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getNextSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespaceURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getLastChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getFirstChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getFeature(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
#Override
public NodeList getChildNodes() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getBaseURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public NamedNodeMap getAttributes() {
// TODO Auto-generated method stub
return null;
}
#Override
public short compareDocumentPosition(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return 0;
}
#Override
public Node cloneNode(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public Node appendChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
};
node.normalize();
}
Everything goes well when run in eclipse environment, but, when release the product, ERRORS in log when runs:
Root exception:
java.lang.NoClassDefFoundError: org/w3c/dom/Node
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node
Anyone can give some help?

OSGi gives access to system packages but only java.* packages by default, this does not include other packages like: javax.net , javax.xml , com.sun
Thus it is necessary to specify any of such packages for OSGi framework to export them through the system bundle making them accessible to other bundles that import them.
To do that you need to set a configuration property with the additional packages required by your bundles, try setting it as a system property before starting the OSGi framework such that it picks up this property when it first starts.
Assuming you are on OSGi 4.2, that property would be configured like:
org.osgi.framework.system.packages.extra=org.w3c.dom
You may want to check the Apache Felix Framework Configuration Properties for more details, though this property is part of the OSGi spec and thus should be available in other implementations as well

Please update your question to include the bundle's MANIFEST.MF
It looks like org.w3c.dom is not implicitly provided in your production. Check the Import-Package header, may be you don't have Import-Package: org.w3c.dom

If you are using Equinox, you can edit the config.ini and add "org.w3c.dom" to org.osgi.framework.system.packages key and import the same packages in your MANIFEST.MF

in my case adding
org.osgi.framework.bootdelegation=xx...xxx,org.w3c.dom
solved my problem.

Related

Selenium - Allure does not create screenshots

I have a problem with connecting screenshots in the report generated by allure using jenkins.
1. I have an interface called ListenersT
package Test;
import Test.resources.Base;
import io.qameta.allure.Allure;
import io.qameta.allure.Attachment;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class ListenersT extends Base implements ITestListener {
Base b = new Base();
public void onFinish(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onStart(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
//screenshot
try {
b.getScreenshot(result.getName());
} catch (IOException e) {
e.printStackTrace();
}
Object testClass = result.getInstance();
WebDriver driver = ((Base) testClass).getDriver();
if(driver instanceof WebDriver) {
takeScreenshot(driver);
}
}
#Attachment
public byte[] takeScreenshot(WebDriver driver) {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}
public void onTestSkipped(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestStart(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestSuccess(ITestResult arg0) {
// TODO Auto-generated method stub
}
}
I have screenshot support attached here
In each test, the listener "#Listeners ({ListenersT.class})" has been added to the beginning.
#Listeners({ListenersT.class})
Still, I don't see screenshots in the generated report
Please help.

JxBrowser does not refresh

I am currently using JxBrowser as an embedded browser in my Java application. I create a browser like below:
public static void main(String[] args) {
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://developer.microsoft.com/en-us/graph");
frame.addWindowListener(new WindowListener() {
#Override
public void windowClosing(WindowEvent e) {
}
#Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowClosed(WindowEvent arg0) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.getCacheStorage().clearCache();
browser.loadURL("https://developer.microsoft.com/en-us/graph");
}
#Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
});
}
When the first URL is opened, I sign in and choose to not keep me signed in. I then close that window and when the second window opens, I see that my user is still logged in. As you can see I am clearing cache as well before opening the URL the second time. But the cache is not cleared.
I am not sure that the issue is related to caching. Would you please create a simple sample that can be used for reproducing the issue from my end?

How to terminate the connection between Observables and ovserver before all items are consumed

I would like to know how can I terminate the connection betwen the observables and the observer early before all the obsevabes are consumed.
I know that it can be done through disposable..but how can I have a reference to disposable object givenas the below posted example
thanks in advance
code:
Observable<List<List<Person>>> observables = Observable.just(Main.getPersons());
observables
.concatMap(ll->{
//how to display the size of List<List<Person>>
//System.out.println("ll: " + ll.size());
return Observable.fromIterable(ll)
.concatMap(l->Observable.fromIterable(l))
.filter(p->p.getAge().orElse(-1) <44)
.map(g->g.getName().map(s->s+"_test").get()+ " " + g.getAge().orElse(0));
}
)
//.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.blockingSubscribe(new Observer() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
System.out.println("onError: " + arg0);
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
}
});

How to Audit Spring data jpa #Query?

To Audit log all the DB changes , we have implemented Hibernate Interceptor(org.hibernate.Interceptor) .
We can able to log the audit for the query executed using JpaRepository
Interceptor We have used- Sample
import java.io.Serializable;
import java.util.Iterator;
import org.hibernate.CallbackException;
import org.hibernate.EntityMode;
import org.hibernate.Interceptor;
import org.hibernate.Transaction;
import org.hibernate.type.Type;
public class TestInterceptor implements Interceptor {
#Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void preFlush(Iterator entities) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void postFlush(Iterator entities) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public Boolean isTransient(Object entity) {
// TODO Auto-generated method stub
return null;
}
#Override
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) {
// TODO Auto-generated method stub
return null;
}
#Override
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public String getEntityName(Object object) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getEntity(String entityName, Serializable id) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public void afterTransactionBegin(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public void beforeTransactionCompletion(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public void afterTransactionCompletion(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public String onPrepareStatement(String sql) {
// TODO Auto-generated method stub
return null;
}
}
But if we run the query via org.springframework.data.jpa.repository.Query that interceptor is not getting called.
Is this possible to Audit/Intercept the Query Executed using org.springframework.data.jpa.repository.Query
i.e I have the following Query in my Repository, this is not triggering Hibernate Interceptor
#Transactional
#Modifying
#Query("DELETE from MyEntity my where my.id =?1")
void deleteById(Long id);
To intercept spring data queries add this prop:
spring.jpa.properties.hibernate.session_factory.interceptor=com.yourpacakge.TestInterceptor
I used an interceptor class that extends from EmptyInterceptor just for simplicity.
public class MyInterceptor extends EmptyInterceptor {
#Override
public String onPrepareStatement(String sql) {
System.out.println("Query intercepted: " + sql);
return super.onPrepareStatement(sql);
}
}
DOCS: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-session-events

OutOfMemoryError while using Universal Image Loader in gridview

I have around 53 images to show in gridview from drwable. But i was getting oom while doing that. So i started using universal image loader to cache these images on to disc and pull it from there..! But i am still getting oom.
Here is my configuration
imageLoader =ImageLoader.getInstance();
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"icons");
else
cacheDir=mContext.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
config= new ImageLoaderConfiguration.Builder(mContext)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.threadPoolSize(2)
.offOutOfMemoryHandling()
.discCache(new UnlimitedDiscCache(cacheDir))
.enableLogging()
.build();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
and this is my getview() of BaseAdapter
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null)
{
ViewHolder holder=new ViewHolder();
inflator = mContext.getLayoutInflater();
convertView = inflator.inflate(R.layout.imagelayout, null);
holder.imageView=(ImageView)convertView.findViewById(R.id.imgDet);
convertView.setTag(holder);
}
ViewHolder hold=(ViewHolder)convertView.getTag();
try
{
imageLoader.displayImage("drawable://" +mThumbIds[position], hold.imageView, options,new ImageLoadingListener() {
#Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
});
}catch(OutOfMemoryError oom)
{
oom.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return convertView;
}
please help me with this.
Always Consider the native way to load drawables first.
ImageView.setImageResource(...) instead of using of ImageLoader.

Resources