import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import org.apache.cxf.jaxrs.ext.search.SearchCondition;
import org.apache.cxf.jaxrs.ext.search.SearchContext;
import com.f2s.bean.Recentbean;
#Path("search")
public class SearchResource {
private List<Recentbean> ra;
#Path("book")
#GET
public List<Recentbean> findBooks(#Context SearchContext searchContext)
{
SearchCondition<Recentbean> condition = searchContext.getCondition(Recentbean.class);
return condition.findAll(ra);
}
error :- annotated with GET of resource, class com.f2s.restws.SearchResource, is not recognized as valid resource method.
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
First of all, you "question" is actually not a question. You're just presenting an error that you get. No explanation, no expected behaviour, no question asked. Providing some more details would be helpful.
Secondly, have you had a look on the other questions dealing with the presented exception? Here there are a few:
Exception :com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Jersey: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Errors$ErrorMessagesException when using Jersey in Java
Because of my reputation I couldn't add this as a comment...
Related
I'm making a Java Spring project in IntelliJ as an exercise and I don't understand a file configuration error I'm having.
Please look at my project directory layout as described in this screenshot:
The three most important files here are the Main & GameConfig classes, and the game.properties file. Or, to use their full package directory names, "console/src/main/java/academy.learnprogramming.console.Main", "core/src/main/java/academy.learnprogramming.config.GameConfig" and core/src.resources.config.game.properties
When I run project, the Main class tries to run the following code:
package academy.learnprogramming.console;
import academy.learnprogramming.MessageGenerator;
import academy.learnprogramming.NumberGenerator;
import academy.learnprogramming.config.GameConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
private static final Logger log = LoggerFactory.getLogger(com.sun.tools.javac.Main.class);
public static void main(String[] args) {
log.info("Guess the number");
//== create the context first ==
ConfigurableApplicationContext context
= new AnnotationConfigApplicationContext(GameConfig.class);
// rest of code, which we never get to because of an error with the above line
When I try to create ConfigurableApplicationContext, I am trying to call the GameConfig class from the Core package. But I get this runtime error instead:
Exception in thread "main"
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class
[academy.learnprogramming.config.GameConfig]; nested exception is
java.io.FileNotFoundException: class path resource
[config/game.properties] cannot be opened because it does not exist
I do not understand why it thinks GameConfig does not exist, or how to fix it. No solutions I have found seem to have the precise answer for this. I have gotten a configuration comparison from someone whose code is identical to mine, but neither of us understand why their version works and mine does not.
For comparison's sake, the GameConfig class has the following code:
package academy.learnprogramming.config;
import academy.learnprogramming.GuessCount;
import academy.learnprogramming.MaxNumber;
import academy.learnprogramming.MinNumber;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
#Configuration
#ComponentScan(basePackages = "academy.learnprogramming")
#PropertySource("classpath:config/game.properties")
public class GameConfig {
//rest of GameConfig code here...
While game.properties is as simple as this:
game.maxNumber = 100
game.guessCount = 10
game.minNumber = 0
I can't find a question similar to this, nor do other websites point out what's going on. Does anyone have any idea why this error might be happening? Any advice would be invaluable
I am starting with Spring Boot and trying to make a Rest service.
I am writing a controller where there are RequestMappings to 3 methods.
Two of them are working fine while the thirl annotation is giving this error while writing the code.
Multiple markers at this line
- Syntax error, insert "enum Identifier" to complete EnumHeader
- Syntax error, insert "EnumBody" to complete EnumDeclaration
I tried everything from other answers but cant seem to find out the issue. Here is my code for the Controller-
package io.springboot.topics;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class TopicsController {
#Autowired
private TopicSrvice topicService;
#RequestMapping("/topics")
public List<Topic> getAllTopics() {
return topicService.getAllTopics();
}
#RequestMapping("/topics/{id}")
public Topic getTopic(#PathVariable String id) {
return topicService.getTopic(id);
}
#RequestMapping(method=RequestMethod.POST,value="/topics")
}
The error is coming in the last line ie last Requestmapping().
A bit late but for those that are just finding this issue: You need to type in the actual method under the #RequestMapping. Eclipse gives an issue when you stop at this stage but once you write your method, you are good to go. At least that is what worked for me.
So:
#RequestMapping(method=RequestMethod.POST,value="/topics")
public ... {
//your method
}
You are writing /topics URL for two methods,one for GET and one for POST,Spring does not support this configuration,You can either change url for two different methods or you can write a single method having url /topics with array of HttpMethod like method = { RequestMethod.GET, RequestMethod.POST }
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have imported project to my new machine (to eclipse) and it threw 88 errors even that on previous machine it was working good. here are the types of errors:
MINUTES cannot be resolved or is not a field
Syntax error
Method not applicable to arguments
isEmpty() undefined
And when I check it all of syntax is good etc.
Anyone had similar problem?
Here's code which throws an exception (MINUTES cannot be resolved or is not a field )
try {
TimeUnit.MINUTES.sleep(Config.DOCS_CHECK_INTERVAL);
} catch (InterruptedException e) {
log.error("Exception", e);
}
Imports:
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.security.cert.X509Certificate;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.ikubasienki.core.Config;
All of your errors suggest that you are using an outdated Java Version. For example, in Java 5, there was no TimeUnit.MINUTES: https://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/TimeUnit.html. It has been added in Java 6.
Assumed that you are calling isEmpty() on a String Object, the same is true: String.isEmpty() has been added in Java 6: https://docs.oracle.com/javase/6/docs/api/java/lang/String.html#isEmpty(), hence you would get an isEmpty() undefined error when building the project with Java 5.
Please check the settings of the "JRE System Library" you are using to build the project in Eclipse:
Verify that the path shown for the jar files matches the java runtime you want to use.
If that still does not help, create a new Project in Eclipse with a simple class like
package com.example;
public class Simple {
public static void main(String[] args) {
System.err.println(System.getProperty("java.version"));
System.err.println("".isEmpty());
}
}
and run it. The output should be something like
1.7.0_80
true
Another common source of errors is the Compiler Compliance Level setting of your project:
However, this would not explain the "undefined symbol" errors since it affects the language level only (e.g. whether enum or generics are allowed). It might explain your syntax error, though.
Make sure your custom jre in eclipse points to jre folder (if you're using jde make sure twice it's not ponting to jde but to jre inside jde!!)!
I have a problem producing JSON in my application.
I'm trying a tutorial about Consuming Java Restful Web Service with AngularJS.
I've created a dynamic web project as my RESTful server and then added the following libraries:
asm-3.3.1.jar
jackson-core-asl-1.9.9.jar
jackson-jaxrs-1.9.9.jar
jackson-mapper-asl-1.9.9.jar
jackson-xc-1.9.9.jar
jersey-bundle-1.8.jar
jersey-bundle-1.9.jar
jersey-client-1.9.jar
jersey-core-1.9.jar
jersey-json-1.9.jar
jersey-media-json-jettison-2.4.jar
jersey-server-1.9.1.jar
jersey-servlet-1.12.jar
jettison-1.3.3.jar
jsr311-api-1.1.1.jar
Here is the service :
package ws;
import java.awt.PageAttributes.MediaType;
import java.util.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import entities.Prospect;
#Path("prospect")
public class ProspectRestful {
#GET
#Path("findall")
#Produces(MediaType.APPLICATION_JSON)
public List<Prospect> findAll(){
List<Prospect> result = new ArrayList<Prospect>();
result.add(new Prospect(35, "Name 35", "last35"));
result.add(new Prospect(36, "Name 36", "last36"));
return result;
}
}
But I'm getting this error:
APPLICATION_JSON cannot be resolved or is not a field.
I've seen in another question that jersey-media-json-jettison-2.4.jar should be there so I added it but no sign.
I'm sure I'm not using a Maven project, in the same tutorial they didn't use Maven either.
Remove this
import java.awt.PageAttributes.MediaType;
and add this
import javax.ws.rs.core.MediaType;
In my case it is not working, so if anyone facing the error then try...
import org.springframework.http.MediaType;
It worked for me...
I'm asking myself how deep should I go in (unit) testing my classes.
As example, I have following simple class .
import javax.annotation.security.PermitAll;
import javax.ejb.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path(value = "ping")
#Singleton
#PermitAll
public class PingRestService {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String pingMethod(){
return "pong";
}
}
I wrote following unit test:
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import javax.annotation.security.PermitAll;
import javax.ejb.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
public class PingRestServiceTest {
PingRestService prs = new PingRestService();
#Test
public void testClassAnnotations(){
assertEquals(3, prs.getClass().getAnnotations().length);
assertTrue(prs.getClass().isAnnotationPresent(PermitAll.class));
assertTrue(prs.getClass().isAnnotationPresent(Singleton.class));
assertTrue(prs.getClass().isAnnotationPresent(Path.class));
assertEquals("ping", prs.getClass().getAnnotation(Path.class).value());
}
#Test
public void testPingMethodAnnotations() throws SecurityException, NoSuchMethodException{
Method method = prs.getClass().getDeclaredMethod("pingMethod");
assertEquals(2, method.getAnnotations().length);
assertTrue(method.isAnnotationPresent(GET.class));
assertTrue(method.isAnnotationPresent(Produces.class));
assertEquals(1, method.getAnnotation(Produces.class).value().length);
assertEquals(MediaType.TEXT_PLAIN, method.getAnnotation(Produces.class).value()[0]);
}
#Test
public void testPingMethod() {
assertEquals("pong", prs.pingMethod());
}
}
does it make sense?
Or should I only test the returning string ("pong", testPingMethod), skipping all annotations tests (testClassAnnotations,testPingMethodAnnotations) ?
I think some annotations are part of a business logic (e.g. PermitAll), and therefore should be tested.
Most of the time one tests the functionality of the code and not the way it is implemented. This is called Black Box Testing (see: http://en.wikipedia.org/wiki/Black-box_testing).
When implementing a test you should ask yourself: "What are the possible input values of the unit to test and what are the expected results?"
Now in the test you call your code with the input values and check the result with the expected one to make sure your code behaves the way you want it.
Over time you might optimize the code without wanting to change the functionality. Then you should not need to change your test. But you can re-run it to make sure it still behaves the same way. Even if it is implemented differently. Or you might make change implementation details that have side effects to the functionality you tested. Also in this case you don't need to change the test but you just need to re-run it.
In your simple case you have no input and one static output so you can just call the method and check if "pong" is returned. But real life cases that are tested are rarely that simple.
Edit: You can see the security that #PermitAll configures and the URL path that '#Path' configures as inputs and also test them in an integration test the way 'Boris the Spider' and 'Avi' suggested. But the other annotations are implementation specific.
In my opinion those annotations are aspects of your class and not the essence of it, its real purpose, so shouldn't be unit tested.
Maybe tomorrow you will use Spring MVC instead of JAX-RS, but your class would have the same behavior so the unit test should be the same