Webservice consumed via Servlet error 500 Jboss AS 7

Asked

Viewed 206 times

2

Talk, you guys!

I have a project, which I decided to divide in two: a core and a web. The core uses CDI with all rules of persistence and business, exposing its functionality via REST and Json webservices. The web project is just html, with bootstrap and angular. "Because you decided to do so, your animal", someone may ask. Because if, later on, I decide to make a mobile app, just consume the existing webservices. I found it more practical.

First of all, I stress that I use the Jboss AS 7, both in development and production environment.

Well, locally, everything is working, when I sent to the hosting provider, everything worked beauty too. Angular calls the webservices, updates database and everything. A real beauty! But, as not everything is flowers in this life, the circumstance of needing to upload a text file appeared. That’s when my sadness began.

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

I hope I’ve been clear in my intention.

Locally, my machine works. It works well in the production environment, there at the provider. What happens is that when consuming the core webserver inside Servlet, I get a 500 error 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)

All the rest, the recordings, readings and navigation work (including those that use the core webservice, via angular). Only the call to the webservice from the upload server returns this error. See 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 HANDLING 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

@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 all this idea works locally and only happens when running in Jboss of my hosting, I’m almost sure it is some configuration of Jboss. Some kind of security drill, I don’t know.

If anyone has any ideas, I strongly appreciate.

Hug to all

  • Do you know the IP of the server on which the Wss are deployed? If so, have you tried with the IP? If it is the same server for both projects, have you used localhost or 127.0.0.1?

1 answer

1

As I understand it, your application is calling WS for an unknown host.

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

Browser other questions tagged

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