Swagger ApiListingResource is not recognized as a valid resource - java

I'm trying to integrate Swagger into my Jersey application following the guide they provide: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5
I'm using Jersy v1.17 and I'm using a custom application rather than web.xml
The following is everything I have in my simple test project which is failing!
public class ResConfig extends DefaultResourceConfig { // custom app
public ResConfig() {
super();
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[] { "http" });
beanConfig.setHost("localhost:9998");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("test.resources"); // the package containing my resource
beanConfig.setScan(true);
}
}
The simple resource I have
#Path("hello")
#Produces("application/json")
public class Res {
public Res() {
}
#GET
public Response getHello() {
Result result = new Result(); // Result is annotated with XmlRootElement and contains one field String str;
result.setStr("hello");
return Response.status(Status.OK).entity(result).build();
}
}
The main:
public static void main(String[] args) throws Exception {
ResConfig resConfig = new ResConfig();
resConfig.getClasses().add(Res.class);
resConfig.getClasses().add(io.swagger.jaxrs.listing.ApiListingResource.class);
resConfig.getClasses().add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
GrizzlyServerFactory.createHttpServer("http://localhost:9998/", resConfig);
System.in.read();
}
the POM contains the following:
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
The Jersey Grizzly server fails on start by throwing exception:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response io.swagger.jaxrs.listing.ApiListingResource.getListing(javax.ws.rs.core.Application,javax.servlet.ServletConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo,java.lang.String) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response io.swagger.jaxrs.listing.ApiListingResource.getListing(javax.ws.rs.core.Application,javax.servlet.ServletConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo,java.lang.String), annotated with GET of resource, class io.swagger.jaxrs.listing.ApiListingResource, is not recognized as valid resource method.
SEVERE: Missing dependency for field: javax.servlet.ServletContext io.swagger.jaxrs.listing.ApiListingResource.context
Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:243)
at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:137)
I searched the first 2 pages of Google for an answer but nothing helped!

Swagger uses Servlet APIs, so the application MUST run in a servlet environment. The way you are configuring Grizzly does not set up a servlet container. It is only an HTTP server.
You want to use the jersey-grizzly2-servlet dependency instead, and use the GrizzlyWebContainerFactory to bootstrap the application. This will set up a servlet container.
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2-servlet</artifactId>
<version>1.19.1</version>
</dependency>
Map<String, String> initParams = new HashMap<>();
initParams.put("javax.ws.rs.Application", "com.package.ResConfig");
GrizzlyWebContainerFactory.create(uri, initParams);

Related

Schedule Task with Jax-RS and CDI

I'm try to understand how to manage scheduled tasks in my project with Jax-RS and CDI.
With Spring I was easily able to achive that with ThreadPoolTaskScheduler or #Scheduled annotation and I'm trying to replicate both ways without success.
First of all, I'm using Wildfly 14 and this seems to cause some issues because I've tryied to inject with #Resource both ManagedScheduledExecutorService and TimerService but Wildfly throws exception of missing dependencies (but the Admin guide didn't help me about that).
Instead of inject resources I've tryied to use a singleton object like this:
#Singleton
public class CacheManager {
private final static Logger log = LogManager.getLogger();
public CacheManager() {
log.error("######## Init" + LocalTime.now());
}
#Schedule(hour = "*", minute = "*", second = "*/1")
private void timeout() {
log.error("######## " + LocalTime.now());
}
}
But the method is never called.
So I'm not understanding what I'm missing. Maybe I have wrongly configured the project so this is my pom.xml dependencies:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.10.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.12.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.12.Final</version>
<scope>provided</scope>
</dependency>
<!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in JBoss WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
<version>2.2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
This is my beans.xml
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="annotated">
</beans>
I am using Java 8.
EDIT: the CacheManager is instantiated in the JAX-WS Application
#ApplicationScoped
#ApplicationPath("/rest")
public class JaxRsActivator extends Application {
private static final Logger logger = LogManager.getLogger();
private Set<Object> singletons = new HashSet<Object>();
private HashSet<Class<?>> classes = new HashSet<Class<?>>();
public JaxRsActivator() {
singletons.add(new CorsFilter());
singletons.add(new CacheManager());
}
#Override
public Set<Object> getSingletons() {
return singletons;
}
#Override
public HashSet<Class<?>> getClasses(){
return classes;
}
}
I've found the solutions: #Singleton must be javax.ejb.Singleton and not javax.inject.Singleton.

Javax UriBuilder error [duplicate]

This question already has answers here:
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri
(8 answers)
Closed 3 years ago.
I am trying to build a REST webservice using an asynchronous response.
I have looked around this error on the web, however, none of the solutions have worked for me. I am not sure on how to go about it.
This is the code for the REST service, it has AsyncResponse, and #Suspended which are taken from jar file specified in the pom.xml, which I will provide below. The problem is, on deploying the war, I get an exception:
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs
My class is as follows:
package com.crudapp;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.annotation.Generated;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
//import javax.ws.rs.core.UriBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.google.gson.Gson;
import com.mysql.jdbc.StringUtils;
import dao.User;
import dao.UserDAO;
import dao.UserDAOImpl;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
#Path("/crudpath")
public class EntityResource {
private final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring.xml");
UserDAO userdao = null;
private final int numOfThreads = 10;
private final ExecutorService executorService = Executors.newFixedThreadPool(numOfThreads);
// userdao.getUsers("118");
//ctx.close();
#GET
#Produces("application/json")
public Response getTupleFromDBasJSON(#QueryParam("param1") String userid, #Suspended final AsyncResponse asyncresponse ){
if(StringUtils.isNullOrEmpty(userid))
throw new ServiceException("Userid passed to the REST service /crudpath is null or empty");
userdao = (userdao==null)?
ctx.getBean("userDAO", UserDAOImpl.class)
: userdao;
Gson gson = new Gson();
Future<List<User>> futures = executorService.submit(new DAOTaskHandlerThread(userid));
List <User> users = new ArrayList<User>();
if(futures.isDone())
{
try{
users = futures.get();
if(users!= null)
return Response.status(200).entity( gson.toJson(users).toString()).build();
}
catch(Exception ex)
{
throw new ServiceException(ex);
}
}
return Response.status(200).entity(new ArrayList<User>().toString()).build();
/*// crrate a new thread.. call the DAO .. returns the result from here.
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", "value");
return Response.status(200).entity( jsonObject.toString()).build();*/
}
private class DAOTaskHandlerThread implements Callable<List<User>>{
//private UserDAO userDAO;
private String userid;
private DAOTaskHandlerThread(//UserDAO userDAO,
String useridpassed){
///this.userDAO= userDAO;
userid= useridpassed;
}
#Override
public List<User> call() throws Exception {
// TODO Auto-generated method stub
return userdao.getUsers(userid);
}
}
}
My pom.xml file for maven is as follow:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RESTJerseyExample</groupId>
<artifactId>RESTJerseyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- spring framework just added -->
<properties>
<java-version>1.7</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- spring framework just added ends here -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>
<!-- used for httpclient library -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.2</version>
</dependency>
<!-- for async response -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m12</version>
</dependency>
</dependencies>
</project>
AbstractMethodError are thrown when an application tries to call an abstract method.
uri is an abstract method in UriBuilder, so you need an implementation of this. This method (with String parameter) is from version 2.0 of JAX-RS specification.
You're trying to use JAX-RS 2.0 with Jersey 1.*. Instead, you need to use Jersey 2.* that implements JAX-RS 2.0 and contains an implementation to uri method.
In your pom.xml you may remove these dependencies:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m12</version>
</dependency>
And use these dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
Using this, uri method is implemented in JerseyUriBuilder class from jersey-common.
EDIT:
You need to change, in your web.xml, servlet com.sun.jersey.spi.container.servlet.ServletContainer to org.glassfish.jersey.servlet.ServletContainer and init-param from com.sun.jersey.config.property.packages to jersey.config.server.provider.packages
I would like to add one answer to this post. I faced a similar problem today and found the root cause to be another dependent jar which was Internally using an older version of Jersey/JAX-RS.
My POM before fix was:
<jersey.version>2.17</jersey.version>
...
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.ci.wrapper</groupId>
<artifactId>client-wrapper</artifactId>
<version>${clients-wrapper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.api.commons</groupId>
<artifactId>transferobjects</artifactId>
<version>3.0.2</version>
</dependency>
The problem was with "com.ci.wrapper" and "com.api.commons".
They inturn included 2 different JAR's of BraveJersey and org.apache.cxf.cxf-rt-frontend-jaxrs (2.5.1) which were using Jersey and JAX-RS 1.X versions.
After excluding the nested jar's and adding the newer version's of BraveJersey2/org.apache.cxf.cxf-rt-frontend-jaxrs(3.1.5) it got resolved.
<dependency>
<groupId>com.api.commons</groupId>
<artifactId>transferobjects</artifactId>
<version>3.0.2</version>
<exclusions>
<exclusion>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<groupId>org.apache.cxf</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.ci.wrapper</groupId>
<artifactId>client-wrapper</artifactId>
<version>${clients-wrapper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<artifactId>brave-jersey</artifactId>
<groupId>com.github.kristofa</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.kristofa</groupId>
<artifactId>brave-jersey2</artifactId>
<version>2.4.2</version>
</dependency>
In case you're facing a similar issue, please check if the project's or jar's included could be using an incompatible version of Jersey/Jax-RS.
In my case it's combination of both cxf-rt-frontend-jaxrs and httpclint jar needed to be removed to resolve the issue. Both of these jars have the class javax.ws.rs.core.UriBuilder, the multiple version of this class caused the issue.
My pom had a transitive dependency on both these jars, after removing it worked.
enter code here
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
I have faced this problem when I was trying to use a library (custom built) in one of my project.
So the problem was happening due to mismatch in the com.sun.jersey dependencies. My project was using jersey version 2.15 whereas the custom library was giving me com.sun.jersey transitively of version 1.17.
So how to find such problems.
Use gradle dependencies task to find out the dependencies (it gives nested level results which means all the transitive dependencies will also be shown)
Once you identify the problem causing dependencies. Exclude them while adding the required dependencies in the project.
For e.g.
httpRestClient is name of my custom library which I wanted to use in my project.
So here is how I have added the dependency and at the same time excluded the conflicting dependencies of group 'com.sun.jersey'
compile(httpRestClient) {
exclude group: 'com.sun.jersey'
}
This way you can use whatever library and exclude the conflicting libraries.
Thanks.
In our case culprit was this dependency
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-common</artifactId>
<version>1.0-incubating</version>
</dependency>

wildfly swarm: lookup ejb remote interface

I have generated two simple wildfly swarm projects. First has EJB facade with Remote interface, second should lookup it and send message. So second should be as client.
I am used
Wildfly swarm version 2017.9.4
My EJB facade lookup paths:
java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:app/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:module/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:jboss/exported/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:global/ejb-one/PingFacade
java:app/ejb-one/PingFacade
java:module/PingFacade
My client :
public static void main(String[] args) {
BackendConnectionManager manager = new BackendConnectionManager();
try {
manager.getPingFacadeRemote().savePingMessage("halloooooo");
} catch (NamingException ex) {
Logger.getLogger(BackendConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
public PingFacadeRemote getPingFacadeRemote() throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
//jndiProperties.put(Context.PROVIDER_URL,"http://localhost:8080");
final Context context = new InitialContext(jndiProperties);
return (PingFacadeRemote) context
.lookup("java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote");
}
Added client dependencies to pom.xml
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>ejb-remote</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-naming</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.remoting3</groupId>
<artifactId>jboss-remoting</artifactId>
<version>3.3.3.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.sasl</groupId>
<artifactId>jboss-sasl</artifactId>
<scope>runtime</scope>
<version>1.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>runtime</scope>
</dependency>
I do not what is whole dependencies for client and always has
javax.naming.CommunicationException: WFNAM00018: Failed to connect to remote host [Root exception is org.jboss.remoting3.ServiceOpenException: Unknown service name]
at org.wildfly.naming.client.remote.RemoteContext.getRemoteTransport(RemoteContext.java:80)
at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:106)
at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:150)
at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:104)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:150)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at io.project.ejbtwo.rest.BackendConnectionManager.getPingFacadeRemote(BackendConnectionManager.java:57)
at io.project.ejbtwo.rest.BackendConnectionManager.main(BackendConnectionManager.java:43)
Caused by: org.jboss.remoting3.ServiceOpenException: Unknown service name
Also how to solve problem with passing security credentials in client lookup?
Projects by itself here
https://drive.google.com/open?id=0B45Md1_c5-gGQ0p3Q2pURUxOY00
In BackendConnectionManager.java, line 57, you are trying to look up the service java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote, but it seems to not exist. PingFacadeRemote interface is a part of ejb-core module. Yes, it is true that you implement it in ejb-one module, but you registered the interface as a remote (#Remote(PingFacadeRemote.class), in PingFacade.java).
You might try to replace it with java:global/ejb-core/PingFacade!io.project.core.interfaces.PingFacadeRemote.

how to ask sun jersey to return http code other than 200

#GET
#Path("/rest/balancequery")
#Produces(MediaType.APPLICATION_JSON)
public XXXPojo balanceQuery(#Context UriInfo ui) {
XXXPojo p = new XXXPojo();
Boolean fail = this.checkAuthority(ui);
if(fail) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
else {
p = getPojo();
}
return p
}
WebAppliactionException is described as none-detectable exception, and should return 403. However, the console output does show the trace of exception (I think this means it is detectable), and the client receives 200 as code. It is also mentioned in answer "should not return entity". It is impossible for a jersey just return 403 but not a bean when nothing goes wrong. I cannot use glassfish jersey. jdk 1.7 thanks.
<!-- jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>8.1.16.v20140903</version>
</dependency>

Using Camel Bean validator Component

I am getting an exception while using Camel Bean Validator. The exception is No component found with scheme: bean-validator
And i have these dependencies in my POM
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
<scope>provided</scope>
</dependency>
And i am using Bean Validator component as below
from("direct:XXX").process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
Car car = new Car();
//car.setVehicleId(1);
car.setName("Swift");
car.setCompany("Maruti");
exchange.getIn().setBody(car);
}
}).to("bean-validator://x").process(new Processor() {
#Override
public void process(Exchange arg0) throws Exception {
LOG.debug("Bean Validation is Success");
}
});
But when i am deploying the generated war into the Wildfly, am getting the exception No component found with scheme: bean-validator. To my surprise the code is working fine in standalone application.
Your help is greatly appreciated.
The issue is that you define the scope as provided, which means the JAR is supposely already part of the server. You most often only use provided scope for API JARs such as the servlet api, etc.
So change this
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
<scope>provided</scope>
</dependency>
To
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
</dependency>

Categories

Resources