-
1. Re: There are no proxy providers registered yet
csa Jan 27, 2013 3:42 PM (in response to isyl)1 of 1 people found this helpfulHi,
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:
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 Jan 28, 2013 3:36 PM (in response to csa)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:
and on the server-side :
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
csa Jan 28, 2013 3:46 PM (in response to isyl)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 Jan 28, 2013 4:16 PM (in response to csa)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
csa Jan 28, 2013 4:31 PM (in response to isyl)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 Jan 28, 2013 4:51 PM (in response to csa)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
csa Jan 28, 2013 5:16 PM (in response to isyl)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 Jan 28, 2013 5:45 PM (in response to csa)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");