How to do HTTP binding for Openfire plugin - java

I'm using Openfire as the chat server for my company. And now I need to create a plugin for Openfire.
As I can see from other plugins, they can have HTTP binding to themself through port 7070.
For example: http://example.com:7070/redfire where redfire is the name of the plugin.
The name of my plugin is toplug, so I want to be able to access the JSP pages of my plugin through: http://example.com:7070/toplug/index.jsp where 'index.jsp' is some example page.
But when I try to access my JSP pages through port 7070, the Jetty server (on which Openfire runs) always reports error 404 'page not found'. I guess this is because the binding to my folder which contains JSP pages hasn't been set. How to do this binding thing please?

The question is answered here:
http://community.igniterealtime.org/message/224134
You do not need a plugin to access the web service for the http bing port. Just put your web pages in a folder under:
OPENFIRE_HOME/openfire/resources/spank
and access with:
http://example.com:7070/your_folder/your_page.html
Note that Openfire does not compile JSP pages unless you replace jasper-xxxx.jar files in the lib folder.
If you still want to create a jetty web context (application) from your plugin, see source code of Redfire plugin:
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.webapp.WebAppContext;
...
public void initializePlugin(PluginManager manager,File pluginDirectory) {
ContextHandlerCollection contexts =
HttpBindManager.getInstance().getContexts();
context = new WebAppContext(contexts,pluginDirectory.getPath(),"/"+NAME);
context.setWelcomeFiles(new String[]{"index.html"});
...

Related

Seperate frontend code from Maven, Tomcat, jax-rs, Jersey project

I am about to create a backend for a web application with Java servlets for a REST Api only, which should base on
Java 11
Maven
Tomcat 9 (externally to project)
JAX-RS
Jersey
Then I am using Eclipse and I have created a dynamic web project and converted it to a Maven project.
Some problems in the project / folder structure might be caused by this. Here is the structure:
When I let the server run and hit localhost:8080/hello_world I can see the index.html in the browser.
I actually have two question:
Having a real WebContent is wrong, isn't it? I should have a real webapps folder, but the WebContent folder should be virtual (from Eclipse), right?
How can I separate the index.html and or at least all other frontend resources (HTML, CSS, JS (React.js etc. pp.)) to a separate folder for heaving one repository for the Java Web Servcice and another one for the frontend? Is this impossible with this tech stack?
I believe that your web service URL is not complete and you have to check your web.xml url-pattern tag and the Path annotation you have defined for your services.
In order to have a better prospect of Restful web services in Eclipse IDE, I suggest you follow these HelloWorld examples (simple hello world rest service and CRUD web services using jersey) to widen your horizon about some configurations in web.xml in which you have to define your container to your application server and corresponding pom.xml for jersey dependencies.
it is ok to have the WebContent folder in Dynamic Web Applications and there is nothing wrong with your project / folder structure

WAR deployment in tomcar

I need some advise over here. I have deployed a java based app on tomcat server. Tomcat server is installed on aws cloud. I am using the URL as hostname:portno/WAR file name to run the app and When i try to hit the app on browser it throws an error 404. However, when i add index.html after the URL or any other name with .html extsn like for ex hostname:port/warname/abc.html my app runs fine. Can you please advise why it is not running without index.html.
Answer to your question has got to do something with the accepted answer in this thread
How does Tomcat find the HOME PAGE of my Web App?
Simply put, Under WEB-INF/web.xml a home page has to be defined, if nothing is defined then what ever is defined in TOMCAT_HOME/conf/web.xml file will be considered as home page by tomcat server
so in your case I think you did not define a specific home page in WEB-INF/web.xml, that is why tomcat was searching for index.html page which is as per default configuration but index.html is not available to tomcat, so you were seeing 404 error. As soon as you put index.html file there then everything started to work for you

Where to get deployed service and generated wsdl using websphere

I am using WebSphere to publish my service as a web service using #WebService annotation in eclipse.
Details of the server :
Product name: WebSphere Application Server
Product Version: 17.0.0.2
Product edition: BASE_ILAN
While deploying the project on the server, the project started successfully and now I wanted to see the generated WSDL through admin console(as I do in Glassfish).But I am not finding any way to view the admin console or any directory which is having the generated WSDL(I am using mac os)
However, I can see(in eclipse) my service is deployed successfully, see attached image:
Thanks in advance.
As far as I know it's not available in the admin center however you can retrieve it from the service using a web browser.
Look in messages.log to find the context root of your webservices app, you'll see something like:
Web application available (default_host): http://localhost:29080/hello_jaxws/
Then to find the service you might need to know a bit about the service. If the name of the service isn't in an #WebService annotation, and the class isn't remapped in web.xml, then it's the name of the class + "Service". So in my case the name of the class is HelloService, so the url to my service is
http://localhost:29080/hello_jaxws/HelloServiceService
A browser should return
Hello! This is a CXF Web Service from that url.
Finally, add ?wsdl to it to get the wsdl
http://localhost:29080/hello_jaxws/HelloServiceService?wsdl
You can find it also when you navigate to {your service} -> Service providers -> {your service} -> WSDL document (from additional properties).
Look there for "soap:address" element, and copy the "location" value/address to your browser with anding "?wsdl" to the end of it.

An address of a website deployed using Tomcat and Eclipse

I'm trying to run a website using Tomcat and Eclipse. I created a Dynamic Web Project, I configured web.xml file and I also used Maven. In a directory src/main/webapp I put an index.html file. I also made a simple REST service in the same project. So this REST service is working for me (for example, when I put "http://localhost:8080/RESTfulService/rest/item" in an address bar. But what is the address that I should write to get an access to a website I put in a webapp folder? I thought "http://localhost:8080/RESTfulService/" should be working, but it's not.
From what i understand of your setup, try "http://localhost:8080/index.html". Do you have a context path called 'RESTfulService' setup?
Do you have a context element listed in your server.xml? If so, what does it say?

how to make my files present in a tomcat server to the browser

I have installed Tomcat 5.0 in order to execute a web application. How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
The simplest thing is to add to the root webapp. That is webapps/ROOT. Any file you put in there will be served unless you change the default configuration.
You should read about the details, of course.
I have installed Tomcat 5.0 in order to execute a web application.
First of all, why are you using the ancient (8 year old) Tomcat 5.0? If you can, rather grab the latest one, Tomcat 6.0.
How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
Is myfolder the context name or just a folder in your webcontent? If it's a context name, then you need to ensure that it's properly deployed. You can find details in the server logs in the /logs folder. If it is a folder in your webcontent and the webapplication is thus supposedly to be the "root" application, then you need to ensure that it's deployed as ROOT.
To learn more about using Tomcat, go through the documentation.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
To the point, just create a class which extends HttpServlet, implement the doPost() method, define the servlet in web.xml and let the action attribute of the HTML <form> element point to an URL which is covered by the url-pattern of the servlet mapping in the web.xml.
As the question is pretty broad, I have the impression that you haven't learned in any way how to work with Tomcat and JSP/Servlets. I would strongly recommend to go through those tutorials to familarize yourself with JSP/Servlet on Tomcat and Eclipse (an IDE) first: Beginning and Intermediate-Level Servlet, JSP, and JDBC Tutorials
Tomcat is not a web server like, say, Apache. It's a servlet container. You can not just move file in a subfolder which seem to be what you did. You need to pack your web application in a .war and deploy it.
The URL should rather be http://host:8080/webapp/subfolder/login.jsp
Without much information it's hard to help. Please edit your question and describe what you've done so far.

Categories

Resources