Simple Glassfish RESTful service in eclipse throws exception - java

This should be easy, but it's been costing me tons of time. I basically can't get a RESTful web service running under eclipse. I'm sure I'm missing something stupid, but resources seem to be a bit scattered and nothing covers the recent 4.0/EE 7 release.
I have a clean install of Eclipse Kepler (4.3). I try and set up a basic RESTful app using the following steps.
I have Java EE 7 installed
I open eclipse, point it to a fresh workspace and create a new 'Dynamic Web Application'.
Project name doesn't particularly matter, a new Target Runtime is created by downloading the Glassfish extension (New Runtime->Download additional server adapters->Glassfish). This requires restarting eclipse - so just repeat the previous, but select a Glassfish 4.0 runtime after clicking 'New Runtime'. Web Module is 3.1, everything else is default. I click 'Finish' to create my new project.
I then right click and open project properties, then 'Project Facets'. I check of JAX-RS (REST Web Services). Then click 'Further Configuration required...". I then select 'Disable Library Configuration' from the drop down. The fields receive the following values:
JAX-RS servlet name: JAX-RS Servlet
JAX-RS servlet class name: org.glassfish.jersey.servlet.ServletContainer
URL mapping patterns: /jaxrs/*
I then click OK to close all the windows.
Now adding a New->'RESTful Web Service from Pattern' creates a new class, that doesn't seem to ever get picked up by glassfish on deployment. My understanding is that it should auto scan and pick up things with an #path. It doesn't seem to. If I finagle things enough I can seem to access the application.wadl - but doesn't show my resource.
If I go back into properties and take a look at my JAX-RS project facet, I'm presented with an error box saying some of my values are invalid.
In the workspace log I'm greeted with the following exception:
!ENTRY org.eclipse.jst.jee 4 0 2013-07-02 21:54:27.780
!MESSAGE org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp
!STACK 0
java.lang.ClassCastException: org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp
at org.eclipse.jst.ws.jaxrs.core.internal.project.facet.UpdateWebXMLForJ2EE.run(UpdateWebXMLForJ2EE.java:32)
at org.eclipse.jst.jee.model.internal.JEE5ModelProvider.modify(JEE5ModelProvider.java:255)
at org.eclipse.jst.jee.model.internal.Web25MergedModelProvider.modify(Web25MergedModelProvider.java:92)
at org.eclipse.jst.ws.jaxrs.core.internal.project.facet.JAXRSFacetInstallDelegate.createServletAndModifyWebXML(JAXRSFacetInstallDelegate.java:275)
at org.eclipse.jst.ws.jaxrs.core.internal.project.facet.JAXRSFacetInstallDelegate.execute(JAXRSFacetInstallDelegate.java:156)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.callDelegate(FacetedProject.java:1477)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.modifyInternal(FacetedProject.java:441)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.mergeChangesInternal(FacetedProject.java:1181)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.access$2(FacetedProject.java:1117)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject$5.run(FacetedProject.java:1099)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.mergeChanges(FacetedProject.java:1109)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy.commitChanges(FacetedProjectWorkingCopy.java:2020)
at org.eclipse.wst.common.project.facet.ui.internal.FacetsPropertyPage$4.run(FacetsPropertyPage.java:232)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.wst.common.project.facet.ui.internal.FacetsPropertyPage$5.run(FacetsPropertyPage.java:246)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Any insight would be so greatly appreciated.

Try running Eclipse with Java SE. The parts of Java EE that your project needs to compile against can come from Glassfish itself. You might also need to use #Path rather than #path since it matches to a type name and is case sensitive.

Related

Project doesnt deploy to localhost root but deploys to localhost/projecttitle

Alternative title: Unable to find [main.SearchServlet], mapping my servlet in Tomcat whilst using annotations
I'm trying to migrate my web application from java netbeans glassfish jdk 1.8 to eclipse tomcat jdk 1.7.
I keep getting a 405 then 404 error when I try to perform my POST by pressing a button on my loaded index jsp.
javax.naming.NameNotFoundException: Name [main.SearchServlet/annj] is not bound in this Context. Unable to find [main.SearchServlet].
I thought that setting a <context root>/</context root> in web.xml would fix this. It did move my loading page from localhost/animelist/index and localhost/animelist down one level to localhost/ and localhost/animelist however it did not fix my error.
As it stands, my project does not run at http://localhost:8080/ or http://localhost:8080/index.jsp . It DOES run at http://localhost:8080/animelist1/ and http://localhost:8080/animelist1/index.jsp
The project works fine in my netbeans setup so my question is what do i need to do for my servlets to be mapped properly in tomcat?
Someone said that " Likely the only problem you have is that the application deployment in your secondary Eclipse isn't working properly yet. As in: the servlet class file is not deployed to the server at all." I'm not sure how to go about fixing this (or googling for it).
I have my classes instanced with
#EJB
private AnnJAXB annj;
and servlet with
#WebServlet(name = "SearchServlet", urlPatterns = { "/search" })
and like i said it all works in netbeans setup.
so do i have to do something with tomcat config or application properties, since deployment should be done automatically? why isn't mainClass.SearchServlet being found?
thankyou for reading. i am near the end i feel . it has been 15 hours trying to deploy this to a host and it is exhausting.

Domino OSGI plugin - Couldn't find design note

I am trying to creata a Domino OSGI plugin which exposes a simple Hello World servlet.
To do this I created in eclipse a plugin project(with web.xml and the servlet in place) , a feature project containing this plugin and an updated site project.
After this I created an application in Domino designer using the 'Eclipse Update Site' as template (name RestDemoUpdateSite.nsf).
With this application open in Domino administrator, I successfully imported my eclipse update site.
Finally I copied RestDemoUpdateSite.nsf to the folder -
C:\Program Files\IBM\Domino\data and added the line OSGI_HTTP_DYNAMIC_BUNDLES=RestDemoUpdateSite.nsf in notes.ini.
The link http://<>/RestDemoUpdateSite.nsf opens fine
A GET request to http://<>/RestDemoUpdateSite.nsf/api/ gives the json response
{
"services":[
{
"name":"Data",
"enabled":false,
"version":"9.0.1",
"href":"\/RestDemoUpdateSite.nsf\/api\/data"
},
{
"name":"Calendar",
"enabled":false,
"version":"9.0.1",
"href":"\/RestDemoUpdateSite.nsf\/api\/calendar"
},
{
"name":"Core",
"enabled":true,
"version":"9.0.1",
"href":"\/RestDemoUpdateSite.nsf\/api\/core"
}
]
}
A GET request to my servlet http://<>/RestDemoUpdateSite.nsf/serviceapi/student gives the error
HTTP Web Server: Couldn't find design note - serviceapi/student [/RestDemoUpdateSite.nsf/serviceapi/student] Anonymous
Any suggestion or hints as to what might be going wrong would be of great help.
Thank you
The first step is to make sure your plugin is being loaded by the OSGi framework. Execute the following server console command:
tell http osgi ss {bundle.name}
For example, tell http osgi ss com.ibm.domino.services lists all the plugins matching the given name. The listing tells you whether a plugin is ACTIVE, RESOLVED, INSTALLED, etc.
Assuming your plugin is being loaded, the next step is to make sure you are defining your servlet correctly. You said you included a web.xml file, but OSGi servlets are typically defined in plugin.xml. They implement the org.eclipse.equinox.http.registry.servlets extension. You can find more details in these slides. See the section starting with "Creating, deploying & debugging a simple servlet".

JavaToWS Error while generating web service with CXF

I get the error when generating web service. I have a simple class that i want to create web service.
I am using CXF 2.7 and Tomcat 7 version.
org.apache.cxf.tools.common.ToolException: Fail to load class :RequestLimit
at org.apache.cxf.tools.util.AnnotationUtil.loadClass(AnnotationUtil.java:88)
at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.getServiceClass(JavaToWSDLProcessor.java:284)
at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.getServiceBuilder(JavaToWSDLProcessor.java:181)
at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.process(JavaToWSDLProcessor.java:100)
at org.apache.cxf.tools.java2ws.JavaToWSContainer.processWSDL(JavaToWSContainer.java:110)
at org.apache.cxf.tools.java2ws.JavaToWSContainer.execute(JavaToWSContainer.java:75)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:58)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:40)
at org.apache.cxf.tools.java2ws.JavaToWS.run(JavaToWS.java:77)
at org.apache.cxf.tools.java2ws.JavaToWS.main(JavaToWS.java:45)
It is all about project hasnt been built. I selected Project->Build Automatically in Eclipse.
More information. Solution here

JSF / Spring Security : view wrapper generates LinkageError

I'm having an issue with JSF rendering. Here's my setup:
CentOS
TomEE Plus 1.5.2
Icefaces
Spring Security 3
And my app is set up like this:
/opt/tomee/lib/[all the normal TomEE jars]
/opt/tomee/lib/[all the Spring Security jars]
/opt/tomee/lib/icefaces.jar
/opt/tomee/lib/icefaces-compat.jar
/opt/tomee/lib/icepush.jar
/opt/tomee/webapps/UI/index.xhtml
/opt/tomee/webapps/UI/WEB-INF/lib/icefaces-ace.jar
/opt/tomee/webapps/UI/[normal jsf 2 configuration]
There isn't anything obvious in the logs but when the JSF attempts to render I get the following error:
com/sun/crypto/provider/HmacCore
viewId=/index.xhtml
location=/opt/tomee/webapps/UI/index.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.lang.LinkageError - com/sun/crypto/provider/HmacCore
at com.sun.crypto.provider.HmacSHA1.(DashA13*..)
The stack trace on the error page is massive, so I'm not going to dump a novel here, but here are the calls of note.
java.lang.LinkageError: com/sun/crypto/provider/HmacCore
at com.sun.crypto.provider.HmacSHA1.(DashA13*..)
{...}
at java.security.Provider$Service.newInstance(Provider.java:1221)
{...}
at org.apache.myfaces.shared.util.StateUtils.encrypt(StateUtils.java:328)
{...}
at org.icefaces.impl.renderkit.RenderWrapper.encodeEnd(RenderWrapper.java:53)
{...}
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
I dumped the contents of all the jars in tomee/lib but com.sun.crypto isn't anywhere that I can find in the web server. Apps that don't use Spring Security work just fine.
Any thoughts?
OK. I got it to work so I'm going to be 'that guy' and answer my own question. I hope that it helps save someone else from the migraine it gave me. The problem went away after I did the following:
delete my war
let tomcat clean up the webapps dir
stop tomcat
delete the related directories from work
add the spring security taglibs jar to my app
remove the encoder declaration from my applicationSecurity.xml
rebuild the app
start tomcat
redeploy
drink heavily
profit
Step 10 wasn't actually a part of debugging process but I wouldn't have complained if it was. Share and enjoy.

Ejb lookup failing on WAS7.0 with NamingException

I have an application developed on RAD using WAS 6.0. I migrated the code to WID 7.0. After making some changes in the EJB modules(Had to remove the bnd.xmi file from each ejb module to deploy the application on Application Server)the application is running fine, but the EJB modules give the following error:
NamingException has Occured While Getting Local Home
javax.naming.NameNotFoundException:nullName ejb/com/igcc not found in context "local:".
I am not able to figure out what changes do it need to make to run the application on WID.
Any help is appreciated.
Thanks,
Ayush
Well, the "bnd.xmi" files you deleted are the WebSphere-specific deployment descriptors, containing binding information. One of the things that are mentioned there is the name under which to bind each individual EJB home.
You cannot possibly run an EJB module without this binding information existing somewhere.
If you delete these files (which are generated by RAD), you have to assign new binding information from within the administration console, or via your wsadmin-based deployment scripts.
In short... lets start by recovering those files that you erased. :-)

Categories