Comments (5)
I can get the response message with the same client but with another server implemented as @managedservice just as the sample Chat.
So I have to implement the same as the Chat server? What if I have to reuse the same server used by the js client.
from wasync.
It should work, so I'm not sure what is the issue. Can you share a test case?
from wasync.
Also, can you use the mailing list for such question? One recommendation is can you try the sample's chat and see if it works for you? Thanks for your help!
from wasync.
Sorry for the inconvenience, I wrote a test case and the problems seems caused by Jackson. I will use the mailing list in the future. Test case sample attached, in case anyone else run into the same issue.
public final static class POJO3{ public String name; public List<String> books; public POJO3(String name, List<String> books){ this.name = name; this.books = books; } public POJO3(){ //Without this empty constructor, jackson will fail the test case } } @Test public void basicDecoderTest2() throws Exception { final CountDownLatch l = new CountDownLatch(1); final ObjectMapper mapper = new ObjectMapper(); Config config = new Config.Builder() .port(port) .host("127.0.0.1") .resource("/suspend", new AtmosphereHandler() { private final AtomicBoolean b = new AtomicBoolean(false); @Override public void onRequest(AtmosphereResource r) throws IOException { if (!b.getAndSet(true)) { r.suspend(-1); } else { String message = r.getRequest().getReader().readLine(); r.getBroadcaster().broadcast(mapper.writeValueAsString(new POJO3(message, Lists.newArrayList("test")))); } } @Override public void onStateChange(AtmosphereResourceEvent r) throws IOException { if (!r.isResuming() || !r.isCancelled()) { r.getResource().getResponse().getWriter().print(r.getMessage()); r.getResource().resume(); } } @Override public void destroy() { } }).build(); server = new Nettosphere.Builder().config(config).build(); assertNotNull(server); server.start(); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference response = new AtomicReference(); Client client = ClientFactory.getDefault().newClient(); RequestBuilder request = client.newRequestBuilder() .method(Request.METHOD.GET) .uri(targetUrl + "/suspend") .decoder(new Decoder() { @Override public POJO3 decode(Event e, String s) { if (e.equals(Event.MESSAGE)) { try { return mapper.readValue(s, POJO3.class); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return null; } } return null; } }) .transport(transport()); Socket socket = client.create(); socket.on(Event.MESSAGE.name(), new Function() { @Override public void on(POJO3 t) { response.set(t); latch.countDown(); } }).open(request.build()).fire("echo"); latch.await(10, TimeUnit.SECONDS); assertNotNull(response.get()); assertEquals(response.get().getClass(), POJO3.class); socket.close(); }
from wasync.
Thanks for the test case, always appreciated.
from wasync.
Related Issues (20)
- Documentation link broken HOT 1
- WebSocketTransport - are ignoring the first text frame HOT 2
- TrackMessageSizeDecoder is aborting messages that contain "__" in the body
- NPE: scheme when opening the socket HOT 1
- reconnect with long-polling transport
- Bug in TransportsUtil.java HOT 5
- Simple HTTP pooling
- Not able to receive some specific data on Android wAsync client HOT 1
- Issue with QueryParams - string becomes too long after a number of reconnect attempts HOT 4
- Update to latest Netty HOT 2
- Exception on Socket.close()
- Nullpointer exception in atmosphere runtime 2.0.3 version HOT 1
- travis CI fails with dist: not set to trusty
- Fix build status banner to point to travis-ci.
- SSLv2Hello HandshakeException
- java.io.IOException: Connection Error 200
- Can Atmosphere be used for persistent connection from behind the firewall?
- Incomplete padding messages are propagated to message Function<String> with long-polling
- StreamTransport triggers Event.REOPENED after each message when protocol is enabled HOT 3
- Closing and reopening a connection which is reconnecting ends up with two connections
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasync.