Everytime I try to implement a modalwindow I get:
java.lang.ClassNotFoundException: org.apache.wicket.request.resource.CompressedResourceReference
None of my libraries has this element. My dependency are:
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>1.5.3</version>
</dependency>
<!-- DatePicker -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-datetime</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>1.5.3</version>
</dependency>
€ Thats how I implemented my modalwindow:
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.util.time.Duration;
public class ModalPanel1 extends WebPage
{
public ModalPanel1(String id)
{
final ModalWindow modalWindow = new ModalWindow("modal");
modalWindow.setTitle("Popup");
modalWindow.setInitialWidth(400);
modalWindow.setInitialHeight(400);
modalWindow.setResizable(true);
modalWindow.setContent(new AbstractModalClosePanel(modalWindow)
{
public void onClick(AjaxRequestTarget target)
{
modalWindow.close(target);
}
});
add(modalWindow);
add(new AjaxLink<Void>("open")
{
#Override
public void onClick(AjaxRequestTarget target)
{
modalWindow.show(target);
}
});
add(new AbstractAjaxTimerBehavior(Duration.seconds(2))
{
#Override
protected void onTimer(AjaxRequestTarget target)
{
modalWindow.show(target);
stop();
}
});
}
}
and
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.panel.Panel;
public abstract class AbstractModalClosePanel extends Panel
{
public AbstractModalClosePanel(ModalWindow modalWindow)
{
super(modalWindow.getContentId());
}
There are no old imports.
Complete Stack Trace
Complete stack:org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.onespark.wicket.components.tasks.Tasks()'. Might be it doesn't exist, may be it is not visible (public). at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:196) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:68) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:47) at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:103) at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:264) at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165) at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:105) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:224) at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:68) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:47) at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:103) at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:264) at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165) at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:105) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:224) at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)java.lang.NoClassDefFoundError: org/apache/wicket/request/resource/CompressedResourceReference at com.onespark.wicket.components.tasks.ModalPanel1.(ModalPanel1.java:16) at com.onespark.wicket.components.tasks.Tasks.(Tasks.java:14) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:68) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:47) at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:103) at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:264) at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165) at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:105) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:224) at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
CompressedResourceReference was dropped in Wicket 1.5 along with other compression stuff.
If you have a reference to this in your own code, you should just use a normal ResourceReference or other non-compressed version.
In earlier versions, it was used in ModalWindow, but it's not at least in 1.5.3, so
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>1.5.3</version>
</dependency>
should have worked.
I would try that again, and make sure you've got a clean update so there isn't a reference to old ModalWindow code hanging around.
There may well still have been references in a release candidate, as I think it was still in wicket-core in some release candidates.
You might also want to look at more of the stack trace to narrow down where the reference to this class is.
Related
We had an integration tests such as the one that follows that used to work:
#ActiveProfiles("local")
#WithMockUser("j_unit_user_http_test")
#RunWith(SpringRunner.class)
#SpringBootTest(
classes = { Application.class },
webEnvironment = RANDOM_PORT
)
#Transactional
#Rollback
#AutoConfigureMockMvc()
public abstract class HttpTest {
static {
//reads and sets a dependency related props
PropertiesReader propertiesReader = new PropertiesReader();
propertiesReader.readDependencyProperties().forEach(System::setProperty);
}
#Autowired
private MockMvc mockMvc;
#PersistenceContext
private EntityManager em;
#Test
public void createDashboard() {
// POST is a utility method that wraps "mockMvc.perform(post(url))", I've omitted it here for brevity.
var postResult = POST("/api/dashboards", Map.of("name", "wonderland"));
var newDashboard = extractJson(postResult);
assertTrue(newDashboard.get("id").isInt());
}
}
Among the changes we made the significant ones that seem to be causing the errors are:
Upgrading spring-boot from '2.3.0' to '2.5.6'
Setting the environment properties needed by some of our dependencies in the static void main class of our app:
public class Application {
public static void main(String[] args) {
// reads and sets dependency related props
PropertiesReader propertiesReader = new PropertiesReader();
propertiesReader.readDependencyProperties().forEach(System::setProperty);
}
}
The error we get is:
java.lang.StackOverflowError
at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:828)
at java.base/java.lang.Throwable.getStackTrace(Throwable.java:820)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:55)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:60) // several frames of this follow
My guess is that the mockMvc is not getting configured correctly, because if I use it without #SpringBootTest and #AutoConfigureMvc, the tests work. Any idea what could be wrong?
The above issue has been fixed.
In the commit when the tests started failing, among other changes, the spring-boot version was changed from 2.3.x to 2.5.x
Turns out in version 2.4 spring-boot removed JUnit 5's vintage engine.
As pointed out in their release notes, ideally, i should migrate the tests to junit 5, but, in the meantime, adding the following in build.gradle helps:
testImplementation("org.junit.vintage:junit-vintage-engine") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
Equivalent changes in pom.xml would be:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Getmapping;
#Controller
public class HomeController {
#GetMapping("/")
public String home(){
return "hone";
}
}
I just can't import org.springframework.web so that I can't use #GetMapping.
How to solve this problem?
Should I add more dependencies?
Add spring-web module to your classpath.
Gradle
compile group: 'org.springframework', name: 'spring-web', version: '5.2.6.RELEASE'
Maven
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
In build.gradle, under dependencies, add:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// TODO: Add this implementation
implementation 'org.springframework:spring-web:5.3.15'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Then, as shown below, be sure to 'Reload All Gradle Projects'.
For additional context, consult the docs on Maven Repository.
Essentially, we have to specify this source for our import to know from where to import.
It's not clear to me why this isn't part of the offerings whenever we use the Spring Intializr. 🤷🏾♂️
I'm trying to run the Google Api Vision sample code but I'm getting this error:
java.lang.NoClassDefFoundError:com/google/cloud/vision/v1/ImageAnnotatorClient
These are the dependencies that imported into my project.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>1.74.0</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
Code that I'm using. Which is provided google Vision API from: https://cloud.google.com/vision/docs/libraries
package com.google.cloud.vision.api.utils;
//Imports the Google Cloud client library
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.Image;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.protobuf.ByteString;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {
// The path to the image file to annotate
String fileName = "/content/dam/USGBoral/Australia/Website/Images/products/steel_framing/SteelFraming-335x135_en.jpg";
// Reads the image file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString imgBytes = ByteString.copyFrom(data);
// Builds the image annotation request
List<AnnotateImageRequest> requests = new ArrayList<>();
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder()
.addFeatures(feat)
.setImage(img)
.build();
requests.add(request);
// Performs label detection on the image file
BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return;
}
for (EntityAnnotation annotation :res.getLabelAnnotationsList()) {
annotation.getAllFields()
.forEach((k, v) -> System.out.printf("%s : %s\n", k, v.toString()));
}
}
}
}
}
Use package Google.Cloud.Vision.V1 or you might also want to check the correct Client Library to use depending on your framework.
I am trying to test google cloud storage in local mvn jetty server.
defining the following java servlet I get the following error during servlet initiallization.
#WebServlet(name = "receiveImage", value = "receiveImage")
#SuppressWarnings("serial")
#MultipartConfig()
public class receiveImage extends HttpServlet {
private static final String BUCKET_NAME = "testbucket";
private static Storage storage = null;
#Override
public void init() {
storage = StorageOptions.defaultInstance().service();
}
HTTP ERROR 500
Problem accessing /receiveImage. Reason:
Server Error
Caused by:
java.lang.IllegalAccessError: tried to access method com.google.cloud.ServiceOptions.getFromServiceLoader(Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; from class com.google.cloud.HttpServiceOptions
at com.google.cloud.HttpServiceOptions.(HttpServiceOptions.java:154)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:69)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:27)
at com.google.cloud.sto
i define the following maven dependency in pom file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.4.0</version>
</dependency>
Appreciate for helps.
I could resolve the issue:
there is a conflict between these two dependencies:
dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.5.1</version>
</dependency>
I just changed the first dependency to
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<version>0.5.1</version>
</dependency>
I wanted to implement Jawr for minification and obfuscation of CSS and JS resources. I am using a Spring MVC project where the configurations are done using Java code using annotations and XML is not used. Now able to find a documentation for the same. Can some one suggest me the configuration or a reference link.
jawr dependencies to your pom:
<dependency>
<groupId>net.jawr</groupId>
<artifactId>jawr-core</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>net.jawr.extensions</groupId>
<artifactId>jawr-spring-extension</artifactId>
<version>3.6</version>
</dependency>
Build a controller like this:
#Controller
public class JsController extends JawrSpringController
{
public JsController ()
{
setType("js");
setConfigLocation("/jawr.properties");
}
#RequestMapping("/js/**")
public void javascript ( HttpServletRequest request, HttpServletResponse response ) throws Exception
{
handleRequest(request, response);
}
}