Package org.zaproxy.zap.extension.api
Class ApiImplementor
- java.lang.Object
-
- org.zaproxy.zap.extension.api.ApiImplementor
-
- Direct Known Subclasses:
ActiveScanAPI
,AlertAPI
,AntiCsrfAPI
,AuthenticationAPI
,AuthorizationAPI
,AutoUpdateAPI
,BreakAPI
,ContextAPI
,CoreAPI
,ForcedUserAPI
,HttpSessionsAPI
,KeyboardAPI
,ParamsAPI
,PassiveScanAPI
,ProxiesAPI
,RuleConfigAPI
,ScriptAPI
,SearchAPI
,SessionManagementAPI
,SpiderAPI
,StatsAPI
,UsersAPI
public abstract class ApiImplementor extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ApiImplementor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addApiAction(ApiAction action)
void
addApiOptions(AbstractParam param)
Adds the given options to the API implementor.void
addApiOthers(ApiOther other)
void
addApiPersistentConnection(ApiPersistentConnection pconn)
void
addApiShortcut(java.lang.String shortcut)
void
addApiView(ApiView view)
void
addCustomHeaders(java.lang.String name, API.RequestType type, HttpMessage msg)
Override to add custom headers for specific API operationsApiAction
getApiAction(java.lang.String name)
java.util.List<ApiAction>
getApiActions()
ApiOther
getApiOther(java.lang.String name)
java.util.List<ApiOther>
getApiOthers()
ApiPersistentConnection
getApiPersistentConnection(java.lang.String name)
java.util.List<ApiPersistentConnection>
getApiPersistentConnections()
protected java.util.List<java.lang.String>
getApiShortcuts()
ApiView
getApiView(java.lang.String name)
java.util.List<ApiView>
getApiViews()
java.lang.String
getDescriptionKey()
Gets the resource key of the description.protected java.lang.String
getI18nPrefix()
Gets the prefix for default resource keys for the description of the API implementor and its elements.protected boolean
getParam(net.sf.json.JSONObject params, java.lang.String name, boolean defaultValue)
protected int
getParam(net.sf.json.JSONObject params, java.lang.String name, int defaultValue)
protected long
getParam(net.sf.json.JSONObject params, java.lang.String name, long defaultValue)
protected java.lang.String
getParam(net.sf.json.JSONObject params, java.lang.String name, java.lang.String defaultValue)
abstract java.lang.String
getPrefix()
ApiResponse
handleApiAction(java.lang.String name, net.sf.json.JSONObject params)
Override if implementing one or more actionsApiResponse
handleApiOptionAction(java.lang.String name, net.sf.json.JSONObject params)
ApiResponse
handleApiOptionView(java.lang.String name, net.sf.json.JSONObject params)
HttpMessage
handleApiOther(HttpMessage msg, java.lang.String name, net.sf.json.JSONObject params)
Override if implementing one or more 'other' operations - these are operations that _dont_ return structured datavoid
handleApiPersistentConnection(HttpMessage msg, HttpInputStream httpIn, HttpOutputStream httpOut, java.lang.String name, net.sf.json.JSONObject params)
Override if implementing one or more 'persistent connection' operations.ApiResponse
handleApiView(java.lang.String name, net.sf.json.JSONObject params)
Override if implementing one or more viewsjava.lang.String
handleCallBack(HttpMessage msg)
Override if handling callbacksHttpMessage
handleShortcut(HttpMessage msg)
protected void
validateParamExists(net.sf.json.JSONObject parameters, java.lang.String name)
Validates that a parameter with the givenname
exists (and it has a value) in the givenparameters
.
-
-
-
Method Detail
-
getApiViews
public java.util.List<ApiView> getApiViews()
-
getApiActions
public java.util.List<ApiAction> getApiActions()
-
getApiOthers
public java.util.List<ApiOther> getApiOthers()
-
addApiView
public void addApiView(ApiView view)
-
addApiOthers
public void addApiOthers(ApiOther other)
-
addApiAction
public void addApiAction(ApiAction action)
-
addApiShortcut
public void addApiShortcut(java.lang.String shortcut)
-
addApiPersistentConnection
public void addApiPersistentConnection(ApiPersistentConnection pconn)
-
addApiOptions
public void addApiOptions(AbstractParam param)
Adds the given options to the API implementor.- Parameters:
param
- the options for the API- See Also:
ZapApiIgnore
-
handleApiOptionView
public ApiResponse handleApiOptionView(java.lang.String name, net.sf.json.JSONObject params) throws ApiException
- Throws:
ApiException
-
handleApiOptionAction
public ApiResponse handleApiOptionAction(java.lang.String name, net.sf.json.JSONObject params) throws ApiException
- Throws:
ApiException
-
handleApiView
public ApiResponse handleApiView(java.lang.String name, net.sf.json.JSONObject params) throws ApiException
Override if implementing one or more views- Parameters:
name
- the name of the requested viewparams
- the API request parameters- Returns:
- the API response
- Throws:
ApiException
- if an error occurred while handling the API view endpoint
-
handleApiAction
public ApiResponse handleApiAction(java.lang.String name, net.sf.json.JSONObject params) throws ApiException
Override if implementing one or more actions- Parameters:
name
- the name of the requested actionparams
- the API request parameters- Returns:
- the API response
- Throws:
ApiException
- if an error occurred while handling the API action endpoint
-
handleApiOther
public HttpMessage handleApiOther(HttpMessage msg, java.lang.String name, net.sf.json.JSONObject params) throws ApiException
Override if implementing one or more 'other' operations - these are operations that _dont_ return structured data- Parameters:
msg
- the HTTP message containing the API requestname
- the name of the requested other endpointparams
- the API request parameters- Returns:
- the HTTP message with the API response
- Throws:
ApiException
- if an error occurred while handling the API other endpoint
-
handleApiPersistentConnection
public void handleApiPersistentConnection(HttpMessage msg, HttpInputStream httpIn, HttpOutputStream httpOut, java.lang.String name, net.sf.json.JSONObject params) throws ApiException
Override if implementing one or more 'persistent connection' operations. These are operations that maintain long running connections, potentially staying alive as long as the client holds them open.- Parameters:
msg
- the HTTP message containing the API requesthttpIn
- the input streamhttpOut
- the output streamname
- the name of the requested pconn endpointparams
- the API request parameters- Throws:
ApiException
- if an error occurred while handling the API pconn endpoint
-
handleCallBack
public java.lang.String handleCallBack(HttpMessage msg) throws ApiException
Override if handling callbacks- Parameters:
msg
- the HTTP message containing the API request and response- Returns:
- the API response (set in the HTTP response body)
- Throws:
ApiException
- if an error occurred while handling the API callback
-
handleShortcut
public HttpMessage handleShortcut(HttpMessage msg) throws ApiException
- Throws:
ApiException
-
getPrefix
public abstract java.lang.String getPrefix()
-
getI18nPrefix
protected java.lang.String getI18nPrefix()
Gets the prefix for default resource keys for the description of the API implementor and its elements.Defaults to
getPrefix()
.- Returns:
- the prefix for i18n keys.
- Since:
- 2.10.0
-
getDescriptionKey
public java.lang.String getDescriptionKey()
Gets the resource key of the description.Defaults to
getI18nPrefix() + ".api.desc"
.- Returns:
- the key of the description.
- Since:
- 2.9.0
- See Also:
I18N.getString(String)
-
getApiAction
public ApiAction getApiAction(java.lang.String name)
-
getApiView
public ApiView getApiView(java.lang.String name)
-
getApiOther
public ApiOther getApiOther(java.lang.String name)
-
getApiShortcuts
protected java.util.List<java.lang.String> getApiShortcuts()
-
getApiPersistentConnection
public ApiPersistentConnection getApiPersistentConnection(java.lang.String name)
-
getApiPersistentConnections
public java.util.List<ApiPersistentConnection> getApiPersistentConnections()
-
getParam
protected int getParam(net.sf.json.JSONObject params, java.lang.String name, int defaultValue)
-
getParam
protected long getParam(net.sf.json.JSONObject params, java.lang.String name, long defaultValue)
-
getParam
protected java.lang.String getParam(net.sf.json.JSONObject params, java.lang.String name, java.lang.String defaultValue)
-
getParam
protected boolean getParam(net.sf.json.JSONObject params, java.lang.String name, boolean defaultValue)
-
validateParamExists
protected void validateParamExists(net.sf.json.JSONObject parameters, java.lang.String name) throws ApiException
Validates that a parameter with the givenname
exists (and it has a value) in the givenparameters
.- Parameters:
parameters
- the parametersname
- the name of the parameter that must exist- Throws:
ApiException
- if the parameter with the given name does not exist or it has no value.- Since:
- 2.6.0
-
addCustomHeaders
public void addCustomHeaders(java.lang.String name, API.RequestType type, HttpMessage msg)
Override to add custom headers for specific API operations- Parameters:
name
- the name of the operationtype
- the type of the operationmsg
- the HTTP response message to the API request
-
-