error 404 due to mishandling of a war file, maybe? - web-services

I'm trying to deploy my java project on Tomcat via a war file, but I got 404-error when I enter the above URL in my favorite navigator. I followed this tutorial.
To deploy my project, I puted the War file under ${Tomcat}/webapp.
Here is my sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="projetServices"
implementation="com.bh.services.Service"
url-pattern="/service"/>
</endpoints>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>service</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/service</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
URL : localhost:8088/projetServices/service
Here is my project architecture:
Please how can I resolve this problem ?

Related

My amazon beanstalk instance is not working

I am using eclipse to deploy java RESTful web project in amazon elastic beanstalk and it is successfully deployed. Snapshot of my Beanstalk dashboard is:
.
When I try to access the http://event-api.us-west-2.elasticbeanstalk.com/ URL, it shows 404 error. Why am I getting this 404 error?
I did not change web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>EventMngmtApi</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.vasithwam.users,com.vasithwam.event</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Passing Parameters using jetty contextHandler

I'm wanting to make some custom endpoints that point to another endpoint in my jetty setup. For example, I already have and endpoint like http://myserver.com/app that serves up a help page. Further, if I pass certain arguments, I get different pages. So for example http://myserver.com/app?app_id=56 might serve one app and http://myserver.com/app?app_id=48 might serve a static html page that documents functions.
For the sake of some of the users, I'd like to set up simple endpoints for a few of the commonly used apps. So if a user went to http://myserver.com/docs, they'd should see the same thing as http://myserver.com/app?app_id=48.
I've been trying to accomplish this with .xml Configuration files. So far I've got it almost working.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.eclipse.org/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/docs</Set>
<Set name="resourceBase">http://localhost:8080</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="welcomeFiles">
<Array type="String">
<Item>app</Item>
</Array>
</Set>
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
Using this config file going to /docs serves the aforementioned help page which I would normally see by loading http://myserver.com/app, my hangup is I can't figure out how to pass the appropriate app_id.
I think I may end up creating some sort of custom handler but I'm not exactly sure how to go about implementing it.
And just to complicate the issue, I also want to be able to pass some arbitrary parameter to my endpoint and have it passed along. So http://myserver.com/docs?foo=bar would display http://myserver.com/app?app_id=48&foo=bar.
Should I be going about this another way or can this all be accomplished through the config xml files?
If using Jetty 9.2+ you can just use the built-in static resource serving (magic provided by the deploy module)
Eg:
$ cd /path/to/my.base
$ ls -l webapps
total 4
lrwxrwxrwx. 1 joakim joakim 84 Oct 27 17:24 docs -> /opt/my/docs
$ java -jar /path/to/jetty-dist/start.jar
But if you really want to handle static resources with an XML ...
Don't use ContextHandler and ResourceHandler they are only for the most simplistic and naive of file serving scenarios.
Use an anonymous WebAppContext
Set resourceBase to the directory where your documents are
Here's how you setup a static file serving XML (done right)
$ cd /path/to/my.base
$ cat webapps/docs.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/docs</Set>
<Set name="resourceBase">/opt/my/docs</Set>
<Set name="defaultsDescriptor"><Property name="jetty.base" default="."/>/etc/docs-web.xml</Set>
</Configure>
$ cat etc/docs-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
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/web-app_3_1.xsd"
metadata-complete="false"
version="3.1">
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>aliases</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>acceptRanges</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>welcomeServlets</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>redirectWelcome</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>maxCacheSize</param-name>
<param-value>256000000</param-value>
</init-param>
<init-param>
<param-name>maxCachedFileSize</param-name>
<param-value>200000000</param-value>
</init-param>
<init-param>
<param-name>maxCachedFiles</param-name>
<param-value>2048</param-value>
</init-param>
<init-param>
<param-name>gzip</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>etags</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cacheControl</param-name>
<param-value>max-age=3600,public</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>
$ java -jar /path/to/jetty-dist/start.jar

Not able to deploy Spring MVC 4.0 Webservice

1) web.xml -
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>gamesWS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
2) rest-servlet.xml -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.service.games" />
<mvc:annotation-driven />
3) Java class-
package com.service.games;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("/service/greeting")
public class SpringServiceController {
#RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String getGreeting(#PathVariable String name) {
String result = "Hello " + name;
return result;
}
}
I created a gamesWS.war file and placed it in the webapps folder of Tomcat server.
Started the server without any error.
But, when trying to access the webserv using localhost:8080/gamesWS/service/greeting/text
I am getting an error - HTTP Status 404 : Requested resource not available.
I tried checking - jdk version mismatch, proper folder to place of war file. Can someone please point me what I might be missing here?
Snap shot of the firebug console -

Why jndi-lookup is not creating a EntityManagerFactory bean definition from JNDI?

I created my app as J2EE app in JDeveloper 11g. It uses JSF 2.1, Spring-core 3.2.1 and Spring-data-jpa-1.4.4 among others Spring necesary modules. I've created a datasource in the integrated WebLogic server within the default domain. When I try to run the app the following error is showing up.
weblogic.application.ModuleException: :org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0:
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:538)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:497)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:659)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:632)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:159)
Truncated. see log file for complete stacktrace
My WEB-INF/web.xml has the configuration to setting up the JSF servlet and Spring listeners:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.jsf;*.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Then there is the WEB-INF/faces-config.xml with the Spring integration:
<?xml version="1.0" encoding="windows-1252"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
Then there is WEB-INF/applicationContext.xml with the Spring config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.myapp.*"/>
<jpa:repositories base-package="com.myapp.repositories" />
<jee:jndi-lookup id="dataSource" jndi-name="MYJNDI"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
</beans>
Then I created the persistence file under META-INF/persistence.xml
<?xml version="1.0" encoding="windows-1252" ?>
<persistence 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"
version="2.0">
<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>MYJNDI</jta-data-source>
<class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
<class>org.eclipse.persistence.example.jpa.server.business.CellAttribute</class>
<properties>
<property name="eclipselink.target-server" value="WebLogic 10"/>
</properties>
</persistence-unit>
</persistence>
My Entity and Repository classes looks like this:
... imports
#Entity
#Table(name = "CONTRIBUYENTE")
public class ContribuyenteEntity implements Serializable {
#SuppressWarnings("compatibility:-6161811794505268140")
private static final long serialVersionUID = 7000366567373058605L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID_CONTRB")
private Long idContrb;
... get and set methods
}
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
-------------------------------------------------------------------------------------
#Repository
public interface ContribuyenteRepository extends CrudRepository<ContribuyenteEntity, Long>{
}
I've performed the extra configuration on the server as the Oracle docs indicates:
http://docs.oracle.com/middleware/1212/toplink/TLADG/tlandwls.htm#BABEDCEI
I don't really found out why the <jee:jndi-lookup id="dataSource" jndi-name="MYJNDI"/> is not registering the EntityManagerFactory bean within the context. I'd really appreciate any help you can provide. Regards!

web services with axis2, integrating spring

I created a webservice with axis2. now i am integrating with spring. in web.xml i want to load both axis servlet and spring dispatcher servlet when the url pattern is /services/listServices/PhysicianInfoImpl?wsdl. but only one is loading. my web.xml is
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Physician</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>/axis2-web/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Admin Servlet Web Admin</display-name>
<servlet-name>AxisAdminServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/PhysicianInfoImpl*</url-pattern>
</servlet-mapping>
</web-app>