Web Service Java on OpenShift using Tomcat 6 (JBoss EWS 1.0)

2

I'm trying to create a Web Service in JAVA to be consumed by an Android application. I need to use a Cloud technology, and only found OpenShift free and best recommended for now ... Well, I've already created my project in Eclipse. I already have all the tools. I already sent the project to OpenShift, etc. The problem is as follows: (Note: I'm a 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 MVC concept, lol ... How can I make this class available as a service? I researched a lot on the internet, but I do not handle English very well (I know I'm chipped, and the translation tool helped me damn good), but unfortunately I did not find anything concrete. I saw some things about web.xml, etc ... But I'm still in the dark! And now, who can help me?

    
asked by anonymous 31.03.2015 / 05:02

1 answer

1

Whether it's OpenShift or any other environment, you need to make your implementation available using some SOAP implementation.

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

Another option is to use Spring Boot , which I believe will make your life easier. Spring Boot is a relatively new Spring Framework project that works strongly with the Convention over Configuration (CoC) concept, and it generally shortens and greatly simplifies the project's setup / p>

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 that project. Use a framework like Spring to manage your data sources or a connection pool library, for example.

    
31.03.2015 / 16:00