Search in sources :

Example 1 with InvalidMessageDataException

use of org.zaproxy.zap.extension.httppanel.InvalidMessageDataException in project zaproxy by zaproxy.

the class ResponseByteHttpPanelViewModel method setData.

@Override
public void setData(byte[] data) {
    if (httpMessage == null) {
        return;
    }
    int pos = HttpPanelViewModelUtils.findHeaderLimit(data);
    if (pos == -1) {
        logger.warn("Could not Save Header, limit not found. Header: " + new String(data));
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.notfound"));
    }
    try {
        httpMessage.setResponseHeader(new String(data, 0, pos));
    } catch (HttpMalformedHeaderException e) {
        logger.warn("Could not Save Header: " + Arrays.toString(data), e);
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.malformed"), e);
    }
    httpMessage.getResponseBody().setBody(ArrayUtils.subarray(data, pos, data.length));
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) InvalidMessageDataException(org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)

Example 2 with InvalidMessageDataException

use of org.zaproxy.zap.extension.httppanel.InvalidMessageDataException in project zaproxy by zaproxy.

the class RequestStringHttpPanelViewModel method setData.

@Override
public void setData(String data) {
    if (httpMessage == null) {
        return;
    }
    String[] parts = data.split(HttpHeader.LF + HttpHeader.LF);
    String header = parts[0].replaceAll("(?<!\r)\n", HttpHeader.CRLF);
    try {
        httpMessage.setRequestHeader(header);
    } catch (HttpMalformedHeaderException e) {
        logger.warn("Could not Save Header: " + header, e);
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.malformed"), e);
    }
    String body = "";
    if (parts.length > 1) {
        body = data.substring(parts[0].length() + 2);
    }
    httpMessage.setRequestBody(body);
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) InvalidMessageDataException(org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)

Example 3 with InvalidMessageDataException

use of org.zaproxy.zap.extension.httppanel.InvalidMessageDataException in project zaproxy by zaproxy.

the class ResponseStringHttpPanelViewModel method setData.

@Override
public void setData(String data) {
    if (httpMessage == null) {
        return;
    }
    String[] parts = data.split(HttpHeader.LF + HttpHeader.LF);
    String header = parts[0].replaceAll("(?<!\r)\n", HttpHeader.CRLF);
    try {
        httpMessage.setResponseHeader(header);
    } catch (HttpMalformedHeaderException e) {
        logger.warn("Could not Save Header: " + header, e);
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.malformed"), e);
    }
    String body = "";
    if (parts.length > 1) {
        body = data.substring(parts[0].length() + 2);
    }
    httpMessage.setResponseBody(body);
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) InvalidMessageDataException(org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)

Example 4 with InvalidMessageDataException

use of org.zaproxy.zap.extension.httppanel.InvalidMessageDataException in project zaproxy by zaproxy.

the class ManualRequestEditorDialog method sendButtonTriggered.

protected void sendButtonTriggered() {
    if (sending) {
        // Can also be triggered by other buttons, eg in the Http Response tab
        return;
    }
    sending = true;
    try {
        btnSend.setEnabled(false);
        try {
            getRequestPanel().saveData();
        } catch (InvalidMessageDataException e1) {
            StringBuilder warnMessage = new StringBuilder(150);
            warnMessage.append(Constant.messages.getString("manReq.warn.datainvalid"));
            String exceptionMessage = e1.getLocalizedMessage();
            if (exceptionMessage != null && !exceptionMessage.isEmpty()) {
                warnMessage.append('\n').append(exceptionMessage);
            }
            View.getSingleton().showWarningDialog(this, warnMessage.toString());
            btnSend.setEnabled(true);
            return;
        }
        Mode mode = Control.getSingleton().getMode();
        if (mode.equals(Mode.safe)) {
            // Can happen if the user turns on safe mode with the dialog open
            View.getSingleton().showWarningDialog(this, Constant.messages.getString("manReq.safe.warning"));
            btnSend.setEnabled(true);
            return;
        } else if (mode.equals(Mode.protect)) {
            if (!getMessage().isInScope()) {
                // In protected mode and not in scope, so fail
                View.getSingleton().showWarningDialog(this, Constant.messages.getString("manReq.outofscope.warning"));
                btnSend.setEnabled(true);
                return;
            }
        }
        btnSendAction();
    } finally {
        sending = false;
    }
}
Also used : Mode(org.parosproxy.paros.control.Control.Mode) InvalidMessageDataException(org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)

Example 5 with InvalidMessageDataException

use of org.zaproxy.zap.extension.httppanel.InvalidMessageDataException in project zaproxy by zaproxy.

the class RequestByteHttpPanelViewModel method setData.

@Override
public void setData(byte[] data) {
    if (httpMessage == null) {
        return;
    }
    int pos = HttpPanelViewModelUtils.findHeaderLimit(data);
    if (pos == -1) {
        logger.warn("Could not Save Header, limit not found. Header: " + new String(data));
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.notfound"));
    }
    try {
        httpMessage.setRequestHeader(new String(data, 0, pos));
    } catch (HttpMalformedHeaderException e) {
        logger.warn("Could not Save Header: " + new String(data, 0, pos), e);
        throw new InvalidMessageDataException(Constant.messages.getString("http.panel.model.header.warn.malformed"), e);
    }
    httpMessage.getRequestBody().setBody(ArrayUtils.subarray(data, pos, data.length));
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) InvalidMessageDataException(org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)

Aggregations

InvalidMessageDataException (org.zaproxy.zap.extension.httppanel.InvalidMessageDataException)5 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)4 Mode (org.parosproxy.paros.control.Control.Mode)1