1

I am attempting to develop a hangouts chat bot. I am attempting to write this up in Java using Eclipse as my development software - along with Apache Tomcat 9 as my server.

My question is how do I develop the API to integrate with my bot program.

The ultimate goal is to have a chat bot for Google Hangouts that is in house developed and can take information from an incoming chat and send it as an email to myself.

I am using a tomcat 9.0 server

I am basing my project of this tutorial video - I followed all the steps, but something is missing. I realize in the video he is using tomcat 8.5, hopefully this is not the root of my issue.

https://www.youtube.com/watch?v=5jQSat1cKMo

I figured if I could follow the steps in the above video I would have a base platform to manipulate to communicate between Google Hangouts and my java program.

//Below is my sample java code based on the linked video above

package test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ApplicationPath; 
import javax.ws.rs.core.Application; 

@Path("/hello")
public class Hello {

@GET
@Produces(MediaType.TEXT_XML)
public String sayHello()
{
    String resource = "<? xml version = '1.0' ?." +
"<hello> HI Patrick, this is hello from XML</hello>";
    return resource; 

}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String sayHelloJASON()
{
    String resource = null;
    return resource; 

}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHelloHTML()
{
    String resource = "<hi> Hi Patrick, this is hello from      HTML</h1>";
    return resource; 

 }



}

Now my xml code

<?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">


 <display-name>javaAPIee</display-name>

 <servlet>
<servlet-name>JAVA API</servlet-name>
   <servletclass>org.glassfish.jersey.servlet.ServletContainer.class</servlet-class>    

<init-param>
 <param-name>jersey.config.server.provider.packages</param-name>
 <param-value>test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAVA API</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

I want the variable from my url - http://localhost:8080/javaAPIee/rest/hello

/rest/hello is supposed to specify the type of API (/rest)followed by the variable '/hello', when this is executed I am supposed to see a response on the webpage that says " HI Patrick, this is hello from XML"

I have tried implementing a tomcat server with my dynamic web project on eclipse - but it is giving me an HTTP 404 - the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

aviator
  • 11
  • 1
  • Your `servlet-class` start tag is misspelled (didn't you get loud validation errors there?), and class names don't end with `.class`, that's just what their file names end with. Fix both. – nitind Jul 21 '19 at 21:51
  • Thank you for you input! I have corrected the mistakes you pointed out - must have been a mistake when creating the post. But It is not working, I am still getting the 404 when trying to run the program. – aviator Jul 24 '19 at 18:10
  • Show us server startup log output and what's logged for the 404 access. – nitind Jul 24 '19 at 18:12

0 Answers0