Web Service Java in Openshift using Tomcat 6 (Jboss EWS 1.0)

Asked

Viewed 476 times

2

I’m trying to create a Web Service in JAVA so it can be consumed by an Android application. I need to use a Cloud technology, and only found the free Openshift and best recommended for now... Well, I already created my project in Eclipse. I already have all the tools. I already sent the project to Openshift, etc. The problem is this: (Note: I am beginner)

I created a connection class with the database:

package conectaMySql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConectaMySql {

    private static final String URL = "link do MySql dado pela OpenShift";
    private static final String USER = "login do MySql dado pela OpenShift";
    private static final String SENHA = "senha do MySql dada pela OpenShift";

    public static Connection obterConexao() throws SQLException{

        try{
            Class.forName("com.mysql.jdbc.Driver");     
        }
        catch(ClassNotFoundException e){
            e.printStackTrace();
        }
        return DriverManager.getConnection(URL, USER, SENHA);
    }
}

I created another class with the following data:

package classesDao;

import java.sql.Connection;
import java.sql.PreparedStatement;

import classes.*;
import conectaMySql.*;

public class AdministradorDao {

    public boolean insertAdmin(Administrador admin){

        try {
            Connection conn = ConectaMySql.obterConexao();

            String queryInserir = "INSERT INTO Administrador VALUES (?, ?)";

            PreparedStatement ppStm = conn.prepareStatement(queryInserir);

            ppStm.setString(1, admin.getLogin());
            ppStm.setString(2, admin.getSenha());

            ppStm.executeUpdate();

            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }

}

Disregarding the concept of MVC, rsrsrs... How can I make this class available as a service? I researched a lot on the internet, but I don’t know very well English (I know I’m chipped, and the translation tool helped me a lot), but unfortunately I didn’t find anything concrete. I saw some things about web.xml, etc... But I’m still in the dark! And now, who can help me?

  • I just want my wsdl :(

  • You want to expose your DAO as a SOAP service, that’s it?

  • exactly that! I saw that I need to configure some xml, but I did not succeed, rsrs..

  • Needs to be SOAP?

  • Jedaias, why don’t you make a Webservice REST using the JAX-RS API? It’s very simple, it will only depend on what implementation the server has, or you can embark on your project, be it Resteasy or for example Jersey.

1 answer

1

Whether it’s Openshift or any other environment, you need to make your implementation available using some SOAP protocol implementation.

The library Apache Axis2 is the most used on the market. Even with Eclipse WTP (Web Tools Platform plugin), you can create and edit a WSDL and then generate the classes stub to implement your web service. Then you need to publish it as a web application. There is no way I can do a tutorial here, but there are several tutorials that you can find around.

Another option is to use the Spring Boot, that I believe will make your life easier. Spring Boot is a relatively new Spring Framework project that works heavily with the concept of Convention on Configuration (Coc - Convention over Configuration), and it generally shortens and greatly simplifies the setup of the project.

However, regardless of the option, it is important that you study and understand what you are doing, because even for something simple you will need to know a little about the architecture of a web project and where to implement each method.

An important tip is that in a project, and especially one that involves cloud, you should never open a connection manually as you are doing in this project. Use a framework like Spring to manage your data sources or a library of Connection pool, for example.

  • Thanks for helping my friend. But I was trying to use Apache Axis2 in Openshift and I couldn’t, I’ll take another look here.

  • Dude, I managed to create a local Webservice using Apache Axis2 and make a WSDL available, the problem is to put it in Openshift.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.