I am trying to write an OSGI class which should populate the configuration dialog in Felix console, my Service implementation as shown below. but when i try to run mvn clean install -PautoInstallPackage am getting the below error. any help is appreciated.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.2:compile
(default-compile) on project osgiexample.core: Compilation failure
[ERROR]
/E://osgiexample/core/src/main/java/osgiexample/core/serviceimpl/TestServiceImpl.java:[40,10]
cannot find symbol
[ERROR] symbol: class Activate
[ERROR] location:
class osgiexample.core.serviceimpl.TestServiceImpl
#Component(immediate=true, label="TEST Service", description="Hello There - This is a Service component", metatype=true)
#Service(value=TestService.class)
public class TestServiceImpl implements TestService {
#Property(value="http://testservice/myservice?wsdl")
static final String SERVICE_ENDPOINT_URL = "service.endpoint.url";
private String serviceEndpointUrl;
#Override
public String getData() {
// TODO Auto-generated method stub
return null;
}
#Activate
public void activate(final Map<String, Object> props) {
System.out.println("Calling Activate Method");
this.serviceEndpointUrl = (String)props.get(SERVICE_ENDPOINT_URL);
System.out.println("ServiceEndpointUrl:" + this.serviceEndpointUrl);
}
}
Add below Activate annotation import statement should resolve your issue
import org.apache.felix.scr.annotations.Activate;
Related
When running equalsverfier in quarkus dev mode, equalsverfier tests fail.
I tried to test a class with equalsverifier. This works in my IDE.
I tried to use it in quarkus dev mode (by running ./mvnw quarkus:dev), but then it fails with the following exception:
ERROR [io.qua.test] (Test runner thread) Test DingetjeTest#implementsEquals() failed
: java.lang.AssertionError: EqualsVerifier found a problem in class a.Dingetje.
-> Can not set final java.lang.String field a.Dingetje.text to a.Dingetje
For more information, go to: http://www.jqno.nl/equalsverifier/errormessages
at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verify(SingleTypeEqualsVerifierApi.java:308)
at a.DingetjeTest.implementsEquals(DingetjeTest.java:11)
Caused by: java.lang.IllegalArgumentException: Can not set final java.lang.String field a.Dingetje.text to a.Dingetje
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at java.base/jdk.internal.reflect.UnsafeQualifiedObjectFieldAccessorImpl.get(UnsafeQualifiedObjectFieldAccessorImpl.java:38)
at java.base/java.lang.reflect.Field.get(Field.java:418)
at nl.jqno.equalsverifier.internal.reflection.FieldModifier.lambda$copyTo$1(FieldModifier.java:79)
at nl.jqno.equalsverifier.internal.reflection.FieldModifier.lambda$change$3(FieldModifier.java:113)
at nl.jqno.equalsverifier.internal.util.Rethrow.lambda$rethrow$0(Rethrow.java:47)
at nl.jqno.equalsverifier.internal.util.Rethrow.rethrow(Rethrow.java:30)
at nl.jqno.equalsverifier.internal.util.Rethrow.rethrow(Rethrow.java:45)
at nl.jqno.equalsverifier.internal.util.Rethrow.rethrow(Rethrow.java:55)
at nl.jqno.equalsverifier.internal.reflection.FieldModifier.change(FieldModifier.java:113)
at nl.jqno.equalsverifier.internal.reflection.FieldModifier.copyTo(FieldModifier.java:79)
at nl.jqno.equalsverifier.internal.reflection.InPlaceObjectAccessor.copyInto(InPlaceObjectAccessor.java:43)
at nl.jqno.equalsverifier.internal.reflection.InPlaceObjectAccessor.copy(InPlaceObjectAccessor.java:24)
at nl.jqno.equalsverifier.internal.checkers.ExamplesChecker.checkSingle(ExamplesChecker.java:84)
at nl.jqno.equalsverifier.internal.checkers.ExamplesChecker.check(ExamplesChecker.java:47)
at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verifyWithExamples(SingleTypeEqualsVerifierApi.java:413)
at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.performVerification(SingleTypeEqualsVerifierApi.java:369)
at nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi.verify(SingleTypeEqualsVerifierApi.java:304)
... 1 more
Here's the class under test:
package a;
import java.util.Objects;
public class Dingetje {
private final String text;
public Dingetje(String text) {
this.text = text;
}
#Override
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Dingetje)) {
return false;
}
Dingetje other = (Dingetje) o;
return text.equals(other.text);
}
#Override
public final int hashCode() {
return Objects.hash(text);
}
}
And the test:
package a;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test;
class DingetjeTest {
#Test
void implementsEquals() {
EqualsVerifier.forClass(Dingetje.class)
.withNonnullFields("text")
.verify();
}
}
What am I missing here?
EqualsVerifier uses Objenesis to create instances of classes, and it keeps the same reference of the objenesis object around for performance reasons. It caches all the objects it has created before, so that makes things quicker when you want to create the same object over and over again, which EqualsVerifier tends to do.
However, EqualsVerifier keeps a static reference to objenesis, which means that it lives as long as the JVM does. It turns out that the Quarkus test runner can re-run the same tests again and again, and it creates a new class loader each time. But part of the equality of java.lang.Class is that the classloader that created the class, must also be the same. So it couldn't retrieve these objects from its cache anymore and returnd instances with classloaders that are now different from the other objects created in the test, and this caused the exceptions that you saw.
In version 3.8 of EqualsVerifier (created as a result of this StackOverflow post), this issue can be avoided by adding #withResetCaches() like this:
EqualsVerifier.forClass(Dingetje.class)
.withResetCaches()
.withNonnullFields("text")
.verify();
That fixes the problem.
I am trying to add JMX metric in my Dropwizard application, But when I am trying make it up locally it gives me error. I added following in my Application class in initalize method :
guiceBundle.addModule(new MetricsInstrumentationModule(bootstrap.getMetricRegistry()))
bootstrap.addBundle(new JmxMetricsBundle());
and in guice module file, I have added provider:
#Provides
#Singleton
MetricRegistry providesMetricRegistry(Environment environment) {
return environment.metrics();
}
added below dependency in pom.xml
<dependency>
<groupId>com.palominolabs.metrics</groupId>
<artifactId>metrics-guice</artifactId>
<version>3.1.3</version>
</dependency>
In my class I am using it below way:
private Timer getTimer(String name) {
return metricRegistry
.timer(MetricRegistry.name(DocumentService.class, name));
}
public void method(){
final Timer.Context context = getTimer("methodMetric").time();
try{
//do something
}finally {
context.stop();
}
}
but when I am making my service up it is throwing following error:
DEBUG [2017-06-02 09:01:58,059] com.codahale.metrics.JmxReporter:
Unable to register timer! javax.management.InstanceAlreadyExistsException:
metrics:name=io.dropwizard.jetty.MutableServletContextHandler.connect-requests
DEBUG [2017-06-02 09:01:58,066] com.codahale.metrics.JmxReporter:
Unable to register gauge! javax.management.InstanceAlreadyExistsException:
metrics:name=io.dropwizard.jetty.MutableServletContextHandler.percent-
4xx-1m
And similar error messages, although my application is getting up successfully. I have no idea why this error is occurring, is it some localhost setup issue which will not happen on production or some genuine issue which I am missing. please help.
EDIT:
JmxMetricsBundle class:
public class JmxMetricsBundle implements Bundle {
public void initialize(Bootstrap<?> bootstrap) {
JmxReporter reporter = JmxReporter.forRegistry(bootstrap.getMetricRegistry()).build();
reporter.start();
}
#Override
public void run(Environment environment) {
}
}
Following are the modules in my project,
1. EJB module (version 3): We prepare ejb jar of this module and deploy on Weblogic11g server. It deals with database operation. It has #local, #Remote interface and #stateless classes implementing #local,#Remote interfaces.
2. Web Application : This web application takes inputs (user uploads file) from users, validates file and inserts data into database. It uses RMI.
Problem: On production (weblogic 11g server ) sometimes we observe exception saying $Proxy99 cannot be cast to "Remote interface name" (for different different classes) e.g com.xyz.fileProcessSetting.FileProcessSttgFacadeRemote.
But after some time when we again upload file, it gets uploaded successfully without any error.
Now, I do not understand how come these remote objects becomes temporarily unavailable? Never faced this issue on development/UAT environment. Also no idea how to reproduce and fix it.
Please help. Thanks in advance.
#Remote
public interface FileProcessSttgFacadeRemote {
//methods
}
#Local
public interface FileProcessSttgFacadeLocal {
//methods
}
#Stateless
public class FileProcessSttgFacade implements FileProcessSttgFacadeLocal, FileProcessSttgFacadeRemote {
//methods
}
in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>FileProcessSttgFacade</ejb-name>
<stateless-session-descriptor>
<business-interface-jndi-name-map>
<business-remote>com.xyz.fileProcessSetting.FileProcessSttgFacadeRemote</business-remote>
<jndi-name>FileProcessSttgFacade</jndi-name>
</business-interface-jndi-name-map>
</stateless-session-descriptor>
</weblogic-enterprise-bean>
In web application also in ejb module whenever we want to call methods we use following lookup method to get remote object:
public class someclass extends EjbLocator {
public void someMethod(){
FileProcessSttgFacadeRemote fpfr = (FileProcessSttgFacadeRemote) getService("FileProcessSttgFacade");
//other code
}
}
Following is the class used for JNDI lookup:
public class EjbLocator {
public Object getService(final String jndiName) throws Exception {
try {
obj = getDefaultContext().lookup(jndiName);
} catch (final Exception exp) {
exp.printStackTrace();
}
return obj;
}
protected Context getDefaultContext() {
try {
final Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL,"weblogic");
env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.PROVIDER_URL, "t3://<ip>:<port>");
defaultContext = new InitialContext(env);
return defaultContext;
} catch (final NamingException nExp) {
nExp.printStackTrace();
}
return null;
}
}
I'm using Eclipse and I have mulitmodule Maven project in which I use Lombok(1.16.4) Java=jdk1.7.0_71.
In Eclipse all my code compiles and JUnit testes pass. However in Maven (v. 3.2.3 and 3.3.3) code does not compile.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] DetermineMarketDirection.java:[86,42] cannot find symbol
symbol: method sumValuesDouble(java.lang.String)
location: variable listToWorkOn of type java.util.List<T>
[INFO] 1 error
This sumValuesDouble is my Lombok's extension method for type List<> which is defined in module A. Error above occures in module C which depends on module A.
This is part of ExtensionList.java:
public static <T> Double sumValuesDouble(List<T> list, final String methodName) {
return sumValuesOf(list, methodName, Double.class);
}
private static <T, N extends Number> N sumValuesOf(List<T> list, final String methodName, Class<N> type) {
Function<T, N> transform = new Function<T, N>() {
#SuppressWarnings("unchecked")
#Override
#SneakyThrows
public N apply(T from) {
Method method = from.getClass().getMethod(methodName);
return (N) method.invoke(from);
}
};
List<N> projectedList = Lists.transform(list, transform);
return sumAll(projectedList);
}
It's very strange because I have tests in Module A for this extension method and they compile OK and pass.
Part of test from Module A:
#ExtensionMethod({ ExtensionList.class })
public class ExtensionListSumAllTest {
#Test
public void testDouble() {
List<ValueDouble> listDouble = new ArrayList<>();
listDouble.add(new ValueDouble(1, 1d));
listDouble.add(new ValueDouble(2, 2d));
listDouble.add(new ValueDouble(3, 3d));
Double actual = listDouble.sumValuesDouble("getValue");
final Double expected = 6d;
assertEquals(expected, actual);
}
#AllArgsConstructor
#Getter
public class ValueDouble {
private final Integer id;
private final Double value;
}
}
What can I do to make Maven "see" this method?
BTW: I use a lot of extension methods in module c and Maven has problem with only that one. Also in this project/eclipse I use Lombok for a long time and I didn't had such problem before.
UPDATE:
I played a little bit more and I found out, that when I add 'dummy' code before execution of Extension method maven compile code wihtout problems.
So, this does not compile
#Slf4j
#ExtensionMethod({ ExtensionList.class })
public class SmaCalculator {
static <C extends Candle> double calculateSMA(List<C> candles, int sma) {
List<C> listToWorkOn = prepareListForSmaCalculation(candles, sma);
Double sum = listToWorkOn.sumValuesOf("getClosePrice");
Double smaValue = sum / sma;
return smaValue;
}
...other methods...
}
But this compiles SUCCESSFULLY by Maven, and dupa object does not even referes to listToWorkOn object:
static <C extends Candle> double calculateSMA(List<C> candles, int sma) {
List<C> listToWorkOn = prepareListForSmaCalculation(candles, sma);
List<C> dupa = new ArrayList<C>();
dupa.add(listToWorkOn.first());
dupa.sumValuesOf("getClosePrice");
Double sum = listToWorkOn.sumValuesOf("getClosePrice");
Double smaValue = sum / sma;
return smaValue;
}
I had the same problem, after switching back to 1.16.2 and it seems to work.
I'm trying to run a Restfuse test using NetBeans.
NetBeans is using the following Maven command to run the Restfuse Test:
mvn -Dtest=com.mycompany.RequestTest -DfailIfNoTests=false test-compile surefire:test
However, the HttpTest method didn't get called:
#RunWith(HttpJUnitRunner.class)
public class RequestTest {
#Rule
public Destination destination;
#Context
private Response response;
public MatchRequestTest() throws UnknownHostException {
this.destination = getDestination();
this.callbackHost = InetAddress.getLocalHost().getHostAddress();
}
#HttpTest(method = Method.GET, path = "/request")
public void matchRequest() {
assertOk(response);
}
}
Prefix your class name with "Test" i.e. TestRequestTest.