Waiker AI Original Text Linking Method
Source Text: The raw data received by Waiker
Waiker AI Original Text: The state in which analysis, tagging, translation, summarization, and other processing of the source text by AI is completed.
The AI WebSocket can be used with any of the following keys: Widget, DataSet, or Ws.
The WebSocket provided by Waiker uses the STOMP format.
Here is a brief explanation with example code in Spring Boot and Kotlin.
package com.example.demo
import com.example.demo.client.StompClient
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.runApplication
import org.springframework.messaging.simp.stomp.StompHeaders
import org.springframework.web.socket.WebSocketHttpHeaders
@SpringBootApplication(exclude = [DataSourceAutoConfiguration::class])
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
val productKey = "***********"
val authKey = "Bearer *****************"
val destination = "/news/us"
val stompClient = StompClient()
val sessionHandler = StompClient.MyStompSessionHandler(
productKey = productKey,
authKey = authKey,
destination = destination
)
val connectHeader = WebSocketHttpHeaders()
connectHeader["Waiker-Product-Key"] = productKey
connectHeader["Authorization"] = authKey
connectHeader["Sec-Websocket-Protocol"] = "v12.stomp, v11.stomp, v10.stomp"
connectHeader["host"] = "oapi.waiker.ai"
connectHeader["accept-version"] ="13"
connectHeader["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
stompClient.connect("wss://oapi.waiker.ai/v2/center-ws", connectHeader, sessionHandler)
}
Here’s the English translation of the provided Markdown content:
markdown 코드 복사
id: 'waiker-ai-original-text-link' title: 'Waiker AI Original Text Linking Method' description: 'Method for linking original text in Waiker AI' sidebar_label: 'Waiker AI Original Text Linking Method' hide_table_of_contents: true info_path: docs/waiker_center_docs/ai-news-1 custom_edit_url: null show_extensions: true
Source Text: The raw data received by Waiker
Waiker AI Original Text: The state in which analysis, tagging, translation, summarization, and other processing of the source text by AI is completed.
The AI WebSocket can be used with any of the following keys: Widget, DataSet, or Ws.
The WebSocket provided by Waiker uses the STOMP format.
Here is a brief explanation with example code in Spring Boot and Kotlin.
package com.example.demo
import com.example.demo.client.StompClient
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.runApplication
import org.springframework.messaging.simp.stomp.StompHeaders
import org.springframework.web.socket.WebSocketHttpHeaders
@SpringBootApplication(exclude = [DataSourceAutoConfiguration::class])
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
val productKey = "***********"
val authKey = "Bearer *****************"
val destination = "/news/us"
val stompClient = StompClient()
val sessionHandler = StompClient.MyStompSessionHandler(
productKey = productKey,
authKey = authKey,
destination = destination
)
val connectHeader = WebSocketHttpHeaders()
connectHeader["Waiker-Product-Key"] = productKey
connectHeader["Authorization"] = authKey
connectHeader["Sec-Websocket-Protocol"] = "v12.stomp, v11.stomp, v10.stomp"
connectHeader["host"] = "oapi.waiker.ai"
connectHeader["accept-version"] ="13"
connectHeader["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
stompClient.connect("wss://oapi.waiker.ai/v2/center-ws", connectHeader, sessionHandler)
}
- The authentication key must be included in the headers when connecting using stompClient.
- The Sec-Websocket-Protocol contains the necessary data for the STOMP header.
- After connecting, afterConnected in the StompClient's SessionHandler is called, triggering session.subscribe.
- Authentication header values are also needed when subscribing.
- When subscribing, headers for destination, product-key, and auth are required.
package com.example.demo.client
import org.springframework.messaging.converter.MappingJackson2MessageConverter
import org.springframework.messaging.simp.stomp.*
import org.springframework.stereotype.Component
import org.springframework.web.socket.WebSocketHttpHeaders
import org.springframework.web.socket.client.standard.StandardWebSocketClient
import org.springframework.web.socket.messaging.WebSocketStompClient
import java.lang.reflect.Type
@Component
class StompClient {
private lateinit var stompClient: WebSocketStompClient
init {
val websocketClient = StandardWebSocketClient()
stompClient = WebSocketStompClient(websocketClient)
stompClient.messageConverter = MappingJackson2MessageConverter()
}
fun connect(url: String, headers: WebSocketHttpHeaders, sessionHandler: StompSessionHandler): StompSession {
val connectFuture = stompClient.connect(url, headers, sessionHandler)
return connectFuture.get()
}
class MyStompSessionHandler(
private val productKey: String,
private val authKey: String,
private val destination: String
) : StompSessionHandlerAdapter() {
override fun afterConnected(session: StompSession, connectedHeaders: StompHeaders) {
println("Connected to STOMP server")
val headers = StompHeaders()
headers["destination"] = destination
headers["Waiker-Product-Key"] = productKey
headers["Authorization"] = authKey
session.subscribe(headers, this)
}
override fun getPayloadType(headers: StompHeaders): Type {
return String::class.java
}
override fun handleFrame(headers: StompHeaders, payload: Any?) {
println("Received: $payload")
}
override fun handleTransportError(session: StompSession, exception: Throwable) {
println("Transport error: ${exception.message}")
}
override fun handleException(
session: StompSession,
command: StompCommand?,
headers: StompHeaders,
payload: ByteArray,
exception: Throwable
) {
println("Error: ${exception.message}")
}
}
}