404 Error while deploying simple web-app in JBoss AS 6 and JBoss AS 7?
Asked Answered
C

1

0

I followed this blog for injecting EJB in REST layer.

Here is the code that I tried deploying in JBOSS AS 6 and 7 using Eclipse:

REST:

package com.example.rest;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Stateless
@Path("current")
public class ServiceFacade {

    @EJB
    ServiceImpl service;

    @GET
    public String getDate(){
        return service.getCurrentDate().toString();
    }

}


EJB:

import java.util.Date;

import javax.ejb.Stateless;

@Stateless
public class ServiceImpl {

    public Date getCurrentDate(){
        return new Date();
    }

}

@ApplicationPath("rest")
public class RestApplication extends Application {
}

pom.xml

<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>com.sample.rest</groupId>
  <artifactId>restejb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>simplet project to test ejb injection in rest</description>
  <dependencies>
  <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>1.0.0.Final</version>
      <packaging>war</packaging>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>
    </dependencies>
</project>

when I access http://localhost:8080/restejb/rest/current, I get 404 page NOT found error.

Here is the log from deployment to JBOSS AS 6:




  11:19:23,701 INFO  [AbstractJBossASServerBase] Server Configuration:

    JBOSS_HOME URL: file:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/
    Bootstrap: $JBOSS_HOME/server/default/conf/bootstrap.xml
    Common Base: $JBOSS_HOME/common/
    Common Library: $JBOSS_HOME/common/lib/
    Server Name: default
    Server Base: $JBOSS_HOME/server/
    Server Library: $JBOSS_HOME/server/default/lib/
    Server Config: $JBOSS_HOME/server/default/conf/
    Server Home: $JBOSS_HOME/server/default/
    Server Data: $JBOSS_HOME/server/default/data/
    Server Log: $JBOSS_HOME/server/default/log/
    Server Temp: $JBOSS_HOME/server/default/tmp/

11:19:23,706 INFO  [AbstractServer] Starting: JBossAS [6.1.0.Final "Neo"]
11:19:27,412 INFO  [ServerInfo] Java version: 1.7.0_71,Oracle Corporation
11:19:27,412 INFO  [ServerInfo] Java Runtime: Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
11:19:27,413 INFO  [ServerInfo] Java VM: Java HotSpot(TM) 64-Bit Server VM 24.71-b01,Oracle Corporation
11:19:27,413 INFO  [ServerInfo] OS-System: Mac OS X 10.9.5,x86_64
11:19:27,414 INFO  [ServerInfo] VM arguments: -Dprogram.name=JBossTools: JBoss AS 6.x -Xms256m -Xmx768m -XX:MaxPermSize=256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/lib/endorsed -Djava.library.path=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/native -Dlogging.configuration=file:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/logging.properties -Dfile.encoding=UTF-8 
11:19:27,483 INFO  [JMXKernel] Legacy JMX core initialized
11:19:35,849 INFO  [AbstractServerConfig] JBoss Web Services - Stack CXF Server 3.4.1.GA
11:19:36,679 INFO  [JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0]
11:19:47,865 WARNING [FileConfigurationParser] AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
11:19:48,389 INFO  [JMXConnector] starting JMXConnector on host localhost:1090
11:19:48,609 INFO  [MailService] Mail Service bound to java:/Mail
11:19:49,990 INFO  [HornetQServerImpl] live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/journal,bindingsDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/bindings,largeMessagesDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/largemessages,pagingDirectory=/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/data/hornetq/paging)
11:19:49,992 INFO  [HornetQServerImpl] Waiting to obtain live lock
11:19:50,105 INFO  [JournalStorageManager] Using NIO Journal
11:19:50,140 WARNING [HornetQServerImpl] Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.
11:19:50,468 INFO  [FileLockNodeManager] Waiting to obtain live lock
11:19:50,469 INFO  [FileLockNodeManager] Live Server Obtained live lock
11:19:51,283 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5445 for CORE protocol
11:19:51,287 INFO  [NettyAcceptor] Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5455 for CORE protocol
11:19:51,290 INFO  [HornetQServerImpl] Server is now live
11:19:51,291 INFO  [HornetQServerImpl] HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [251821f6-c6bb-11e4-9df3-60334b2115c1] started
11:19:51,386 INFO  [WebService] Using RMI server codebase: http://localhost:8083/
11:19:51,699 INFO  [jbossatx] ARJUNA-32010 JBossTS Recovery Service (tag: JBOSSTS_4_14_0_Final) - JBoss Inc.
11:19:51,711 INFO  [arjuna] ARJUNA-12324 Start RecoveryActivators
11:19:51,745 INFO  [arjuna] ARJUNA-12296 ExpiredEntryMonitor running at Tue, 10 Mar 2015 11:19:51
11:19:51,903 INFO  [arjuna] ARJUNA-12310 Recovery manager listening on endpoint 127.0.0.1:4712
11:19:51,904 INFO  [arjuna] ARJUNA-12344 RecoveryManagerImple is ready on port 4712
11:19:51,905 INFO  [jbossatx] ARJUNA-32013 Starting transaction recovery manager
11:19:51,933 INFO  [arjuna] ARJUNA-12163 Starting service com.arjuna.ats.arjuna.recovery.ActionStatusService on port 4713
11:19:51,934 INFO  [arjuna] ARJUNA-12337 TransactionStatusManagerItem host: 127.0.0.1 port: 4713
11:19:51,937 INFO  [arjuna] ARJUNA-12170 TransactionStatusManager started on port 4713 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
11:19:52,007 INFO  [jbossatx] ARJUNA-32017 JBossTS Transaction Service (JTA version - tag: JBOSSTS_4_14_0_Final) - JBoss Inc.
11:19:52,103 INFO  [arjuna] ARJUNA-12202 registering bean jboss.jta:type=ObjectStore.
11:19:52,481 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/bin/native
11:19:52,764 INFO  [TomcatDeployment] deploy, ctxPath=/invoker
11:19:53,207 INFO  [ModClusterService] Initializing mod_cluster 1.1.0.Final
11:19:53,286 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jboss-local-jdbc.rar/META-INF/ra.xml
11:19:53,308 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jboss-xa-jdbc.rar/META-INF/ra.xml
11:19:53,322 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/jms-ra.rar/META-INF/ra.xml
11:19:53,347 INFO  [HornetQResourceAdapter] HornetQ resource adaptor started
11:19:53,359 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/mail-ra.rar/META-INF/ra.xml
11:19:53,382 INFO  [RARDeployment] Required license terms exist, view vfs:/Users/sridhar1982AQ/Documents/EE7_servers/jboss-6.1.0.Final/server/default/deploy/quartz-ra.rar/META-INF/ra.xml
11:19:53,522 INFO  [SimpleThreadPool] Job execution threads will use class loader of thread: Thread-2
11:19:53,574 INFO  [SchedulerSignalerImpl] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
11:19:53,575 INFO  [QuartzScheduler] Quartz Scheduler v.1.8.3 created.
11:19:53,579 INFO  [RAMJobStore] RAMJobStore initialized.
11:19:53,583 INFO  [QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v1.8.3) 'JBossQuartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

11:19:53,583 INFO  [StdSchedulerFactory] Quartz scheduler 'JBossQuartzScheduler' initialized from an externally opened InputStream.
11:19:53,583 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.8.3
11:19:53,584 INFO  [QuartzScheduler] Scheduler JBossQuartzScheduler_$_NON_CLUSTERED started.
11:19:54,133 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'
11:19:54,533 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
11:19:54,715 INFO  [xnio] XNIO Version 2.1.0.CR2
11:19:54,733 INFO  [nio] XNIO NIO Implementation Version 2.1.0.CR2
11:19:55,100 INFO  [remoting] JBoss Remoting version 3.1.0.Beta2
11:19:55,279 INFO  [TomcatDeployment] deploy, ctxPath=/
11:19:55,417 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.ExpiryQueue
11:19:55,462 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.DLQ
11:19:55,508 INFO  [service] Removing bootstrap log handlers
11:19:55,616 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080
11:19:55,624 INFO  [org.apache.coyote.ajp.AjpProtocol] Starting Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009
11:19:55,625 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.1.0.Final "Neo"] Started in 31s:909ms
11:19:56,100 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/restejb
Crouton answered 10/3, 2015 at 0:42 Comment(7)
Go and write Adam Bien an email, usually he answers to direct questions concerning his examples.Sosanna
Seems like there is a lack of log in your post, the exception you post is just a WARNING (depending on how you configure your logging it even won't appear). Should it be possible if you paste the complete log (here or in a gisthub, pastebin, etc ...)Porush
@alphamikevictor: I updated with error messgeCrouton
Seems like you have in your deployment directory more than one app with the same name: like ServiceImpl.war and ServiceImpl.earPorush
@alphamikevictor: I fixed that and updated the log above. Now I don't get any ERROR but WARN and still it is not working.Crouton
Could you please define what is not working? What do you do, what results are you getting ... At least now the application starts, which is a first step.Porush
@alphamikevictor: I have updated the question and log above. Basically when I access http://localhost:8080/restejb/rest/current, i get 404 errorCrouton
P
1

I am checking one of my projects using rest and in the annotation I use a slash / before the resource name both in @ApplicationPath("/rest") as in the rest service `@Path("/current"), so your EJB seems like must be something like:

@Stateless
@Path("/current")
public class ServiceImpl {

    @GET
    public Date getCurrentDate(){
        return new Date();
    }

}

And your activator class something like:

@ApplicationPath("/rest")
    public class RestApplication extends Application {
}
Porush answered 10/3, 2015 at 22:45 Comment(7)
did you try this? I tried what you suggested. but i get javax.naming.NameNotFoundException: local not bound ERRORCrouton
I don't have an EJB which at the same time is a rest resource, also there are some missing lines on your code so it's a bit hard to imagine where the Exception is launched.Porush
my code is full above. Nothing more than what I have pasted aboveCrouton
Probably you need to remove the @Stateless annotation of your REST. Let me create an small app with this ...Porush
Take a look at this small GistHub which implementes your case: gist.github.com/alphamikevictor/3b15c131e035f92daa8bPorush
I dont see your pom.xml and what is the version of JBOss you are running?Crouton
I ran it on Jboss 6.3.0, these were just file example not the whole project :)Porush

© 2022 - 2024 — McMap. All rights reserved.