use of org.zaproxy.zap.extension.httppanel.Message in project zaproxy by zaproxy.
the class BreakAPI method handleApiAction.
@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
if (ACTION_BREAK.equals(name)) {
String type = params.getString(PARAM_TYPE).toLowerCase();
if (type.equals(VALUE_TYPE_HTTP_ALL)) {
extension.setBreakAllRequests(params.getBoolean(PARAM_STATE));
extension.setBreakAllResponses(params.getBoolean(PARAM_STATE));
} else if (type.equals(VALUE_TYPE_HTTP_REQUESTS)) {
extension.setBreakAllRequests(params.getBoolean(PARAM_STATE));
} else if (type.equals(VALUE_TYPE_HTTP_RESPONSES)) {
extension.setBreakAllResponses(params.getBoolean(PARAM_STATE));
} else {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_TYPE + " not in [" + VALUE_TYPE_HTTP_ALL + "," + VALUE_TYPE_HTTP_REQUESTS + "," + VALUE_TYPE_HTTP_RESPONSES + "]");
}
} else if (ACTION_BREAK_ON_ID.equals(name)) {
extension.setBreakOnId(params.getString(PARAM_KEY), params.getString(PARAM_STATE).toLowerCase().equals("on"));
} else if (ACTION_CONTINUE.equals(name)) {
extension.getBreakpointManagementInterface().cont();
} else if (ACTION_STEP.equals(name)) {
extension.getBreakpointManagementInterface().step();
} else if (ACTION_DROP.equals(name)) {
extension.getBreakpointManagementInterface().drop();
} else if (ACTION_SET_HTTP_MESSAGE.equals(name)) {
if (extension.getBreakpointManagementInterface().getMessage() == null) {
// We've not got an intercepted message
throw new ApiException(ApiException.Type.DOES_NOT_EXIST);
}
String header = params.getString(PARAM_HTTP_HEADER);
String body = this.getParam(params, PARAM_HTTP_BODY, "");
if (header.indexOf(HttpHeader.CRLF) < 0) {
if (header.indexOf("\\n") >= 0) {
// Makes it easier to use via API UI
header = header.replace("\\r", "\r").replace("\\n", "\n");
}
}
Message msg = extension.getBreakpointManagementInterface().getMessage();
if (msg instanceof HttpMessage) {
HttpMessage httpMsg = (HttpMessage) msg;
if (extension.getBreakpointManagementInterface().isRequest()) {
try {
httpMsg.setRequestHeader(header);
httpMsg.setRequestBody(body);
extension.getBreakpointManagementInterface().setMessage(httpMsg, true);
} catch (HttpMalformedHeaderException e) {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, e.getMessage());
}
} else {
try {
httpMsg.setResponseHeader(header);
httpMsg.setResponseBody(body);
extension.getBreakpointManagementInterface().setMessage(httpMsg, false);
} catch (HttpMalformedHeaderException e) {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, e.getMessage());
}
}
}
} else if (ACTION_ADD_HTTP_BREAK_POINT.equals(name)) {
try {
extension.addHttpBreakpoint(params.getString(PARAM_STRING), params.getString(PARAM_LOCATION), params.getString(PARAM_MATCH), params.getBoolean(PARAM_INVERSE), params.getBoolean(PARAM_IGNORECASE));
} catch (Exception e) {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, e.getMessage());
}
} else if (ACTION_REM_HTTP_BREAK_POINT.equals(name)) {
try {
extension.removeHttpBreakpoint(params.getString(PARAM_STRING), params.getString(PARAM_LOCATION), params.getString(PARAM_MATCH), params.getBoolean(PARAM_INVERSE), params.getBoolean(PARAM_IGNORECASE));
} catch (Exception e) {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, e.getMessage());
}
} else {
throw new ApiException(ApiException.Type.BAD_ACTION);
}
return ApiResponseElement.OK;
}
use of org.zaproxy.zap.extension.httppanel.Message in project zaproxy by zaproxy.
the class ManualHttpRequestEditorDialog method getMenuItem.
@Override
public ZapMenuItem getMenuItem() {
if (menuItem == null) {
menuItem = new ZapMenuItem("menu.tools.manReq", KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Message message = getMessage();
if (message == null) {
setDefaultMessage();
} else if (message instanceof HttpMessage && ((HttpMessage) message).getRequestHeader().isEmpty()) {
setDefaultMessage();
}
setVisible(true);
}
});
}
return menuItem;
}
use of org.zaproxy.zap.extension.httppanel.Message in project zaproxy by zaproxy.
the class BreakAPI method handleApiView.
@Override
public ApiResponse handleApiView(String name, JSONObject params) throws ApiException {
if (VIEW_IS_BREAK_ALL.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakAll()));
} else if (VIEW_IS_BREAK_REQUEST.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakRequest()));
} else if (VIEW_IS_BREAK_RESPONSE.equals(name)) {
return new ApiResponseElement(name, Boolean.toString(extension.getBreakpointManagementInterface().isBreakResponse()));
} else if (VIEW_HTTP_MESSAGE.equals(name)) {
Message msg = extension.getBreakpointManagementInterface().getMessage();
if (msg == null) {
return new ApiResponseElement(name, "");
} else if (msg instanceof HttpMessage) {
HttpMessage httpMsg = (HttpMessage) msg;
StringBuilder sb = new StringBuilder();
if (extension.getBreakpointManagementInterface().isRequest()) {
sb.append(httpMsg.getRequestHeader().toString());
sb.append(httpMsg.getRequestBody().toString());
} else {
sb.append(httpMsg.getResponseHeader().toString());
sb.append(httpMsg.getResponseBody().toString());
}
return new ApiResponseElement(name, sb.toString());
}
throw new ApiException(ApiException.Type.BAD_TYPE);
} else {
throw new ApiException(ApiException.Type.BAD_VIEW);
}
}
use of org.zaproxy.zap.extension.httppanel.Message in project zaproxy by zaproxy.
the class AutoDetectSyntaxHttpPanelTextArea method detectAndSetSyntax.
private void detectAndSetSyntax() {
Message message = getMessage();
if (message instanceof HttpMessage) {
final String syntax = detectSyntax((HttpMessage) message);
setSyntaxEditingStyle(syntax);
}
}
Aggregations