Remote API JAVA url does not work GAE - java

I have deployed application into GAE. When i try the url as http://aabbbaaacccc.appspot.com/_ah/remote_api. I am getting 404 Error page. I have added in web.xml file. I have given correct app id. It deploys. After deployment successful, An dialog box appears and displays file not found along with notepad.
<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
I need to deploy my app into server and start a Remote api with an other application and share the entites from an other app.
I am struggling with this issue for past 2 days. Please help me.
U can look at the error dialog box in the following link.
http://i40.tinypic.com/bfgzki.png
Thanks.

Appengine should works fine.. i've listed the all details for basic project setup. please look and find what you missed.
The Servlet Class
App Engine Java applications use the Java Servlet API to interact with the web server.
In the directory src/guestbook/, make a file named GuestbookServlet.java with the following contents:
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
The web.xml File
When the web server receives a request, it determines which servlet class to call using a configuration file known as the "web application deployment descriptor." This file is named web.xml, and resides in the war/WEB-INF/ directory in the WAR. WEB-INF/ and web.xml are part of the servlet specification.
In the directory war/WEB-INF/, a file named web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>guestbook</servlet-name>
<servlet-class>guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
This web.xml file declares a servlet named guestbook, and maps it to the URL path /guestbook.
The appengine-web.xml File
App Engine needs one additional configuration file to figure out how to deploy and run the application. This file is named appengine-web.xml, and resides in WEB-INF/ alongside web.xml.
In the directory war/WEB-INF/, a file named appengine-web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application></application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
appengine-web.xml is specific to App Engine, and is not part of the servlet standard. You can find XML schema files describing the format of this file in the SDK, in the appengine-java-sdk/docs/ directory. See Configuring an App for more information about this file.
Running the Project
The App Engine SDK includes a web server application you can use to test your application.
select Debug As > Web Application.
Testing the Application
Start the server, then visit the server's URL in your browser. If you're using Eclipse and the Google Eclipse plugin, the server runs using port 8888 by default:
http://localhost:8888/guestbook
If you're using the dev_appserver command to start the server, the default port is 8080:
For details please see following tutorials:
Tutorial 1:
Tutorial 2:
Tutorial 3:

Related

Simple Java web app with tomcat, from localhost to deployment

I'm a complete beginner in java development, coming from rails.
I'm following this Heroku tutorial I've git cloned this example project to try deployment on heroku.
Now I have different app, a small back-end for an android app which runs on Tomcat. It's really simple but I dont understand how/where to put the files from my back-end to the embedded-tomcat app (it's Heroku's example) and push it to Heroku.
My back-end (named hatalink) has this form (and it's inside webapps folder in Tomcat)
.
hatalink
└─── WEB-INF
|
└─── lib
| └─── mysql-connector-java-5.1.27-bin.jar
|
└─── classes
└─── hatalink
| └─── All my classes in *.class
|
└─── All my classes in *.java form
└─── web.xml
And the content of my web.xml is all like:
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>hatalink.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
.... (The same for all classes...)
</web-app>
This works fine on my localhost with tomcat, but how do I add the files that are already working from my back-end project to the example project?
Then again am I going right about this? Is there a simpler way/place to deploy this app? Its really simple, I just want it online.
There is a simpler way since servlets 3.0.
Instead using Deployment Descriptor (web.xml) like you did
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>hatalink.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
.... (The same for all classes...)
</web-app>
You can use annotations.
#WebServlet(name = "myServlet", urlPatterns = { "/path/to/my/servlet" })
public class YourServletName extends HttpServlet {
Your web.xml file always has to go into WEB-INF/web.xml regardless of what kind of server/service you are using. This would have to be the case for your local Tomcat, too.
Your ASCII art picture shows you hev it in WEB-INF/classes/web.xml, so you'll need to move it.
You never need to package .java files with a web application. I would recommend that you don't include them for a number of reasons.

Deploying Servlet on Tomcat 8.0.30

I am trying to deploy a compiled Servlet class onto Apache Tomcat server 8.0.30.
But i get the following exception :
javax.servlet.ServletException: Error instantiating servlet class HelloWorld
java.lang.ClassNotFoundException: HelloWorld
My tomcat webapps/ROOT/ folder did not contain the classes folder so i created one and copied HelloWorld.class into it. I added the following lines inweb.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<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"
version="3.1"
metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
Can anyone tell me what am I doing wrong?
#wero : This is the content of my HelloWorld.java :
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
private String message;
public void init() throws ServletException
{
// Do required initialization
message = "Hello World";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// Set response content type
response.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy()
{
// do nothing.
}
}
You need to put the files into the correct places. Java class files need to be placed into WEB-INF/classes:
webapps/ROOT/WEB-INF/web.xml
webapps/ROOT/WEB-INF/classes/HelloWorld.class
Then start Tomcat and look if there are errors in the Tomcat log.
When tomcat had been started there were not class file in your app. Tomcat is loading classes during deployment on startup or if you manually deploy it at runtime. After that the context should be reloaded. You can't just copy your classes to the tomcat webapps folder without loading them.
Read Tomcat docs how to deploy your application.
Deployment is the term used for the process of installing a web
application (either a 3rd party WAR or your own custom web
application) into the Tomcat server.
Web application deployment may be accomplished in a number of ways
within the Tomcat server:
Statically (the web application is setup before Tomcat is started)
Dynamically (by directly manipulating already deployed web applications (relying on auto-deployment feature) or remotely by using
the Tomcat Manager web application)
The Tomcat Manager is a web application that can be used interactively
(via HTML GUI) or programmatically (via URL-based API) to deploy and
manage web applications.
There are a number of ways to perform deployment that rely on the
Manager web application. Apache Tomcat provides tasks for Apache Ant
build tool. Apache Tomcat Maven Plugin project provides integration
with Apache Maven. There is also a tool called the Client Deployer,
which can be used from a command line and provides additional
functionality such as compiling and validating web applications as
well as packaging web application into web application resource (WAR)
files.
Got it. The classes folder I created was "C"lasses where tomcat expects "c"lasses.

Failure trying to deploy GWT on Apache Tomcat

I am working on a GWT application. The app. is working in dev mode.
I am working on a gwt project and trying to deploy it to Apache Tomcat. I have never used Apache Tomcat before and I am rather new to Java and GWT. My tomcat server seems to be up and running as I see the "If you see this you have succesfully installed Tomcat" on localhost:8080/
After I got Tomcat up and running I used Eclipse GWT Compile to compile my app. I have copied my .html file and .css file + the war folder to C:\apache-tomcat-8.0.15\webapps\MyAPP\
Opening the .html file (file:///C:/apache-tomcat-8.0.15/webapps/PurchaseOrder/PurchaseOrder.html) gives me my ui (login screen), but when making the first RPC call (loggin in) I am getting the error "FailureUnable to initiate the asynchronous service invocation (PurchaseOrderService_Proxy.checkUsernameAndPassword) -- check the network connection"
My thougts are that something is incorrect in my web.xml or my service class
PurchaseOrderService.java
package com.google.gwt.sample.purchaseorder.client;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.gwt.sample.purchaseorder.client.model.Brands;
import com.google.gwt.sample.purchaseorder.client.model.Item;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("exampleservice")
public interface PurchaseOrderService extends RemoteService {
boolean checkUsernameAndPassword(String value, String value2);
ArrayList<Item> getPersonalInfo();
HashMap<String, ArrayList<Item>> getListOfPurchaseOrderSortedFromBrands();
String createExcelExportFile(HashMap<String, ArrayList<Item>> exportMap);
}
web.xml:
<!-- Servlets -->
<servlet>
<servlet-name>purchaseOrderServiceImpl</servlet-name>
<servlet-class>com.google.gwt.sample.purchaseorder.server.PurchaseOrderServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>purchaseOrderServiceImpl</servlet-name>
<url-pattern>/purchaseorder/exampleservice</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>PurchaseOrder.html</welcome-file>
</welcome-file-list>
</web-app>
Opening the .html file
(file:///C:/apache-tomcat-8.0.15/webapps/PurchaseOrder/PurchaseOrder.html)
gives me my ui (login screen), but when making the first RPC call
(loggin in) I am getting the error "FailureUnable to initiate the
asynchronous service invocation
(PurchaseOrderService_Proxy.checkUsernameAndPassword) -- check the
network connection"
This is not how you access the application running in Tomcat. Your tomcat is running # localhost:8080 so you have to access using http://localhost:8080/<app_context_root>/filename.html

Deploying a Maven Project using Vaadin to Tomcat

This may be an incredibly stupid question, but I have a web application that relies heavily on jQuery for many various widgets and aesthetic utilities that I'm trying to migrate into using Vaadin. For starters, I'm attempting to just create your run-of-the-mill "Hello World" application -- built with Maven and deployed to Tomcat -- with Vaadin, and I'm having a problem deploying it. I've been following the turtorial posted here ( https://vaadin.com/book/-/page/intro.walkthrough.html ). Here's my file structure thus far:
HelloWorld
src
main
java
com
business
helloworld
HelloWorld.java
resources
webapp
WEB-INF
web.xml
test
target
pom.xml
I'm guessing that my problem lies somewhere in my web.xml that follows:
web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>HelloWorld</display-name>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>HelloWorld</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I've tried my best to follow the examples I've seen, but I have a feeling I'm making a stupid mistake. When I run the project as a Maven Build (tomcat:redeploy), it doesn't appear in my Tomcat Manager. Any ideas? If you need any more information (like what's in my pom.xml), just let me know...
EDIT: Is it better to create a Vaadin Project and convert it to Maven, or vis versa?
MyApplicationClass in application param-value should be the whole qualified class name, like
com.business.helloworld.HelloWorld
(I'm on a mobile phone so I didn't check the syntax, but that should be it.)
Edit: To the second question, there's an Maven archetype that creates an Maven Vaadin project. By using that you won't have to convert either way.

Tomcat 6 not recognizing <url-mapping>

I have what I think is the simplest possible
hello world example (see below). But when asking for
"http://localhost:8080/hello" thru firefox,
it gives me the
"The requested resource (/hello/) is not available"
error.
Environment: newly installed tomcat 6.0.32 on Windows 7.
Other information:
1. None of the "similar questions" provides any clues.
From experimentation, it appears that tomcat is not
doing the mapping from localhost:8080/hello to my servlet.
I set "<load-on-startup>"
which showed me that the servlet's init entry was being
called, but doGet() is never called.
The log files show no errors.
I have tried both starting tomcat with the hello
directory already in webapps, with hello.war in
webapps, and deploying using the manager application.
All act the same way.
Some possibilities I have considered:
According to the documentation, I should
not need to use a context.xml file, and my experiments
with a context.xml produced the same resource not found
error.
localhost:8080/hello should instead be
localhost:8080/.../hello, but if so, then what is
the ... supposed to be?
Trailing / (e.g. /hello versus /hello/). I changed
the url-pattern to "/hello/*", but it fails the same
way.
I assume the problem is something simple, but I cannot
see it.
[Added 8/8/2011]
The answers about using context.xml were correct; thanks.
In looking around, it appears that an alternate way
to achieve the same effect is to put this
into my web.xml file.
<context-param>
<param-name>ContextPath</param-name>
<param-value>/dts</param-value>
</context-param>
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>test.HelloServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
HelloServlet.java:
package test;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class HelloServlet extends HttpServlet {
public void init()
{
System.out.println("\nHelloServlet.init");
}
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
System.out.println("\nHelloServlet.doGet");
PrintWriter out = res.getWriter();
out.println("Hello, world!");
out.close();
}
}
With a Java Servlet Application (part of, but not the total sum of Java EE - Java Enterprise Edition), applications have servlets under what is called a "context path". This "context path" has to be specified in order to map any request to the application.
Apache Tomcat makes this context path pretty easy to configure, either via server.xml (not recommended) or individual context files (recommended). Both ways specify where to find your web application directory (an unpacked web application archive, or WAR file) and where to place it on the server at a context path.
As Vlad has already said, if you deploy your war file into Tomcat's webapps directory and have automatic installation on (I believe it is on by default), Tomcat will unpack the .war into a directory under that location and use the war's name as its context path. His example war file is named "helloapp.war", so, with the default settings, it would receive any request to http://localhost:8080/helloapp because its context path becomes helloapp.
Of course, once the request is sent to the context path, something needs to match against it. That's where the web.xml comes in to play. While it is possible to use the root as a matcher (every request to the context path gets handled by the same process), typically a pattern is used (such as *.do, *.action, etc), so that individual requests to the helloapp are easily distinguishable (it's easier to read and debug http://localhost:8080/helloapp/login.action and http://localhost:8080/helloapp/doSomethingElse.action than both being recognized via some parameters and the same path of http://localhost:8080/helloapp in my opinion)
So, the context path gets to your application, then your application has to do a lookup on the web.xml to see where to send the actual request. In your example, if your webapp was deployed at the context path of helloapp, to access it with the proper mapping, you would simply append /hello, so the request becomes http://localhost:8080/helloapp/hello
You are deploying your hello servlet in a webapp. Assuming the webapp is in a folder helloapp or in an archive helloapp.war in Tomcat's webapps directory then your sevlet would be accessible at http://localhost:8080/helloapp/hello
You will either need to rename the package to ROOT.war (or the ROOT directory) or modify the ROOT.xml context.xml file to point to the hello folder.
If you go to /hello/hello I bet you'll see your app. If you're using tomcat, use context.xml.
You may not need to use it for a webapp to work, but if you deploy under tomcat, things just work more coherently when you have a context.xml file.
In /yourtomcatinstall/webapps/hello/META-INF/ create a context.xml file with this information"
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/hello">
</Context>
And change the url mapping of your servlet in web.xml to / and/or /* you can have more than one url mapping for a servlet.

Categories