Jersey REST Web Service with Tomcat, Eclipse and 404's - Need another set of eyes please - eclipse

This should be so simple, but its blowing my mind... I have read through hundreds of the questions here, and so far none of the responses has made a difference in what I have tried. It is obviously time for another set of eyes..
I am getting a 404 error when trying to do the most simple of rest tests.
My Tomcat 7.0 Servers starts up just fine. No errors.
My project name in Eclipse is: atomic_services_poc
The Context in Tomcat is set to: /atomic_services_poc
I can successfully return static pages with: http://localhost:8080/atomic_services_poc/index.html
Here is my web.xml:
<servlet>
<servlet-name>workflowmanagerserlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.tp.wfm.webservice</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>workflowmanagerserlvet</servlet-name>
<url-pattern>/workflowmanager/*</url-pattern>
</servlet-mapping>
Here is the java code for WorkFlowManagerRestService.java
package com.tp.wfm.webservice;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/workflow")
public class WorkFlowManagerRestService {
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello()
{
return "Data Return";
}
}
I am using SoapUI to test the GET method of the restful request. I have tried numerous variations of the following and they all result in a 404 error.
GET host:8080/atomic_services_poc/workflowmanager/workflow
Help please before I throw this laptop...

I don't see anything wrong in your setup, from what you show. You don't mention which Jersey version you are using but I guess is bigger than 2. (I believe in Jersey < 2 the name of the property in the web.xml was different).
I would suggest the following to try to debug:
(1) For the moment remove the
#Produces(MediaType.TEXT_XML)
as suggested by #braunpet, and just test it with your web browser
(2) Add a ResourceConfig class so that you can at least debug what the server is doing in startup. This is pretty simple, you define a class like this:
package com.tp.wfm.application;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApplication extends ResourceConfig {
public MyApplication() {
super();
packages("com.tp.wfm.webservice");
}
}
And change your web.xml like this:
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.tp.wfm.application.MyApplication</param-value>
</init-param>
Then you add a breakpoint in Eclipse to make sure your resources are loading.
I hope it helps!

Ok, so this morning I went back to basics. I created a brand new workspace with eclipse on my laptop from the vogella tutorial. I got this one to work on my laptop in all of 10 minutes. I then went to my problem work area and added the same items step by step. It worked...
I then started adding in my components and slowly one by one, I was able to get them working. I must have had some type of spelling or something wrong, but I feel better that no one here could see it either.
The good news it is now working. (Even after I removed the vogella stuff)..
:)
Thanks all that helped!

well I had the same problem. I was looking for a solution for about 2 weeks. After having passed 20 tutorials it drived me crazy why my tomcat is still showing the 404 response. I just wanted to get a helloworld-example working but the server was showing the 404 every time when I tried to open a ResourcePATH (e.g. #Path("/hello")). My Web.xml was "setupped" for jersey 2.x and the url param was declared as "/rest/*". The URL was called correctly by localhost:PORT/PROJECT/rest/hello.. but no Chance.
Finally I found a solution for myself that may help someone else who is troubling with this (like the author of this question):
Create a .WAR file of your Project and put it into your "apache_tomcat/webapps" directory
(Eclipse: Right Click on the Project-> Export-> as .WAR file)
Restart the Tomcat-Server
Run the Application on the restarted Server
After that, it worked for me, I was able to connect to any #Path("") I implemented. And if I want to implement a new #Path I have to reprocess the 3 steps. Hope this can be helpful!

Related

ATG CRS changing context root causes raw JSP to display

I am working on ATG 10.1.2 with Endeca 3.1.2 with the CRS app. Here is what I've done so far.
wanted to change my context root to /mystore
I changed the contexts in web.xml, application.xml and MANIFEST.MF entry for CommerceReferenceStore, subsequently changed my site configuration for one of the CRS stores to have my custom baseUrl and production URL.
In my case I am not using path based multi-site approach. my baseUrl and production Url are same. If I start my application, all pages are coming fine. However, when I try to browse the category pages (cartridges), the JSP's code is displayed on the browser, they do not compile.
I found some solution on oracle community that I should remove the FORWARD dispatcher from PageFilter from my web.xml, and that should solve the issue. I did that, now the page compiles, but intermittent raw JSPs are displayed along with JSP comments on the browser.
Below threads might give you some context on my issue.
https://community.oracle.com/thread/2508338
https://community.oracle.com/thread/3518254
Has someone tried it and have a solution, please share your inputs.
Would suggest you look at your configuration for these components as changing the context root might require configuration changes to:
ContentItemToRendererPath in the ATG documentation
The getRendererPathForContentItem() method returns the web-app relative path of the JSP file used to render the ContentItem.
/atg/endeca/servlet/request/NucleusHttpServletRequestProvider which provides access to the endeca components
/atg/endeca/assembler/AssemblerPipelineServlet with a full explanation here.
Try to add REQUEST and ERROR as well to the dispatcher element.
If you have ...
<filter>
<filter-name>PageFilter</filter-name>
<filter-class>atg.filter.dspjsp.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PageFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
then change it to...
<filter>
<filter-name>PageFilter</filter-name>
<filter-class>atg.filter.dspjsp.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PageFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Sorry for posting the answer to this after so long.
This was an issue with Oracle Commerce itself. You should try to get a patch for it from Oracle, if you see this on Oracle Commerce version 10.x

JBoss ESB pipeline interceptors

I am new to JBoss ESB and I am trying to intercept and handle all messages that happen on my application server.
I found that pipeline interceptors are what I am looking for. However, I am unable to make them work. Could you direct me to any tutorial concerning this problematigue? I tried documentation for JBoss ESB but this section is very vague. Is there any working sample with pipeline interceptors? I have not found any...
Here is what I have tried:
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.message.PipelineInterceptor;
import org.jboss.soa.esb.message.Message;
public class Interceptor implements PipelineInterceptor {
#Override
public void processMessage(Message msg, ConfigTree arg1) {
System.out.println("Intercepted" + msg.getContext());
}
}
I programmed this very simple class and converted it into a .jar file and placed it in the root directory of my project. I also copied jbossesb-properties.xml next to it and uncommented the interceptors section. What else should I do? Where do I specify the path to my interceptor class?
Any help is appreciated...
Ok, after a day of trying everything possible, I think I have solved it. You have to place the .jar file with Interceptor somewhere in the path of ESB (the best way is probably to the folder with deployed ESB in AS) and specify path to it in jbossesb-properties.xml file...

Combining Akka, Spray, and embedded Jetty

I'm trying to create a standalone JAR containing Akka, Spray, and Jetty. Ideally I distribute the entire application in that single file, without any external files whatsoever.
I understand how to create an embedded Jetty server instance
def main(args: Array[String]): Unit = {
val server = new Server(9012);
server.start();
server.join();
Thread.sleep(2000);
server.stop();
}
and I've followed the Spray example code in creating a HelloService and Boot class, but I have no earthly idea of how to connect the two, so that when a URL is requested on the Jetty server a Spray service responds to it. Any help would be much appreciated.
Update: I'm getting a lot closer to solving this problem, thanks to a thread of inquiry prompted by Alois Cochard (I'm coming from a web scripting background, and getting my head around Java web services has been ... challenging!). I've modified my main method to start the server and read the Jetty and akka configuration files that are in the getting started template. It's reading both of those files, but now I'm getting this when I navigate to / on the Jetty server:
HTTP ERROR: 500
Problem accessing /. Reason:
assertion failed: 0 actors for id 'spray-root-service' found, expected exactly one
I know I'm missing something silly (and probably that I should break down and use SBT, but being able to just compile and run in Eclipse, and then refresh in the browser, is so simple and appealing).
Update #2: Figured out the problem. I wasn't creating a WebAppContext object, which meant that the web.xml was never getting read, and thus Akka was never being loaded. This is the revised main method which is now working.
According to the spray-template, you should add the Spray servlet connector in the web.xml configuration file:
http://github.com/spray/spray-template/blob/master/src/main/webapp/WEB-INF/web.xml
You can find some informations about how to configure a standealone jetty to use this file here (there is surely better references in netty documentation directly):
http://exist.sourceforge.net/deployment.html#d47e594
BTW, using the spray template as a basis for your project looks like a good idea ;)

Play framework weblogic 10.3.3.0 deployment

I built a Play app and tried to deploy on weblogic using the following commands:
play war -o myApp myApp
Later I just deployed the exploded war directory to weblogic, everything worked fine but everytime I try to access a route. I get the following error:
Not found
GET /myApp/params
This is a rest service not an application with UI's. I tried to deploy on tomcat and everything worked fine but I had to make the application context root to be /. I tried the same thing with weblogic but it did not work.
Here is my route file:
GET / Application.index
GET /sectorinformer/{telephone} Application.show
GET /sectorinformer/public/ staticDir:public
* /{controller}/{action} {controller}.{action}
And here is my controller code:
package controllers;
import models.InstalAddress;
import models.SectorInfo;
import play.Logger;
import play.mvc.Controller;
public class Application extends Controller {
public static void index() {
render();
}
public static void show(String telephone) {
Logger.debug("Starting request");
Logger.debug("domain: '%s'", request.domain);
String instalAddressId = InstalAddress.getInstalAddressId(telephone);
SectorInfo si = new SectorInfo();
si.initializeSectorInfo(instalAddressId);
renderXml(si.generateXmlResponse());
}
}
Thanks in advance for any help.
Weblogic 10 is a fully compliant J2EE 5 application server, as a consequence it is bundled with JPA 1.0.
There are two little issues to get Play running on weblogic.
Applying an Oracle patch to have weblogic support JPA 2.0
Adding a deployment descriptor property to prioritize class resolution from web-inf
Both are trivial and the Play documentation should probably mark weblogic 10 as a working deployment target.
To fix #1, open to following oracle link.
For the lazy readers, add this declaration at the top of wlserver/common/bin/commEnv.sh
export PRE_CLASSPATH=$MW_HOME/modules/javax.persistence_1.0.0.0_2-0-0.jar:$MW_HOME/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar
for windows, the file is wlserver/common/bin/commEnv.bat
set PRE_CLASSPATH=%MW_HOME%/modules/javax.persistence_1.0.0.0_2-0-0.jar;%MW_HOME%/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar
To fix #2, create the file weblogic.xml at the following location myplayapp/war/WEB-INF/weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
The war folder is automatically picked up by play war when the web archive is built.
That's it!
I personally believe Play should create weblogic.xml itself, but that's not how it works as of 1.2.1
Unfortunately I don't have either weblogic know nor time to investigate in you interesting problem. I can only can give you some hints what I would do:
Try to connect the app with a debugger or if this doesn't work checkout the Code and build your own version, with a lot of log-statements.
As far as I know every request will handled by ActionInvoker. invoke. Look how the argument comes in. The other point is the Router, which has still a lot of trace-logs. So perhaps you start first and let the whole stuff run on trace-level. Perhaps that give you some hint's where to look in more detail.
To do this start with a clean app and make no configuration tricks, specially don't run it in ROOT-Context. Just create play war myapp -o myapp.war --zip and deploy it (Don't forget --zip). Then analyze the log.
Good look.
Niels
I deployed my Play app (play 1.1.1) to Websphere 6.1 and I encountered some issues. Not sure you have the same issues but here there are (hope it can help you):
1- JDK version: My "play war xxxx --zip" use a JDK 1.6, and Websphere 6.1 uses a JDK 1.5. When I tried to launch my webapp an UnsupportedClassVersionException was thrown. I regenerated my war file using the correct JDK et voilĂ  !
2- When you deploy a war aplication to Websphere, you can specify the context's name. I don't know how to do it with Weblogic, but did you set the correct value ?
As Niels said, analyze logs files: you should find what happens !
Unfortunately, Play! doesn't support Weblogic.
See: http://www.playframework.org/documentation/1.2/deployment

Jetspeed null PortletDefinition

I am running a jetspeed portal which contains various portlet applications and have come across an issue after a recent reinstall where some of the portlets will return
Cannot pass a null PortletDefinition
to a PortletEntity
Any idea what is causing this issue? I investigated a bit and it seems that jetspeed runs a process when new portlets are added where it creates mappings in its DB (derby in my case). If this does not complete it seems to cause this problem. Is my assumption correct? If yes, how can I restart this process?
Many thanks
This exception can be caused by having a mismatched portlet name on on your page. This often happens when the portlet application is deployed with one name, but then the page fragment references another name, for example, on your page you have:
<fragment id="1234" type="portlet" name="myApp::myPortlet">
and when you deploy your war file, it is named for example myApp-1.0-SNAPSHOT.war
The fragment's name attribute should have the value "${portlet.war.name}::${portlet.name}. The first part (${portlet.war.name}) is the name of the portlet war file, minus the .war. The second part comes from the value of the tag in the portlet.xml file.
You can either rename your war file, or change your page definition to include the version. I don't recommend putting the version number in the fragment though, as it can change.
A third solution is to actually change the name of the portlet app in your web.xml by setting an init param named contextName on the Jetspeed Container servlet. In the example below its set to "myApp":
<servlet>
<description>MVC Servlet for Jetspeed Portlet Applications</description>
<display-name>Jetspeed Container</display-name>
<servlet-name>JetspeedContainer</servlet-name>
<servlet-class>
org.apache.jetspeed.container.JetspeedContainerServlet</servlet-class>
<init-param>
<param-name>contextName</param-name>
<param-value>myApp</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>