Error 404--Not Found - Unable to call REST WebService - web-services

I am not lucky so far to get the solution for the below error,
"Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address."
but no luck and so posting this question here.
I have a requirement to download a image file from the server location using RESTFul Web Services. So, i created a REST WS in eclipse as below steps,
Eclipse --> File --> New Dynamic WebProject
Created a service class called "DownloadWebService" in src
Added Jersey libraries in Java Resources --> Libraries folder.
Created index.jsp and web.xml in WebContent folder.
Project right click --> Export--> WAR file.
DownloadWebService:
package com.downloadfile.webservice;
import java.io.File;
import java.util.logging.Logger;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
#Path("/files")
public class DownloadWebService {
private static final String FILE_PATH = "/ngs/app/alect/test";
#POST
#Path("/image")
#Produces("image/png")
public Response getFile() {
System.out.println("************");
Logger.getLogger("############");
File file = new File(FILE_PATH);
ResponseBuilder response = Response.ok((Object) file);
System.out.println("testing Web Service..."+FILE_PATH);
System.out.println("");
response.header("Content-Disposition","attachment; filename=\"test.png\"");
return response.build();
}
}
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"
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">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.downloadfile.webservice.DownloadWebService</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Download Image File
</body>
</html>
I am able to deploy this WAR application in WebLogic server and when i hit the test below link, it's taking me the index.jsp file in the browser which is expected and it's correct. After i click the link "Download Image File", its forwarding the below URL in the browser
http://alecitapp.corp.apple.com:7007/AppleDownloadWebService/rest/files/image
It's throwing the above said 404 --Not found error.
Am i missing something here? Not even seeing the Service class is being called? Index page is coming up and on click the download link it should go to the Service class but it didn't.
Please correct me if i am doing wrong.
Thanks,
Karthik.

Related

JAX-WS multiple endpoints Not Found: Invalid Request

I'm trying implement a web service for two endpoints and getting this error
"404 Not Found: Invalid Request" when tried accessing the service after deploying onto the apache toncat 8.
Below are my web service implementation classes, sun-jaxws.xml and web.xml
WebImplementation1.java
package com.ws.soap.services;
import javax.jws.WebService;
#WebService(endpointInterface = "com.ws.soap.services.WebServiceImpl1")
public class WebServiceImpl1 {
public String printMessage() {
return "Hello from WebServiceImpl1 ";
}
}
WebServiceImplementation2.java
package com.ws.soap.services;
import javax.jws.WebService;
#WebService(endpointInterface = "com.ws.soap.services.WebServiceImpl2")
public class WebServiceImpl2 {
public String displayMessage() {
return "Hello from WebServiceImpl2 ";
}
}
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="WebServiceImpl1" implementation="com.ws.soap.services.WebServiceImpl1"
url-pattern="/impl1" />
<endpoint name="WebServiceImpl2" implementation="com.ws.soap.services.WebServiceImpl2"
url-pattern="/impl2" />
</endpoints>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<display-name>JAX-WS-Tomcat</display-name>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>sayhello</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>sayhello</servlet-name>
<url-pattern>/impl1</url-pattern>
<url-pattern>/impl2</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
Using the exact code supplied (plus the JAX-WS RI jars downloaded from https://jax-ws.java.net/), I was able to create a webapp and successfully access the service endpoints /impl1 and /impl2. Be advised the <url-pattern> and <endpoint ... url-pattern="/impl1"> directives state the resource path to the JAX-WS endpoints within the context path of the enclosing web application.
So, if the name of the webapp is MyWebServices (MyWebServices.war with no other files/code than described in the post, deployed to Tomcat 8) and you have <url-pattern>/impl1</url-pattern> in web.xml, and with a default Tomcat instance listening on port 8080, your web service endpoint would be http://localhost:800/MyWebServices/impl1 with the WSDL available via http://localhost:800/MyWebServices/impl1?wsdl
If you want to customize your context path of your webapp (e.g. you don't want /MyWebServices/... you can use the techniques described in this SO question.
For example, my local Tomcat 8 is running on port 8081:

set contextpath for EJB3 webservice on Weblogic 11g

I build a web service with ejb3 and maven (EAR File),code First, JAXWS, Without WSDL and without WAR, only ejb, with Eclipse, the service works in JBOSS but now i need put the service in Weblogic 11g.
With JBOSS i have the annotation
#WebContext(contextRoot="/wsManCa7", urlPattern="/manCA7WS")
But on Weblogic not, I found this link http://erikwramner.wordpress.com/2012/03/26/ejb3-web-service-context-path-in-weblogic-11g/ to create weblogic-webservices.xml and webservices.xml I put the files inside the META-INF of the jar (And JAr inside EAR) but web logic throws this error
Servlet: "WSEE_SERVLET" failed to preload on startup in Web application:
"/ManCA7". com.sun.xml.ws.server.ServerRtException: Port namespace
http://someserver.com/ManCA7 doesnt match Service namespace {1} at
com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:160) at
com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496) at
com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539) at
weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183) at
weblogic.wsee.jaxws.JAXWSServlet.registerEndpoint(JAXWSServlet.java:138) at
weblogic.wsee.jaxws.JAXWSServlet.init(JAXWSServlet.java:67) at ....
I understand the problem is this tag
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
But which is the required Service namespace???
I don't know what put inside the tag :(
my webservices.xml is
<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
<webservice-description>
<webservice-description-name>ManCA7</webservice-description-name>
<port-component>
<port-component-name>ManCA7Port</port-component-name>
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
<service-endpoint-interface>my.company.manCA7.sei.ManCa7SEI</service-endpoint-interface>
<service-impl-bean>
<ejb-link>ManCa7EndPoint</ejb-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>
And my weblogic-webservices.xml is
<?xml version = '1.0' encoding = 'UTF-8'?>
<weblogic-webservices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices
http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices">
<webservice-description>
<webservice-description-name>ManCA7</webservice-description-name>
<webservice-type>JAXWS</webservice-type>
<port-component>
<port-component-name>ManCA7Port</port-component-name>
<service-endpoint-address>
<webservice-contextpath>/ManCA7</webservice-contextpath>
<webservice-serviceuri>/Mant</webservice-serviceuri>
</service-endpoint-address>
<wsdl>
<exposed>true</exposed>
</wsdl>
</port-component>
</webservice-description>
</weblogic-webservices>
And my EJB expose the service with this
#WebService(endpointInterface = "my.company.manCA7.sei.ManCa7SEI")
#TransactionManagement(TransactionManagementType.CONTAINER)
#Stateless
public class ManCa7EndPoint implements ManCa7SEI{
private final Logger logger = LoggerFactory.getLogger(ManCa7EndPoint.class);
.
.
.
I Found the Solution...
In the annotation webservice I put the same namespace of webservices.xml and worked !!
Inside webservices.xml
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
Inside EJB
#WebService(endpointInterface = "my.company.manCA7.sei.ManCa7SEI",targetNamespace = "http://someserver.com/ManCA7")
#TransactionManagement(TransactionManagementType.CONTAINER)
#Stateless
public class ManCa7EndPoint implements ManCa7SEI{
The solution was targetNamespace = "http://someserver.com/ManCA7"

Restful webservice with jersey 2.0 without maven

Can anybody tell me how to make a restful web service with Jersey 2.0 by not using maven. I have searched everywhere and found tutorial for Jersey1.x versions but not for 2.0. Please help
We provide detail answere based on the user answer user2629427. we checked this on windows 7.
Requirement: (brackets indicate version which this example is tested)
tomcat (8 zip version)
jersey (2.x)
Unzip the tomcat & create a below folder structure in tomcat's 'webapps' folder (folder names are case sensitive).
abc
|___ WEB-INF
|____ classes
|____ lib
Put 'Hello.java' and 'MyApplication.java' into 'classes' folder and 'web.xml' into 'WEB-INF' folder.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.king.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Myapplication.java
package com.king;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("com.king");
}
}
Hello.java
package com.king;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/hello")
public class Hello {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?><hello>Hello Jersey</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html><title>Hi Jersey</title><body><h1>Hello Jersey this is laksys</body></h1></html>";
}
}
Unzip jersey and copy all jar files from api, ext, and lib (not folders) into your apps 'lib' folder.
Now compile the two java files using following command
D:\apache-tc-8\webapps\abc\WEB-INF\classes>javac -d . -cp ..\lib\javax.ws.rs-api-2.0.1.jar;..\lib\jersey-server.jar;..\l ib\jersey-common.jar *.java
Next run the tomcat server
D:\apache-tc-8\bin>startup
In browser address bar type this: http://localhost:8080/abc/rest/hello
I found the answer
package com.hellowebservice;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/hello")
public class Hello {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
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">
<display-name>FirstRestWebService</display-name>
<servlet>
<display-name>Rest Servlet</display-name>
<servlet-name>RestServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.hellowebservice.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
MyApplication.java
package com.hellowebservice;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("com.hellowebservice");
}
}
run with localhost:8080/FirstRestWebService/rest/hello
Just to add to the previous answer. If you aren't using Maven and just building using Eclipse with a Dynamic Web Project and deploying to web app server like Tomcat.
Just download the Jersey JAX-RS 2.0 RI bundle Jersey Downloads, unzip and add all the jars in the lib, api and ext folders to your build path. (I tried without ext jars but got classnotfound when starting the server).
Also add all the jars to the Deployment Assembly of your Dynamic Web Project so they get automatically copied to the WEB-INF/lib directory when deployed to your web app server. Along with the code & web.xml in the above answer, you should have a RESTful api using Jersey 2 up and running.

noHandlerFound No mapping found for HTTP request with URI [..] [duplicate]

This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I am trying out a very simple helloworld kind RestFul webservice in the Spring environment and I have been getting "org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping found for HTTP request with URI [..] in DispatcherServlet with name ..". I have tried various things but nothing is working. So far this is what I have :
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spitter</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spitter</servlet-name>
<url-pattern>/testWs/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spitter-servlet.xml</param-value>
</context-param>
spitter-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="org.resttest.bso" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
And the Controller class;
package org.resttest.bso;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.ModelMap;
#Controller
#RequestMapping("/partners")
public class PartnerController {
public PartnerController(){
System.out.println("******* From the constructor ***** " );
}
#RequestMapping("method=RequestMethod.GET")
public String getPartner(ModelMap model){
try{
model.addAttribute("message", "Spring 3 MVC Hello World");
System.out.println("******* Test message " );
}catch(Exception ex){
System.out.println("******* Exception thrown ... " + ex.getMessage());
}
return "test";
}
}
And in WEB-INF/views/test.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%#page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h1>Message : ${message}</h1>
</body>
</html>
When the server starts I also do see this :
[11/28/12 9:24:02:803 EST] 00000013 DefaultAnnota I org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler Mapped URL path [/partners/method=RequestMethod.GET] onto handler 'partnerController'
But when I try to access using url :
localhost:9080/contextRoot/testWs/partners/
I get the error :
[11/28/12 9:31:07:034 EST] 00000044 PageNotFound W org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping found for HTTP request with URI [/contextRoot/testWs/partners/] in DispatcherServlet with name 'spitter'
Any help is highly appreciated. I have tried several changes based on suggestions on the forums, but nothing seems to work.
Thanks
You have #RequestMapping("method=RequestMethod.GET")
remove the quotes
#RequestMapping(method=RequestMethod.GET)
And it should work.
Remember things while server spring MVC project doing
index.jsp(firslt starting page) should be under WebConent. not under WEB-INF
not under your jsp folder(your jsp pages folder).
Mapping : url pattern is like, if it is in web.xml like /
then "/" this symbol comes at only at in controller class annotation of request
mappin("/**"). no where comes. especially in request at jsp page. there is
request is going to that annatation.
add all jars, like ojdbc14.jar for db.
autowiring is main, how bean id name in configuration file it should same as it is
in your classes.

Build a WS with Spring

I need to create a WS with Spring 3.0.4.RELEASE to run in a Tomcat with Axis2. I'm following this doc: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-web-services-jaxws-export-ri (if that paragraph can be called "doc")
Ok, here are the details:
The java class:
package foo;
#WebService(serviceName="MyService")
public class MyService{
#WebMethod
public String getString(){
return "Hello StackOverflow";
}
}
The WEB-INF/spring-ws.xml:
<?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:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://jax-ws.dev.java.net/spring/core https://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet https://jax-ws.dev.java.net/spring/servlet.xsd">
<wss:binding url="/myService" service="#myService" />
<ws:service id="myService"
impl="foo.MyService" />
</beans>
The WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="myService" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>my Service</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-ws.xml</param-value>
</context-param>
<!-- this is for Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- these are for JAX-WS -->
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/myService</url-pattern>
</servlet-mapping>
And last, but not less important, the error when I start tomcat 6.0.29:
Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://jax-ws.dev.java.net/spring/servlet]
Offending resource: ServletContext resource [/WEB-INF/spring-ws.xml]
Someone has any clue of what is happening? Is all the configuration correct? Does anyone have a simple (working) WS to show how to deploy a WS using Spring?
Thanks in advance
I also experience this issue a while back and figured out the problem is with the "https://". Change it back to http:// and you should be good to go. But when you use http:// you get a schema validation error in eclipse because eclipse can't automatically redirect schema url from http:// to https://. And apparently netbeans is capable of it.
One more thing. You'll have to have the xbeans-spring as well. I honestly think that's a pretty stupid dependency.