Skip to content

Commit 324d0e8

Browse files
committed
Add websocket API
Add the API of WebSockets add-on (version 15).
1 parent d1dc484 commit 324d0e8

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Summary of the changes done in each version.
88

99
- Explicitly disable HTTP caching, to always obtain a fresh response from ZAP.
1010

11+
### New APIs
12+
13+
- WebSockets ("websocket").
14+
1115
## 1.5.0 (2017-11-30)
1216

1317
### Updated APIs

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.zaproxy.clientapi.gen.Spider;
7373
import org.zaproxy.clientapi.gen.Stats;
7474
import org.zaproxy.clientapi.gen.Users;
75+
import org.zaproxy.clientapi.gen.Websocket;
7576

7677
public class ClientApi {
7778

@@ -117,6 +118,7 @@ public class ClientApi {
117118
public Spider spider = new Spider(this);
118119
public Stats stats = new Stats(this);
119120
public Users users = new Users(this);
121+
public Websocket websocket = new Websocket(this);
120122

121123
public ClientApi(String zapAddress, int zapPort) {
122124
this(zapAddress, zapPort, false);
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Zed Attack Proxy (ZAP) and its related class files.
3+
*
4+
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
5+
*
6+
* Copyright 2018 The ZAP Development Team
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.zaproxy.clientapi.gen;
21+
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
import org.zaproxy.clientapi.core.ApiResponse;
25+
import org.zaproxy.clientapi.core.ClientApi;
26+
import org.zaproxy.clientapi.core.ClientApiException;
27+
28+
/** This file was automatically generated. */
29+
@SuppressWarnings("javadoc")
30+
public class Websocket {
31+
32+
private final ClientApi api;
33+
34+
public Websocket(ClientApi api) {
35+
this.api = api;
36+
}
37+
38+
/**
39+
* Returns all of the registered web socket channels
40+
*
41+
* <p>This component is optional and therefore the API will only work if it is installed
42+
*/
43+
public ApiResponse channels() throws ClientApiException {
44+
return api.callApi("websocket", "view", "channels", null);
45+
}
46+
47+
/**
48+
* Returns full details of the message specified by the channelId and messageId
49+
*
50+
* <p>This component is optional and therefore the API will only work if it is installed
51+
*/
52+
public ApiResponse message(String channelid, String messageid) throws ClientApiException {
53+
Map<String, String> map = new HashMap<>();
54+
map.put("channelId", channelid);
55+
map.put("messageId", messageid);
56+
return api.callApi("websocket", "view", "message", map);
57+
}
58+
59+
/**
60+
* Returns a list of all of the messages that meet the given criteria (all optional), where
61+
* channelId is a channel identifier, start is the offset to start returning messages from
62+
* (starting from 0), count is the number of messages to return (default no limit) and
63+
* payloadPreviewLength is the maximum number bytes to return for the payload contents
64+
*
65+
* <p>This component is optional and therefore the API will only work if it is installed
66+
*/
67+
public ApiResponse messages(
68+
String channelid, String start, String count, String payloadpreviewlength)
69+
throws ClientApiException {
70+
Map<String, String> map = new HashMap<>();
71+
if (channelid != null) {
72+
map.put("channelId", channelid);
73+
}
74+
if (start != null) {
75+
map.put("start", start);
76+
}
77+
if (count != null) {
78+
map.put("count", count);
79+
}
80+
if (payloadpreviewlength != null) {
81+
map.put("payloadPreviewLength", payloadpreviewlength);
82+
}
83+
return api.callApi("websocket", "view", "messages", map);
84+
}
85+
86+
/**
87+
* Sends the specified message on the channel specified by channelId, if outgoing is 'True' then
88+
* the message will be sent to the server and if it is 'False' then it will be sent to the
89+
* client
90+
*
91+
* <p>This component is optional and therefore the API will only work if it is installed
92+
*/
93+
public ApiResponse sendTextMessage(String channelid, String outgoing, String message)
94+
throws ClientApiException {
95+
Map<String, String> map = new HashMap<>();
96+
map.put("channelId", channelid);
97+
map.put("outgoing", outgoing);
98+
map.put("message", message);
99+
return api.callApi("websocket", "action", "sendTextMessage", map);
100+
}
101+
}

0 commit comments

Comments
 (0)