REST Annotated classes not part of org.superbiz package are not being deployed by TomEE Plume 7.0.4 - apache-tomee

On TomEE Plume 7.0.3/4 when I change my REST annotated classes package from org.superbiz then they are no more deployed when I deploy the war file.
Sample class is given below
package com.abc.rest.application;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
#ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class));
}
}
Now ApplicationConfig class is never read by the TomEE Plume. What configuration I need to make so that TomEE recognize my rest application config class and other jax-rs, ejb and jpa annotated classes.

In system.properties set openejb.classloader.forced-load=com.abc
then only my application packages would be loaded. Tricky to understand.

Related

Androidx ServiceTestRule cannot find my service

To be fair, I am not testing the service, but am using a service as part of my test classes to test a Bluetooth library. So my test class needs to create a service that invokes the Bluetooth library. The test class then needs to bind to this service to perform the tests. However, attempting to start the service always gives me the following error which leads to a Nullpointer exception
W/ActivityManager: Unable to start service Intent { cmp=com.example.androidhdpadapter.test/com.lampreynetworks.ahd.oxp.transport.BluetoothTestService } U=0: not found
At this stage, the test class is very simple:
package com.lampreynetworks.ahd.oxp.transport;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.fail;
#RunWith(AndroidJUnit4.class)
public class AndroidServiceBluetoothAdapterTests
{
private final static String TAG =
AndroidServiceBluetoothAdapterTests.class.getName();
#Rule
public final ServiceTestRule serviceRule = new ServiceTestRule();
#Test
public void testAndroidBluetoothAdapter() throws TimeoutException, InterruptedException
{
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
Intent intent = new Intent(context, BluetoothTestService.class);
serviceRule.startService(intent);
Thread.sleep(12000);
IBinder binder = serviceRule.bindService(intent);
BluetoothTestService service = ((BluetoothTestService.TestManagerBinder) binder).getService();
serviceRule.unbindService();
}
}
There are NUMEROUS posts regarding problems with testing services and I have tried all of them (messing with gradle.build file dependencies, conflicts between androidx.test and android.support.test, etc.). I have also tried invoking the service in the standard manner without ServiceTestRule, but that likely failed because there is no AndroidManifest for the test that specifies the service (I don't know if that can be done).
Maybe it is not possible to use Androidx's ServiceTestRule unless one is actually testing a service that is part of an application. Here I am testing a Bluetooth Library that is typically invoked by a service, and this test service is NOT part of the library, but exists only in the androidTests directory.
The reason I am doing this is that Android has buggy Bluetooth and on some platforms, the Bluetooth spontaneously shuts down and then restarts. My Bluetooth Library tries to recover from this shutdown. The recovery works BUT for every spontaneous shutdown and recovery, I get a service leak. That is what I am trying to solve in a simplified framework instead of a full-fledged application.

Having problems launching my glassfish server

I followed a starting guide for jax-rs web service development with intellij,glassfish. After i done the tutorial i tried to launch it as shown in tutorial, but server launched and atemmpted to start domain for a while and the website did not load. So I stopped the server and got error message at the bottom on the screen: http://prntscr.com/nsrmeb. Moreover here is how i start my application.
Tried restarting it couple times also searching in web for similar problems, but failed to find anything.
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
#ApplicationPath("/")
public class MyApplication extends Application{
#Override
public Set<Class<?>> getClasses(){
HashSet h = new HashSet<Class<?>>();
h.add(MatchResource.class);
return h;
}
}
This is how the tutorial I followed:
https://www.jetbrains.com/help/idea/creating-and-running-your-first-
restful-web-service.html

Cucumber.class error: cannot convert from class cucumber to calls runner

I'm getting an error in Cucumber.class saying
cannot convert from class cucumber to calls runner
Here's my code:
package testRunners;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="resources/features", glue="StepDefinition")
public class Login {
}
It happens when you have dependency mismatch in your project. More details can be seen after digging in pom.xml. Please share it.
For now you should be knowing that #Runwith takes something which extends ParentRunner Class, so make sure the Cucumber.class that you are using here is extending ParentRunner.

How to use selenium-server-standalone-2.0rc2 while creating script with RC

package com.html;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
public class Html5 extends TestCase{`enter code here`
Selenium selenium1;
public void setUp()
{
selenium1=new DefaultSelenium("localhost",4444,"*firefox","http://live.com");
selenium1.start();
}
}
Error appearing in com.thoughtworks.selenium.DefaultSelenium; and DefaultSelenium("localhost",4444,"*firefox","http://live.com"); line.
Please suggest.
First :
What the enter code here string does there ?
Secondly :
If there is an error in the import com.thoughtworks.selenium.DefaultSelenium; and in the new DefaultSelenium, it's certainly that the jars are not in your classpath
selenium-server-standalone contains the Selenium server classes, but not the client ones, where DefaultSelenium is. You'll have to bring the client jars in your classpath, that is selenium2-java for this version I think
I think you need to give Path to firefox.exe in your Constructor..So
selenium1 = new DefaultSelenium("localhost",4444,"*firefox","http://live.com"); Goes like
selenium1 = new DefaultSelenium("localhost",4444,"*firefox C:\Documents and Settings\Mozilla Firefox\firefox.exe","http://live.com");
Try this once.

Eclipse Juno EE NoClassDefFoundError when using external Jar

I added an external jar in my eclipse dynamic webproject via Folder -> properties -> build path -> Libraries -> add external jar.
The code is working fine on compile time.
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tika.Tika;
#WebServlet(name="UploadServlet", urlPatterns={"/uploadFile"}) // specify urlPattern for servlet
#MultipartConfig //Specify that this servlet will receive a multipart data
public class UploadServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
Tika tika = new Tika();
res.setContentType("text/html");
PrintWriter writer = res.getWriter();
writer.write(mediaType);
}
}
I added Apache Tika but when I run my application. these exception occured.
root cause
java.lang.NoClassDefFoundError: org/apache/tika/Tika
servlet.UploadServlet.doPost(UploadServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: org.apache.tika.Tika
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
servlet.UploadServlet.doPost(UploadServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
I am using Apache Tika to determine what file has been upload, I want to use it for validating if a file is an image, or audio file
You forgot to add that jar to the Deployment Assembly page. It's not deployed to the server when you run your application, hence the NoClassDefFoundErrors.