My end goal is simple. I am building a website that has three components: a mobile interface, an admin web interface, and a web user interface. I plan to put each of these modules into separate WAR files and, together with an EJB module & possibly a common library module, bundle them all into a EAR for deployment on JBoss AS 7.1.
But first things first, can I deploy a very simple WAR file and get it to work - NO!
My war file has the following structure:
project-mobile.war:
META-INF/MANIFEST.MF
WEB-INF/jboss-web.xml
WEB-INF/classes/org/dobbo/project/mobile/Accounts.class
index.html
The manifest.mf file as the following content:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.0
Created-By: 1.6.0_18-b18 (Sun Microsystems Inc.)
Built-By: steve
The jboss-web.xml file's content are:
<?xml version="1.0"?>
<jboss-web>
<context-root>/mobile</context-root>
</jboss-web>
The Accounts.java file was based on the Library.java example from https://docs.jboss.org/author/display/AS71/Java+API+for+RESTful+Web+Services+(JAX-RS)
I did make some changes, added the Application subclassing and the AppicationPath annotation as this got me a little further in getting the deployment to work.
package org.dobbo.<project>.mobile;
import javax.ws.rs.*;
import javax.ws.rs.core.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#ApplicationPath("/accounts")
#Consumes({"application/xml"})
#Produces({"application/xml"})
public class Accounts
extends Application {
...
#GET
#Path("/list")
public Collection<UUID> getAccounts() {
Collection<UUID> list = uuids.values();
log.info("getAccounts: " + list);
return list;
}
...
}
So far so good.
When I deploy I get the following logged to the JBoss console (timestamp & log level INFO removed):
[org.jboss.as.repository] (management-handler-thread - 12) JBAS014900: Content added at location /home/jboss/jboss-7.1.1/standalone/data/content/11/e8cdaea9dfa4e984ada3e22b0c890970f0ba75/content
[org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment sokoban-mobile.war in 60ms
[org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "project-mobile.war"
[org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /mobile
[org.jboss.as.server] (management-handler-thread - 12) JBAS018565: Replaced deployment "project-mobile.war" with deployment "project-mobile.war"
So far all seems well. But when I point my browser at jboss-server:8080/mobile/accounts/list I get a:
HTTP Status 404 - Could not find resource for relative : /list of full path: http://jboss-server:8080/mobile/accounts/list
type Status report
message Could not find resource for relative : /list of full path: http://jboss-server:8080/mobile/accounts/list
description The requested resource (Could not find resource for relative : /list of full path: http://jboss-server:8080/mobile/accounts/list) is not available.
However, something is working because pointing the broswer at jboss-server:8080/mobile/ successfully returns the index.html file also included in the WAR file.
It's probably just a simple configuration error on my part, but I can't work it out for the life of me. Many thanks to all that take the trouble to read this issue and even more thanks for posting any ideas you have.
Steve
The logs shows that no REST resource is loaded.
The resource is missing the #Path annotation.
You need on Application class with the #ApplicationPath annotation (The class will be empty).
Then you need to add the #Path annotation to your resource class (Accounts for your case)
So you will have:
#ApplicationPath("/")
public class AccountApp
extends Application {}
And:
#Path("accounts")
#Consumes({"application/xml"})
#Produces({"application/xml"})
public class Accounts{
...
#GET
#Path("/list")
public Collection<UUID> getAccounts() {
Collection<UUID> list = uuids.values();
log.info("getAccounts: " + list);
return list;
}
...
}
Related
I want to create a simple JAX-RS REST Service for Wildfly 10. My issue is that my REST Service is not found. Result in browser is 404 not found. I am not sure what exactly the issue is. I get no error or exception in wildfly log file. I am using eclipse neon 3 and wildfly 10. My project is using JAX-RS not resteasy.
Here my project setup and code:
I have created a Dynamic Web Project in Eclipse.
I have set JAX-RS(REST Service) support in the project facets. JAX-RS version is 2.0 (also tried with version 1.1)
I have create a subclass which extends Application (javax.ws.rs.core.Application)
I added the annotation #ApplicationPath("/yoshi-rest") to the class which extends Application.
I have created a class which contains my rest service method. The class itself has the #Path("/StatusService") annotation.
The affected method has the annotations #Get and #Path("/getStatus").
Due to I have the subclass of Application I didn't set the servlet mapping in web.xml.
Here the code:
Subclass of Application(RESTConfig):
#ApplicationPath("/yoshi-rest")
public class RESTConfig extends Application {
}
REST Service class(StatusService):
#Path("/StatusService")
public class StatusService {
#Get
#Path("/getStatus")
public String getStatus() {
return "Yoshi is up and running";
}
}
I can see during startup of wildfly that the subclass RESTConfig is deployed:
11:09:23,777 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 61) RESTEASY002225: Deploying javax.ws.rs.core.Application: class XXXX.yoshi.rest.services.RESTConfig
If I call the rest service url (http://localhost:8080/yoshi-rest/StatusService/getStatus) in browser, I get a '404 - Not found' as result.
Any idea what I am doing wrong?
You need to register service to connect to your RESTConfig:
#ApplicationPath("/yoshi-rest")
public class RESTConfig extends ResourceConfig {
public RESTConfig() {
register(StatusService.class);
}
See more on ResourceConfig configuration options
Standard JAX-RS uses an Application as its configuration class. ResourceConfig extends Application.
Putting the project name in the url solved the issue.
Thanks for help.
I'm trying to deploy a very simple application on Openshift. It's an EAR project with a single WAR and EJB module. Inside the WAR there's a REST service that calls an EJB defined in EJB module. Locally and on Openshift I'm using Wildfly 9.0.0 CR2 and PostgreSQL 9.2. When deploying locally everything works fine. When the same code is deployed on Openshift I'm getting following errors in logs:
2015-06-28 18:23:04,574 WARN [org.jboss.as.clustering.jgroups] (MSC service thread 1-1) WFLYCLJG0006: property bind_addr for protocol org.jgroups.protocols.TCP attempting to override socket binding value 127.12.77.1 : property value 127.12.77.1 will be ignored
2015-06-28 18:23:04,574 WARN [org.jboss.as.clustering.jgroups] (MSC service thread 1-1) WFLYCLJG0006: property bind_port for protocol org.jgroups.protocols.TCP attempting to override socket binding value 7600 : property value 7600 will be ignored
2015-06-28 18:23:06,252 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 70) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'cooking.ear/cooking-ejb-1.0-SNAPSHOT.jar#cookingPU'
2015-06-28 18:23:08,165 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.jgroups.channel.ee: org.jboss.msc.service.StartException in service jboss.jgroups.channel.ee: java.security.PrivilegedActionException: java.net.BindException: [TCP] /127.12.77.1 is not a valid address on any local network interface
at org.wildfly.clustering.jgroups.spi.service.ChannelBuilder.start(ChannelBuilder.java:79)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.security.PrivilegedActionException: java.net.BindException: [TCP] /127.12.77.1 is not a valid address on any local network interface
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:638)
at org.jboss.as.clustering.jgroups.JChannelFactory.createChannel(JChannelFactory.java:99)
at org.wildfly.clustering.jgroups.spi.service.ChannelBuilder.start(ChannelBuilder.java:77)
... 5 more
Caused by: java.net.BindException: [TCP] /127.12.77.1 is not a valid address on any local network interface
at org.jgroups.util.Util.checkIfValidAddress(Util.java:3480)
at org.jgroups.stack.Configurator.ensureValidBindAddresses(Configurator.java:902)
at org.jgroups.stack.Configurator.setupProtocolStack(Configurator.java:118)
at org.jgroups.stack.Configurator.setupProtocolStack(Configurator.java:57)
at org.jgroups.stack.ProtocolStack.setup(ProtocolStack.java:477)
at org.jgroups.JChannel.init(JChannel.java:854)
at org.jgroups.JChannel.<init>(JChannel.java:159)
at org.jboss.as.clustering.jgroups.JChannelFactory$1.run(JChannelFactory.java:96)
at org.jboss.as.clustering.jgroups.JChannelFactory$1.run(JChannelFactory.java:93)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:634)
... 7 more
The address mentioned - 127.12.77.1 is $OPENSHIFT_WILDFLY_IP.
I have no idea what is causing this issue. First I thought it's a database connectivity issue because it happens when 2nd phase of starting persistence unit happens. I connected to DB on Openshift and saw that it was created successfully so maybe that's not it, but here's the persistence.xml I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="cookingPU">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/PostgreSQLDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" />
</properties>
</persistence-unit>
</persistence>
The datasource used is the default one. I didn't change anything in standalone.xml.
Another thing I noticed is that the deploy problem happens when I add any EJB to the project.
This is a simple one I tried to use:
#Stateless
public class AnyEjb {
public String hello() {
return "Hi there!";
}
}
This is defined in EJB module. Then in web module I have this class calling it:
#Path("anything")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class AnyEndpoint {
#EJB
private AnyEjb anyEjb;
#GET
public String sayHi() {
return anyEjb.hello();
}
}
I'm not sure if and how it can be connected with this BindException.
I've tried running this application locally with both standalone and standalone-full-ha profile and it works in both cases. I just feel it has to be some issue with Openshift configuration but I have no idea where to look anymore. I'm very new to Openshift and Java EE. Please point me in a right direction. Any help will be much appreciated.
Might be https://issues.jboss.org/browse/JGRP-1928. Talk to Rado Husar to see how to resolve this.
It looks like the problem is (as #Bela Ban suggested) connected with the version of JGroups shipped with WildFly 9.0.0CR2. I will be waiting for the fix coming with the Final version of WildFly.
Meanwhile as a workaround to be able to deploy an application on WildFly 9.0.0CR2 on Openshift, I decided to disable clustering capabilities for my server.
In standalone.xml available in .openshift I have removed org.jboss.as.clustering.jgroups module and changed infinispan cache settings from distributed to local.
I have been basing on this solution (for WildFly 8): https://gist.github.com/fjuma/3df7f64fbaebd5506ef5#file-standalone-xml
But I had to modify it so that it works on Wildfly 9. Full standalone.xml that's been working for me is available here for reference http://pastebin.com/aANkPUWk
I try to build a Java EE 7 app with Rest services and EJB injection.
I created a multi module maven project which I deploy on Glassfish 4. My final EAR contain a JAR with my EJBs, with for example my Rest services definitions :
#Stateless
#Path("countries")
public class CountryRest {
//#EJB
//StockService stockService;
#GET
public Response getCountries() {
//stockService.getAll(); --> firing a NPE, stockService is Null
return Response.ok().build();
}
}
#Stateless
#Remote(IStockService.class)
public class StockService implements IStockService {
#Override
public List<Stock> getAllStock() {
return new ArrayList<Stock>();
}
}
When I deploy my app, I see the following logs which seems ok. Even if I wonder why it defines "java:global" JNDI since by default #Stateless EJB is #Local :
Portable JNDI names for EJB CountryRest: [java:global/GeoData-ear/GeoData-ejb-1.0-SNAPSHOT/CountryRest, java:global/GeoData-ear/GeoData-ejb-1.0-SNAPSHOT/CountryRest!com.tomahim.geodata.rest.CountryRest]
Portable JNDI names for EJB StockService: [java:global/GeoData-ear/GeoData-ejb-1.0-SNAPSHOT/StockService, java:global/GeoData-ear/GeoData-ejb-1.0-SNAPSHOT/StockService!com.tomahim.geodata.services.IStockService]
Then when I'm doing a GET on /rest/countries, the status is 200 as expected but I have a NameNotFoundException / NamingException :
Avertissement: An instance of EJB class, com.tomahim.geodata.rest.CountryRest, could not be looked up using simple form name. Attempting to look up using the fully-qualified form name.
javax.naming.NamingException: Lookup failed for 'java:module/CountryRest' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound to name java:module/CountryRest]
I see that the lookup for "java:module/ContryRest" is not matching "java:global/.../CountryRest" but what am I doing wrong ?
EDIT 1 : I was able to make #Ejb injection work by placing my Rest definitions ans EJBs in my webapp maven module deploy as a WAR. So it seems that the problem occur only when I deploy my EJB in a JAR. Any idea ? What could be the difference between JAR and WAR deployment ?
It is required by the JAX-RS spec that all REST endpoints must live within your WAR file. Do you really need an EAR file?
I am running a javaee web application from the ground up using wildfly and simply want to expose some RESTful web services. My wildfly application server is running with the defaults it shipped with and I am not using any database entities although I do have a persisitance.xml to make wildfly happy. My application deploys fine as indicated by log messages below.
12:50:38,585 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-5) Deploying javax.ws.rs.core.Application: class org.netbeans.rest.application.config.ApplicationConfig
12:50:38,585 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-5) Adding class resource os.acquisition.acq.Acquisition from Application class org.netbeans.rest.application.config.ApplicationConfig
12:50:38,588 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017534: Registered web context: /acq-1.0
12:50:38,712 INFO [org.jboss.as.server] (management-handler-thread - 29) JBAS018565: Replaced deployment "acq-1.0.war" with deployment "acq-1.0.war"
My issue comes when trying to call the GET request below. (always returns 404)
#Path("/acq")
public class Acquisition {
#GET
#Path("ping")
public Response ping(#Context HttpServletRequest req) {
return Response.ok().entity(GenericResponse.OK).build();
}
}
I have also used the standard IDE generated ApplicationConfig.java which has this service as one of its resources.
#javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources);
return resources;
}
/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(os.acquisition.acq.Acquisition.class);
}
}
I have been using a short curl script to call the rest service and have tried every possible combination of #Path params and URL configurations to no avail.
#!/bin/bash
curl -v -X GET http://localhost:8080/acq-1.0/acq/ping
Additionally, when curl -v -X GET http://localhost:8080/acq-1.0/ is called it returns to me the index.html page as I expect.
It seems that I am missing something fundimental here. Any ideas?
#ApplicationPath's value is appended to the resource URI before the individual resource paths. Looks like your curl request is missing the "webresources" portion.
As the title say, I created a class in the war layer that is annotated with #Picketlink. Note that I have an ear deployment structure (ejb, war).
The custom authenticator:
#PicketLink
public class PicketlinkAuthenticator extends BaseAuthenticator { }
If I put that class in the ejb layer, the authentication is ok but when I put it to the war layer it seems like it's not found by the project as it's throwing:
20:49:46,027 INFO [org.picketlink.common] (default task-10) Using logger implementation: org.picketlink.common.DefaultPicketLinkLogger
20:49:46,043 INFO [org.picketlink.idm] (default task-10) PLIDM001000: Bootstrapping PicketLink Identity Manager
20:49:46,068 WARN [org.picketlink.idm] (default task-10) PLIDM001101: Working directory [\tmp\pl-idm] is marked to be always created. All your existing data will be lost.
20:49:46,111 INFO [org.picketlink.idm] (default task-10) PLIDM001100: Using working directory [\tmp\pl-idm].
20:49:46,127 DEBUG [org.picketlink.idm] (default task-10) No partitions to load from \tmp\pl-idm\pl-idm-partitions.db
20:49:46,152 DEBUG [org.picketlink.idm] (default task-10) Initializing Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436] with id [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
20:49:46,153 DEBUG [org.picketlink.idm] (default task-10) Loaded Agents for Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
20:49:46,154 DEBUG [org.picketlink.idm] (default task-10) Loaded Credentials for Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
Why not just move the authenticator to the ejb side?
->Because I'm throwing custom error like user expired, etc. I need jsf to post these error messages.
Why not move the picketlink dependency in the web layer?
->Because my account that extended the picketlink account is binded to my services.
As suggested here I already added the picketlink module in the war project:
https://docs.jboss.org/author/display/PLINK/JBoss+Modules
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<sub-deployment name="THE-WAR-MODULE-THAT-REQUIRES-PICKETLINK.war">
<dependencies>
<module name="org.picketlink" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Anyway around this? I just want to show some custom errors :-(
I was not able to solve this problem but I have a work-around solution and that is to move the picketlink module to the web layer and just pass the identity instance to the services that need it.
I have been missing around with the same problem as well for a while now (it's 2016 now ...). What seems to make it work is to add the following CDI annotations:
#PicketLink
#Name
#RequestScoped
public class PicketlinkAuthenticator extends BaseAuthenticator { }
I would have expected the core Authentication Manager to pick this up just based on the #PicketLink Annotation, but without the CDI Annotations, the custom Authenticator class is never even loaded. Maybe there is an other way that will require us to bootstrap PicketLink - but I could not find any references.