I have a java class with a member:
#Entity
public class TypeA {
...
#Reference(lazy = true) private TypeB anObj;
...
}
Now when I do a datastore.find(TypeA.class).asList().get(0), the reference also gets loaded and I get the message "WARNING: Lazy loading impossible due to missing dependencies." logged to the console.
What are the dependencies I'm missing and how do I include them?
You'll need to add this to your pom.xml (if you're using maven):
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>[2.1_3,3.0)</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.thoughtworks.proxytoys</groupId>
<artifactId>proxytoys</artifactId>
<version>1.0</version>
<type>jar</type>
<optional>true</optional>
</dependency>
Related
I'm trying to use DBCPConnectionPool service in my custom processor. So, how to use in-built controller services (which are already available on NiFi) in our custom processors.
Here are my properties in *-nar/->pom.xml
<dependencies>
<dependency>
<groupId>org.sample.com</groupId>
<artifactId>nifi-customprocessor-processors</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>1.14.0</version>
<type>nar</type>
</dependency>
</dependencies>
Here are my dependencies in *processors/->pom.xml
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock</artifactId>
<version>1.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service-api</artifactId>
<version>1.14.0</version>
</dependency>
And here is my propertydescriptor for DBCPConnetionPool service :-
public static final PropertyDescriptor DBCPConnectionPool_SERVICE = new PropertyDescriptor.Builder()
.name("DBCPConnectionPoolLookup Service")
.description("The Controller Service to use in order to establish a connection")
.required(true)
.dynamic(true)
.identifiesControllerService(DBCPService.class)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
and in my OnTrigger method I didn't used it as :-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
and was trying to use this con object as in regular passion createStatement->executeQuery.
When I tried to package it using mvn clean install it started throwing error as : A required class was missing while executing org.apache.nifi:nifi-nar-maven-plugi
n:1.3.1:nar: org/apache/nifi/record/sink/RecordSinkService
then I added the following dependencies in processors/->pom.xml
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-sink-service</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-sink-api</artifactId>
<version>1.14.0</version>
</dependency>
This time it was new error as :- Failed to create Extension Definition for CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup: Null
PointerException
I also checked by commenting out code which I have written, to check the way I'm using that property was wrong but, even that didn't worked.:-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
Can someone help me out in order to use DBCPConnectionPoolService controller service in my custom processor?
I had the same issues the other day and I solved it by using AbstractControllerService instead of DBCPConnectionPool therefore not needing org.apache.nifi.dbcp.DBCPService anymore. Therefore my code would look like this:
MyService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(MyService.class);
Connection con = DBCPService.getConnection();
MyService is the custom interface that extends ControllerService.(you have to use it when you also define the PropertyDescriptor DBCPConnectionPool_SERVICE)
And StandardMyService the class that extends AbstractControllerService and implements MyService and getConnection() from it.
I have class that one of it's parameters i want to set from properties file:
import org.springframework.beans.factory.annotation.Value;
(..)
#Getter
#Setter
#NoArgsConstructor
public class ConvertNonStandardOfferRequestDtoWrapper {
private ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto;
#Value("true")
private boolean documentPrintoutsRequired;
public ConvertNonStandardOfferRequestDtoWrapper(ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto) {
this.convertNonStandardOfferRequestDto = convertNonStandardOfferRequestDto;
}
}
What i see inside constructor is that documentPrintoutsRequired is false instead of true. I see that when debuging and setting breakpoint inside constructor. And i have a pom file for this module:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>x</groupId>
<artifactId>policy</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>
<artifactId>policy-api</artifactId>
<dependencies>
<dependency>
<groupId>x</groupId>
<artifactId>common-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
(...)
</build>
</project>
I am wonderning why #value does not work correctly ?
I'd advise you use constructor inyection for all attributes, this way you'll see the injected #Value during construction time.
Besides the class must be a Spring bean, so add #Component annotation:
#Component
#Getter
#Setter
#NoArgsConstructor
public class ConvertNonStandardOfferRequestDtoWrapper {
private ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto;
private boolean documentPrintoutsRequired;
public ConvertNonStandardOfferRequestDtoWrapper(ConvertNonStandardOfferRequestDto convertNonStandardOfferRequestDto,
#Value("${yourproperty}") boolean documentPrintoutsRequired) {
this.convertNonStandardOfferRequestDto = convertNonStandardOfferRequestDto;
this.documentPrintoutsRequired = documentPrintoutsRequired;
}
}
You can read the value from properties file, such as
username = Tom.
use #Value in Java, you can set a default value like this:
#Value("${username:Jack}")
If the username does not exist in properties file, it will be "Jack".
Did you try this:
#Value("${yourPropInPropertiesFile}")
private boolean documentPrintoutsRequired;
I am currently trying to create a Resteasy Client, having to use Version 2.3.10.Final. Unfortunately, I should not use a newer Version. I am very new to this, so I hope I manage to provide all required Information to make this question answerable.
First, the Request is created and finally "PUT". The returned ClientResponse is to be evaluated.
I can successfully call
Response.getStatus()
showing me that the "PUT" has been successful, as the Status is equal to
Response.Status.CREATED.getStatusCode()
However, any attempt to call response.readEntity Returns the error
java.lang.AbstractMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;
at blabla.evaluateResponse(MyResteasyClient.java:80)ยด
This is for any attempt to call .readEntity, but for the sake of specificity, let's concentrate on
String entity = Response.readEntity(String.class);
When attempting response.getEntity(), it Returns the following error message:
java.lang.RuntimeException: RESTEASY001555: No type information to extract entity with, use other getEntity() methods
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:337)
at blabla.evaluateResponse(MyResteasyClient.java:81)
Am I even on the right Track? My Goal is to achieve something along the lines of:
List<? extends MyResponse> myResponses = response.readEntity(new GenericType<List<MyResponse>>() {});
Where the class "MyResponse" is an implementation of the Interface
public interface MyPartialResponse {
boolean isSuccessful();
String getMessage();
}
The dependencies within pom.xml are:
<properties>
<version.jackson>2.6.5</version.jackson>
<version.resteasy-client>2.3.10.Final</version.resteasy-client>
</properties>
<dependencies>
(removed a company specific dependency)
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${version.resteasy-client}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${version.resteasy-client}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
</dependencies>
If anyone happens to land on this question with the same error, let me provide the answer, how I solved my issue:
By adding
BaseClientResponse<?> r = (BaseClientResponse<?>) response;
I could successfully call
r.getEntity(new GenericType<List<MyResponse>>() {});
I think there is a conflicts between Jar files in Maven. Please check your maven dependency hierarchy.
I have a custom JSP tag
public class HappyTag extends TagSupport { ... }
and now I need to test it.
So I've created a simple JUnit test:
#Test
public void testTag() {
HappyTag tag = new HappyTag();
}
and I get the following error:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/jsp/tagext/TagSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
(.....)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I am using maven to build and test my application, tags included.
My current dependencies of the tags sub-module are:
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
plus some dependencies from the parent module:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.portletfaces</groupId>
<artifactId>portletfaces-bridge-impl</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
Those dependencies are enough to compile and use the tags in my JSP. They are not enough to test the tag :-(
So, what did I do wrong?
Kindest regards,
Q.
the Java EE maven dependencies only provides stubs to help compile code which requires those interfaces. IT doe snot provide the implementation. Hence you cannot run them. You need to either work around to mock the behavior (which might end up refactoring your code a lot), or you need to functionally run the test using a dependency which provides a full implementation of the API's.
Maybe this answer might help.
You can use mockito and or power mock to mock servlet context and jsp page context. Mock each method that your tag calls to properly function(doTag). You need to add the mocking framework and javax.el as test dependencies.
Neel is right. You need to mock the ServletContext if you don't want to use the full javaee.jar.
If you are using Spring Test you can do it in the following way:
public class MyCustomTagTest {
private MockServletContext mockServletContext;
private MockPageContext mockPageContext;
#BeforeEach
void setUp() {
mockServletContext = new MockServletContext();
mockPageContext = new MockPageContext(mockServletContext);
}
#Test
void testMyTag() throws Exception {
MyCustomTag myCustomTag = new MyCustomTag();
myCustomTag.setPageContext(mockPageContext);
myCustomTag.doStartTag();
String output = ((MockHttpServletResponse) mockPageContext.getResponse()).getContentAsString();
// do your assertions on output
}
}
I have a HFile that I am trying to read/deserialize using Java.
Looks like this HFile.reader is very promising but however, I am having a hard time even getting the library imported in Maven.
This is how my POM looks like:
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
And somehow I don't see that many classes or objects when I tried to import.
This class can be found in the hbase-server artifact, so you need to depend on that one instead of hbase-common and hbase-client:
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.2.1</version>
</dependency>
But do note that this class is not intended to be used by 3rd parties. It is annotated #InterfaceAudience.Private, which means:
Intended for use only within Hadoop itself.