8 Replies Latest reply: Jan 28, 2013 5:45 PM by isyl RSS

There are no proxy providers registered yet

isyl Newbie

Hello i am new to Errai, i am training on a small project (according to the "Getting started" section of https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS) and i have the following issue :

 

issue.jpg

 

I have seen in another topic that it can be caused by the ErraiApp.properties file. I created one and put it in several directories but it still doesn't work. Where do i have to put it ?

directory.jpg

 

Front_End.gwt.xml

<module rename-to="front_end" >

    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.google.gwt.http.HTTP" />
    <inherits name="com.google.gwt.xml.XML" />

    <inherits name="org.jboss.errai.enterprise.Jaxrs" />
    <inherits name="org.jboss.errai.bus.ErraiBus" />
    <inherits name="org.jboss.errai.common.ErraiCommon"/>

    <entry-point class="com.ald.front.client.Front_End" />


    <source path="client" />
    <source path="shared" />

</module>

 

Front_end.java

 

public class Front_End implements EntryPoint {

    public void onModuleLoad() {

       Connexion connexion = new Connexion("azerty", "azerty");

       ResponseCallback callback = new ResponseCallback() {
            public void callback(Response response) {
                Window.alert("HTTP status code: " + response.getStatusCode());
                Window.alert("HTTP response body: " + response.getText());
            }
        };

        RestClient.create(MuseeService.class, callback).connection(connexion);
     }
}

 

MuseeService.java

 

@Path("/service")
public interface MuseeService {

    @POST
    @Path("/connexion")
    @Produces("application/xml")
    public String connexion(Connexion connexion);

}

 

 

 

I have also implemented CORS on the server-side.

 

Any help would be appreciated. Thx in advance

 

 

  • 1. Re: There are no proxy providers registered yet
    Christian Sadilek Master

    Hi,

     

    ErraiApp.properties should go into the root of your source or resource folder (src/main/java or src/main/resources).

     

    Also, using Errai you don't need to specify the EntryPoint in your gwt.xml and implement the EntryPoint interface. You can just annotate your class with @EntryPoint, and use a @PostConstruct method (or @AfterInitializiation if you use Errai bus) .

     

    Here's an example:

    https://github.com/errai/errai/blob/master/errai-jaxrs/demos/jaxrs-demo/src/main/java/org/jboss/errai/samples/restdemo/client/local/App.java

     

    We also have a maven archetype that sets up a working Errai JAX-RS project (your project looks fine though except for the missing ErraiApp.properties):

    https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS+Maven+Archetype

     

    Cheers,

    Christian

  • 2. Re: There are no proxy providers registered yet
    isyl Newbie

    Hi Christian, thank you for the answer.

     

    I have resolved the problem placing ErraiApp.properties in the right directory and adding

    <dependency>
          <groupId>org.jboss.errai</groupId>
          <artifactId>errai-ioc</artifactId>
    </dependency>
    

    in my pom.xml

     

     

    I can't reach the server (here is what i get with Firebug), i have a Same Origin Policy issue:

    reach_server.png

    and on the server-side :

    reach_server2.png

     

    i have implemented CORS on the server side yet:

    RESTInterceptor.java

     

    @Provider
    @ServerInterceptor
    //@Precedence("HEADER_DECORATOR")
    public class RestInterceptor implements MessageBodyWriterInterceptor {
    
        private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RestInterceptor.class);    
        
        public void write(MessageBodyWriterContext context) throws IOException,
        WebApplicationException {
            context.getHeaders().add("ACCESS_CONTROL_ALLOW_ORIGIN", "*");
            context.proceed();
        }
    }
    

     

    and web.xml

     

    <context-param>
          <param-name>resteasy.providers</param-name>
          <param-value>com.ald.service.RestInterceptor</param-value>
    </context-param>
    

     

    I don't don't even reach the "write" function.

     

    I don't know if this is the right place to ask this question, but how can i resolve it ?

    Thx again

     

     

     

  • 3. Re: There are no proxy providers registered yet
    Christian Sadilek Master

    Hi,

     

    The errors in the Firebug screenshot you pasted stem from Errai Bus remote requests. These are *not* requests originating from your JAX-RS client. You can deactivate remote communication in Errai Bus:

    https://docs.jboss.org/author/display/ERRAI/Client+Configuration

     

    In Errai 3, simply not inherting the errai bus module is enough, in 2.x you need to deactivate bus remote communication if you don't want it.

     

    If you do intend to use Errai Bus, you need to make sure that errai-bus.jar is deployed on your server and that the bus endpoint URL is set in case it's on a different server (see URL above).

     

    Christian

  • 4. Re: There are no proxy providers registered yet
    isyl Newbie

     

     

    That made it

     

    I have just one last question and it's perfect .. if someone has an idea

     

     

    This is my REST service on server side

    @POST
    @Path("/connexion")
    public Response connection(Connexion connexion){ 
            String status = connexionDAO.isValidConnexion(connexion);
            return Response.ok(status).build();
        }
    

     

     

    when i call it with :

     

     

            Connexion connexion = new Connexion("azerty", "azerty");
    
            ResponseCallback callback = new ResponseCallback() {
                public void callback(Response response) {
                    Window.alert("HTTP status code: " + response.getStatusCode());
                    Window.alert("HTTP response body: " + response.getText());
                }
            };
      
            RestClient.setApplicationRoot("proxy.jsp?url=http://localhost:8080/rest");
            RestClient.create(MuseeService.class, callback).connection(connexion);
    

     

     

    I get the error :

    org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class com.ald.backend.Connexion of content type: application/x-www-form-urlencoded

     

     

    "class com.ald.backend.Connexion" is the Connexion class in the back end.

    Serialized connexion object in the POST request cannot be unmarshalled? isn't it supposed to be in JSON format instead of application/x-www-form-urlencoded ?

  • 5. Re: There are no proxy providers registered yet
    Christian Sadilek Master

    For Errai, your Connexion class needs to be marked as portable using either the @Portable annotation or a configuration in ErraiApp.properties.

     

    The rest is server-side. You have 2 options here. You can either use Errai's JSON format or Jackson. For Errai JSON you will need to deploy the errai-jaxrs-provider which registers a MessageBodyReader/Writer with RestEasy. For Jackson, you need to make sure the RestEasy jackson-provider is deployed.

     

    You can control the content-type on your JAX-RS interface using @Consumes and @Produces.

     

    More details if needed: https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS#ErraiJAX-RS-GettingStarted and https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS#ErraiJAX-RS-Configuration

     

    Cheers,

    Christian

  • 6. Re: There are no proxy providers registered yet
    isyl Newbie

    Yes my connexion class is already marked as Portable.

    I removed @Consumes(application/json)  annotation because it tells "Cannot consume content type" as it is application/x-www-form-urlencoded.

    I also use Errai's JSON format.

     

     

  • 7. Re: There are no proxy providers registered yet
    Christian Sadilek Master

    OK, you will definitely need the @Consumes(application/json). Errai sets the headers based on @Consumes and @Produces. So, it will not just set application/x-www-from-urlencoded. You should see the correct request headers in Firebug. Maybe something changes the headers in between (e.g some proxy)?

  • 8. Re: There are no proxy providers registered yet
    isyl Newbie

    it confirms what I thought, it's my proxy (used to avoid Same Origin Policy).

     

    Here is my proxy :

     

     

    <%@page import="javax.naming.Context"%>
    <%@page import="javax.naming.InitialContext"%><%@page session="false"%>
    <%@page import="java.net.*,java.io.*" %>
    
    <%
    try {
        String reqUrl = request.getQueryString();
        URL url = new URL(reqUrl.substring(4));
    
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod(request.getMethod());
        int clength = request.getContentLength();
        if (clength > 0) {
            con.setDoInput(true);
            byte[] idata = new byte[clength];
            request.getInputStream().read(idata,0,clength);
            con.getOutputStream().write(idata,0,clength);
        }
        response.setContentType(con.getContentType());
        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            out.println(line);
        }
        rd.close();
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatus(500);
        }
    %>
    

     


    RestClient.setApplicationRoot("proxy.jsp?url=http://localhost:8080/rest");