ไม่พบตัวเข้ารหัสที่เหมาะสม (java websocket)

ฉันมีปัญหาบางอย่าง ฉันพยายามเขียนเว็บแอปพลิเคชันด้วย websockets สำหรับการสตรีมข้อมูล มันยังไม่พร้อม แต่ฉันกำลังดำเนินการอยู่ ฉันพยายามส่งสตริงเซิร์ฟเวอร์ของฉันและเซิร์ฟเวอร์ควรส่งข้อความกลับมาพร้อมกับ UUID ฉันเพิ่งส่ง UUID ด้วย

session.getBasicRemote().sendText(uuid.tostring())

ใช้งานได้ดี แต่ตอนนี้ฉันพยายามส่งแผนที่เพื่อให้สามารถส่ง UUID และ String เข้าด้วยกันโดยใช้

session.getBasicRemote().sendObject(map);

แต่ตอนนี้ไคลเอนต์ JS ของฉันไม่ได้รับข้อมูลที่ฉันพยายามส่งเซิร์ฟเวอร์ของฉันทำให้เกิดข้อยกเว้น

javax.websocket.EncodeException: ไม่พบตัวเข้ารหัสที่เหมาะสม

ฉันไม่รู้ว่าจะแก้ไขปัญหานี้อย่างไร

รหัสเจเอส

var websocket;
$(document).ready(function(){
    websocket = new WebSocket("ws://localhost:8080/TimeStreamingTestartID-1.0-SNAPSHOT/websockets/simplestockmarket")

    websocket.onopen = function(){ 
    alert("SUCESS: REGISTERED!!");
    }

$("#tblcontainer").html('<table id="tableID" class="table table-bordered" ><thead><tr><th>Identification</th><th>Text</th></tr></thead></table>')
$("#start").click(function(){

    websocket.send("Test")
    websocket.onmessage = function(erg){ 
    $("#tableID").append('<tr><td>'+"1"+'</td><td>'+erg+'</td></tr>')
    console.log(erg);
    }

});
});

วิธี java onMessage ของฉัน

    @OnMessage
public void message(Session session,String message) throws IOException {
    UUID uuid = UUID.randomUUID();
    Map map = new HashMap<>();
    map.put(uuid,message);

    try {
        session.getBasicRemote().sendObject(map);
    } catch (EncodeException e) {
        e.printStackTrace();
    }
}

person alovaros    schedule 06.08.2015    source แหล่งที่มา


คำตอบ (1)


จุดสิ้นสุดเซิร์ฟเวอร์ของคุณมีลักษณะอย่างไร คุณมีคำอธิบายประกอบนี้อยู่ด้านบนหรือไม่?

@ServerEndpoint(value="/whatever", encoders = {MessageEncoder.class}, decoders = {MessageDecoder.class}) 
public class MessageService {

    @OnMessage
    public void message()...
}
person darijan    schedule 06.08.2015
comment
@ServerEndpoint("/websockets/simplestockmarket") public class SimpleStockMarketWSServerEndpoint ดูเหมือนว่าในขณะนี้พยายามเขียนเหมือนคุณ แต่ไม่มี MessageEncoder - person alovaros; 06.08.2015
comment
ถ้าคุณไม่มีก็นำเข้าโถ - person darijan; 06.08.2015
comment
ถ้าบอกชื่อขวดด้วยจะดีมาก :D - person alovaros; 06.08.2015
comment
ขออภัย คุณต้องเขียนของคุณเอง: บล็อก .idrsolutions.com/2013/12/ - person darijan; 06.08.2015
comment
ขอบคุณ :D ฉันจะลองหวังว่าทักษะของฉันจะเพียงพอที่จะเขียนได้ ฮ่าๆ - person alovaros; 06.08.2015