Webservice consumed via servlet error 500 JBoss AS 7

2

Talk, guys!

I have a project, which I decided to split in two: a core and a web. The core uses CDI with all persistence and business rules, exposing its functionality via REST and JSon webservices. Already the web project is just the html, with bootstrap and angular. "Because you have decided to do so, your beast," someone might ask. Because if, later, I resolve to make a mobile app, just consume the existing webservices. I thought it was more practical.

First of all, I point out that I use JBoss AS 7, both in development environment and production environment.

Well, locally, everything is working, when I sent it to the hosting provider, everything worked fine too. The angular calls the webservices, updates database and everything. A real beauty! But since everything is not flowers in this life, the circumstance of having to upload a text file appeared. That's when my sadness began.

I researched how to do angular and found it very complicated. I decided to do with a servlet in my same web project. The user submits the file, the servlet receives it, treats it and, to record the client record, triggers a specific webservice for that, existing in the core project.

I hope I have been clear in my intention.

Locally, my machine works. Gives a dick in the production environment, there at the provider. What happens is that, at the time of consuming the webserver of the core inside the servlet, I receive error 500 with this stacktrace:

java.net.UnknownHostException: <<www.nomedomeusite.com.br>>
    java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    java.net.Socket.connect(Socket.java:579)
    java.net.Socket.connect(Socket.java:528)
    sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    sun.net.www.http.HttpClient.New(HttpClient.java:308)
    sun.net.www.http.HttpClient.New(HttpClient.java:326)
    sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    br.com.bonysoft.servlet.FileUploadServlet.doPost(FileUploadServlet.java:205)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

Everything else, the recordings, readings and navigation work (including those that use the webservice of the core, via angular). Just the call to the webservice coming from the upload servlet will return this error. Look at the code:

HTML:

<div class="container" >

    <form name="form1" id="form1" action="servletUpload" method="post" enctype="multipart/form-data">

        <div class="container col-md-12 col-lg-12" style="padding-top: 20px; margin-bottom: 20px;">

            <div class="panel panel-default">

                <div class="panel-heading">
                    <h3 class="panel-title">IMPORTAÇÃO DE PLANILHA DE CLIENTES</h3>
                </div>

                <div class="panel-body">
                    <input type="file" size="150" name="file1" id="idfile1" style="width: 100%;">                           
                </div>

            </div>

        </div>


        <div class="form-group">
            <button type="submit" class="btn btn-primary" >Confirmar upload</button>
            <button type="button" class="btn btn-primary" ng-click="desistir();">Desistir da operação</button>
        </div>

    </form>


</div>

FILE TREATMENT SERVLET:

String uri = "http://www.meudominio.com.br/cliente/uploadCliente/fulano/[email protected]/fone1/fone2";

URL url = new URL(uri);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "*/*");

InputStream xml = connection.getInputStream();

String ret = xml.toString();

connection.disconnect();       

RELEVANT WEB SERVICE REST CODE EXPOSED

@GET
@Path("cliente/uploadCliente/{nome}/{email}/{fone1}/{fone2}")
public void uploadCliente(
        @PathParam("nome") String nome,
        @PathParam("email") String email,
        @PathParam("fone1") String fone1,
        @PathParam("fone2") String fone2) throws Exception {


    Cliente cliente = new Cliente();
        cliente.setEmail(email);
        cliente.setFoneResidencial(fone1);
        cliente.setFoneComercial(fone2);
        cliente.setNome(nome);

        clienteDAO.gravar(cliente);

        entityManager.flush();

 }

Since this whole idea works locally and only happens when running on JBoss from my hosting, I'm pretty sure it's some JBoss configuration. Some security parameter, I do not know.

If anyone has any ideas, thank you very much.

Hugs to all

    
asked by anonymous 23.05.2015 / 03:06

1 answer

1

As I understand, your application is making a WS call to an unknown host.

The WS address that will be accessed by your Servlet must be exactly the address you would access using a browser for example. The API will perform a remote call, regardless if it is on the same host ...

    
12.11.2015 / 23:40