Missing dependency for method - rest

I am running REST Web Service and after adding some new Web Services I got some errors.
Why do I get these errors?
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK), annotated with GET of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
SEVERE: Missing dependency for method public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK), annotated with DELETE of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
I am using Jersey 1.1.1, these are my dependencies:
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Looks like methods service.ProyectoHasPersonaRESTFacade.find() and service.ProyectoHasPersonaRESTFacade.remove() take one parameter which is not annotated (i.e. it means the methods expect the request entity to be passed into this parameter), however, these methods are mapped to HTTP GET and DELETE. Neither HTTP GET nor HTTP DELETE can have an entity. So the unannotated parameter on the corresponding Java methods does not make sense.
You can get the ID/PK of the object to be retrieved/deleted e.g. by putting it either in a path parameter or query parameter.

Related

Connecting to a running Gemfire server

Using gfsh I have started a locator on my PC. How do I connect to this locator using spring-data-gemfire.
Here is the my locator
gfsh>start locator --name=locator1
Locator in /Users/adas/locator1 on 10.1.51.200[10334] as locator1 is currently online
Now I have the following class to connect to this locator
#ClientCacheApplication(locators = {
#ClientCacheApplication.Locator(host = "10.1.51.200", port = 10334)
})
#EnableEntityDefinedRegions(basePackageClasses = Person.class,
clientRegionShortcut = ClientRegionShortcut.LOCAL)
#EnableGemfireRepositories
public class GemfiretestApplication {
public static void main(String[] args) {
SpringApplication.run(GemfiretestApplication.class, args);
}
On compiling I get the following error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178)
Given the INCREDIBLY limited information provided (partial stacktrace, no versions, no maven/gradle build files) I could only venture a guess at your problem. I think #juanramos has the correct idea.
I'm testing with:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelave-SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
AND
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
Without the full stack trace I believe that I see your error. If then add the following exclusion, this problem disappears.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
If this does not solve your problem, please forward your complete stacktrace... or maybe the last "Caused by:...." statement and/or list of your dependencies.

com.sun.enterprise.admin.remote.RemoteFailureException

I am new to REST webservices and I am trying to build a webservice using jersey to upload a file. When deploying, i get this error
Artifact RestTest:war exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : CDI definition failure:WELD-000071: Managed bean with a parameterized bean class must be #Dependent: class org.glassfish.jersey.process.internal.DefaultRespondingContext. Please see server.log for more details.
I created the project using this command:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.test -DartifactId=RestTest -Dpackage=com.test \
-DarchetypeVersion=2.27
My pom.xml looks like:
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<scope>provided</scope>
<version>2.0-m05-2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.0-m05-2</version>
</dependency>
</dependencies>
According to this answer, i've changed to scope to 'provided', but it isn't working.
Thanks in advance :)

spring-data-redis 1.7.x and lettuce 4.1.x - java.lang.IncompatibleClassChangeError

Things work just fine when I use lettuce version 3.4.x; Looks like lettuce has changed a class contract when it updated to 4.1.x (from abstract class to an interface) and spring-data-redis 1.7.x is not aware of that. I get the following error:
BeanInstantiationException: Failed to instantiate
[org.springframework.data.redis.core.RedisKeyValueAdapter]: Constructor threw exception;
nested exception is java.lang.IncompatibleClassChangeError:
class org.springframework.data.redis.connection.lettuce.BytesRedisCodec has
interface com.lambdaworks.redis.codec.RedisCodec as super class
Not sure if Spring data redis team is working on it? Or is there a workaround or suggestion that I can use to still keep at 4.1.x version of lettuce?
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.0.RC1</version>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.1.1.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<optional>true</optional>
</dependency>

Problem with #Indexed annotations in hibernate search

I'm actually trying to deploy HibernateSearch in a J2EE application. I have imported some dependencies I've seen on tuto's :
<!-- HIBERNATE DEPENDENCIES -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
<!-- Hibernate Search -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers</artifactId>
<version>3.0.3</version>
</dependency>
My problem is, in order to continue, I need to put the #Indexed annotation in my entity classes but I don't have access to this annotation(Eclipse doesn't know it and of course,that doesn't pass the compilation)
Could you give me some advice or lead ? Maybe I don't have the good dependencies ?
I don't use Eclipse or Maven but I can confirm that in my project that uses Hibernate Search 3.3.0 that the Indexed annotation does definitely exist in the hibernate-search-3.3.0.Final JAR. Try update your dependencies to use the latest JAR. There is definitely nothing else that you need to use this annotation though.

How do I import javax.validation into my Java SE project?

I'm trying to add constraints checking, as described here How to specify the cardinality of a #OneToMany in EclipseLink/JPA
Here are the dependencies I'm using (with Maven):
<dependencies>
<!-- Bean Validation API and RI -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
</dependencies>
That you can get from this repository:
<repositories>
<repository>
<id>jboss</id>
<name>JBoss repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
The dependencies as of 2019:
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.16.Final</version>
</dependency>
This transitively pulls in the dependency to the Bean Validation API, so you don't need to do this anymore:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
For additional features, Expression Language and CDI support, you might need to add:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b09</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>6.0.16.Final</version>
</dependency>
Source: Hibernate Validator documentation
These are all in Maven Central Repo, so you don't need to add the JBoss repo.
And BTW here's my example convenience method:
public static <T extends Object> void validate( T object ) throws MigrationException
{
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<T>> valRes = validator.validate( object );
if( ! valRes.isEmpty() )
{
StringBuilder sb = new StringBuilder("Validation failed for: ");
if( object instanceof Origin.Wise )
sb.append( ((Origin.Wise)object).getOrigin() );
else
sb.append(object);
for( ConstraintViolation<T> fail : valRes)
{
sb.append("\n ").append( fail.getMessage() );
}
throw new IllegalArgumentException( sb.toString() );
}
}
The Origin.Wise is something like JAXB's #XmlLocation Locator.
In 2013 (the original post) the versions were:
<!-- BeanValidation and Hibernate Validator. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>5.4.0.Final</version>
</dependency>
An alternative solution other than Hibernate
Overview
javax.validation (validation-api) is validation rules that follows JSR 380 Java Bean Validation Specification. The validation rules need a validator in order to perform validating according to the validation rules.
And there are various validators such as hibernate (the most popular one), Bval, etc.
Bval
Bval is an alternative solution that I think It pretty cool also besides Hibernate. And here you can follow my alternative solution:
MVN
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.2</version>
</dependency>
Implementation
create static a validator
...
import javax.validation.Validation;
import javax.validation.Validator;
import org.apache.bval.jsr.ApacheValidationProvider;
...
private static final Validator validator;
static {
validator = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory()
.getValidator();
}
There you go!!!.
Again, validator, it is just a validator, in which you switch to other validators easily.
Pro&Con
It is not that popular, but You gonna like it.
For Maven projects only is necessary use this dependency for validation annotations:
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.16.Final</version>
</dependency>
If you are using spring boot you can add the following dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>