Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 94 additions & 22 deletions client/src/com/mirth/connect/connectors/http/HttpSender.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.connectors.http;

Expand Down Expand Up @@ -130,7 +124,7 @@ public void changedUpdate(DocumentEvent e) {
checkContentEnabled();
}
});

initToolTips();
initLayout();
}
Expand All @@ -148,6 +142,8 @@ public ConnectorProperties getProperties() {
properties.setUseProxyServer(useProxyServerYesRadio.isSelected());
properties.setProxyAddress(proxyAddressField.getText());
properties.setProxyPort(proxyPortField.getText());
properties.setOverrideLocalBinding(overrideLocalBindingYesRadio.isSelected());
properties.setLocalAddress(localAddressField.getText());

if (postButton.isSelected()) {
properties.setMethod("post");
Expand Down Expand Up @@ -190,7 +186,7 @@ public ConnectorProperties getProperties() {
properties.setParametersMap(getProperties(queryParametersTable));
properties.setUseParametersVariable(useQueryParamsVariableRadio.isSelected());
properties.setParametersVariable(queryParamsVariableField.getText());

properties.setHeadersMap(getProperties(headersTable));
properties.setUseHeadersVariable(useHeadersVariableRadio.isSelected());
properties.setHeadersVariable(headersVariableField.getText());
Expand Down Expand Up @@ -219,6 +215,15 @@ public void setProperties(ConnectorProperties properties) {
proxyAddressField.setText(props.getProxyAddress());
proxyPortField.setText(props.getProxyPort());

if (props.isOverrideLocalBinding()) {
overrideLocalBindingYesRadio.setSelected(true);
overrideLocalBindingYesRadioActionPerformed();
} else {
overrideLocalBindingNoRadio.setSelected(true);
overrideLocalBindingNoRadioActionPerformed();
}
localAddressField.setText(props.getLocalAddress());

if (props.getMethod().equalsIgnoreCase("post")) {
postButton.setSelected(true);
postButtonActionPerformed(null);
Expand Down Expand Up @@ -656,6 +661,15 @@ public boolean checkProperties(ConnectorProperties properties, boolean highlight
}
}

if (props.isOverrideLocalBinding()) {
if (props.getLocalAddress().length() <= 3) {
Comment thread
jbeckers marked this conversation as resolved.
valid = false;
if (highlight) {
localAddressField.setBackground(UIConstants.INVALID_COLOR);
}
}
}

return valid;
}

Expand All @@ -670,6 +684,7 @@ public void resetInvalidProperties() {
headersVariableField.setBackground(null);
contentTypeField.setBackground(null);
contentTextArea.setBackground(null);
localAddressField.setBackground(null);
}

@Override
Expand Down Expand Up @@ -889,6 +904,12 @@ private void initComponents() {
responseBinaryMimeTypesField = new MirthTextField();
responseBinaryMimeTypesRegexCheckBox = new MirthCheckBox();
patchButton = new MirthRadioButton();
overrideLocalBindingLabel = new JLabel();
overrideLocalBindingButtonGroup = new ButtonGroup();
overrideLocalBindingYesRadio = new MirthRadioButton();
overrideLocalBindingNoRadio = new MirthRadioButton();
localAddressLabel = new JLabel();
localAddressField = new MirthIconTextField();

setBackground(new Color(255, 255, 255));
setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
Expand Down Expand Up @@ -926,13 +947,13 @@ public void actionPerformed(ActionEvent evt) {
useQueryParamsTableRadio.addActionListener(event -> {
useQueryParamsVariableFieldsEnabled(false);
});

useQueryParamsVariableRadio.setText("Use Map:");
useQueryParamsVariableRadio.setBackground(new Color(255, 255, 255));
useQueryParamsVariableRadio.addActionListener(event -> {
useQueryParamsVariableFieldsEnabled(true);
});

ButtonGroup queryParamsButtonGroup = new ButtonGroup();
queryParamsButtonGroup.add(useQueryParamsTableRadio);
queryParamsButtonGroup.add(useQueryParamsVariableRadio);
Expand Down Expand Up @@ -989,17 +1010,17 @@ public void actionPerformed(ActionEvent evt) {
useHeadersTableRadio.addActionListener(event -> {
useHeadersVariableFieldsEnabled(false);
});

useHeadersVariableRadio.setText("Use Map:");
useHeadersVariableRadio.setBackground(new Color(255, 255, 255));
useHeadersVariableRadio.addActionListener(event -> {
useHeadersVariableFieldsEnabled(true);
});

ButtonGroup headersButtonGroup = new ButtonGroup();
headersButtonGroup.add(useHeadersTableRadio);
headersButtonGroup.add(useHeadersVariableRadio);

responseContentLabel.setText("Response Content:");

responseContentXmlBodyRadio.setBackground(new Color(255, 255, 255));
Expand Down Expand Up @@ -1203,8 +1224,38 @@ public void actionPerformed(ActionEvent evt) {
patchButtonActionPerformed(evt);
}
});

localAddressLabel.setText("Local Address:");

localAddressField.setToolTipText("<html>The local address that the client socket will be bound to, if Override Local Binding is set to Yes.<br/></html>");

overrideLocalBindingLabel.setText("Override Local Binding:");

overrideLocalBindingYesRadio.setBackground(new Color(255, 255, 255));
overrideLocalBindingYesRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
overrideLocalBindingButtonGroup.add(overrideLocalBindingYesRadio);
overrideLocalBindingYesRadio.setText("Yes");
overrideLocalBindingYesRadio.setToolTipText("<html>Select Yes to override the local address that the client socket will be bound to.<br/>Select No to use the default values of 0.0.0.0:0.<br/></html>");
overrideLocalBindingYesRadio.setMargin(new Insets(0, 0, 0, 0));
overrideLocalBindingYesRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
overrideLocalBindingYesRadioActionPerformed();
}
});

overrideLocalBindingNoRadio.setBackground(new Color(255, 255, 255));
overrideLocalBindingNoRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
overrideLocalBindingButtonGroup.add(overrideLocalBindingNoRadio);
overrideLocalBindingNoRadio.setText("No");
overrideLocalBindingNoRadio.setToolTipText("<html>Select Yes to override the local address that the client socket will be bound to.<br/>Select No to use the default values of 0.0.0.0:0.<br/></html>");
overrideLocalBindingNoRadio.setMargin(new Insets(0, 0, 0, 0));
overrideLocalBindingNoRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
overrideLocalBindingNoRadioActionPerformed();
}
});
}

private void initToolTips() {
urlField.setToolTipText("Enter the URL of the HTTP server to send each message to.");
queryParametersTable.setToolTipText("Query parameters are encoded as x=y pairs as part of the request URL, separated from it by a '?' and from each other by an '&'.");
Expand Down Expand Up @@ -1243,15 +1294,15 @@ private void initToolTips() {
patchButton.setToolTipText("Selects the HTTP operation used to send each message.");
useQueryParamsTableRadio.setToolTipText("<html>The table below will be used to populate query parameters.</html>");
useQueryParamsVariableRadio.setToolTipText("<html>The Java map specified by the following variable will be used to populate query parameters.<br/>The map must have String keys and either String or List&lt;String&gt; values.</html>");
queryParamsVariableField.setToolTipText("<html>The variable of a Java map to use to populate query parameters.<br/>The map must have String keys and either String or List&lt;String&gt; values.</html>");
queryParamsVariableField.setToolTipText("<html>The variable of a Java map to use to populate query parameters.<br/>The map must have String keys and either String or List&lt;String&gt; values.</html>");
useHeadersTableRadio.setToolTipText("<html>The table below will be used to populate headers.</html>");
useHeadersVariableRadio.setToolTipText("<html>The Java map specified by the following variable will be used to populate headers.<br/>The map must have String keys and either String or List&lt;String&gt; values.</html>");
headersVariableField.setToolTipText("<html>The variable of a Java map to use to populate headers.<br/>The map must have String keys and either String or List&lt;String&gt; values.</html>");
}

private void initLayout() {
setLayout(new MigLayout("insets 0 8 0 8, novisualpadding, hidemode 3, gap 12 6", "[][]6[]", "[][][][][][][][][][][][][][][][][grow][][grow][][][][grow]"));

add(urlLabel, "right");
add(urlField, "w 312!, sx, split 2");
add(testConnection, "gapbefore 6");
Expand All @@ -1262,6 +1313,11 @@ private void initLayout() {
add(proxyAddressField, "w 202!, sx");
add(proxyPortLabel, "newline, right");
add(proxyPortField, "w 56!, sx");
add(overrideLocalBindingLabel, "newline, right");
add(overrideLocalBindingYesRadio, "split 2");
add(overrideLocalBindingNoRadio);
add(localAddressLabel, "newline, right");
add(localAddressField, "w 200!, sx");
add(methodLabel, "newline, right");
add(postButton, "split 5");
add(getButton);
Expand Down Expand Up @@ -1476,21 +1532,31 @@ private void dataTypeTextRadioActionPerformed(ActionEvent evt) {
charsetEncodingCombobox.setEnabled(true);
}
}

private void useHeadersVariableFieldsEnabled(boolean useVariable) {
headersVariableField.setEnabled(useVariable);
headersTable.setEnabled(!useVariable);
headersNewButton.setEnabled(!useVariable);
headersDeleteButton.setEnabled(!useVariable && headersTable.getSelectedRow() > -1);
}

private void useQueryParamsVariableFieldsEnabled(boolean useVariable) {
queryParamsVariableField.setEnabled(useVariable);
queryParametersTable.setEnabled(!useVariable);
queryParametersNewButton.setEnabled(!useVariable);
queryParametersDeleteButton.setEnabled(!useVariable && queryParametersTable.getSelectedRow() > -1);
}


private void overrideLocalBindingYesRadioActionPerformed() {
localAddressField.setEnabled(true);
localAddressLabel.setEnabled(true);
}

private void overrideLocalBindingNoRadioActionPerformed() {
localAddressField.setEnabled(false);
localAddressLabel.setEnabled(false);
}

private ButtonGroup authenticationButtonGroup;
private JLabel authenticationLabel;
private MirthRadioButton authenticationNoRadio;
Expand Down Expand Up @@ -1570,4 +1636,10 @@ private void useQueryParamsVariableFieldsEnabled(boolean useVariable) {
private MirthRadioButton useProxyServerYesRadio;
private MirthTextField usernameField;
private JLabel usernameLabel;
private JLabel overrideLocalBindingLabel;
private ButtonGroup overrideLocalBindingButtonGroup;
private MirthRadioButton overrideLocalBindingNoRadio;
private MirthRadioButton overrideLocalBindingYesRadio;
private JLabel localAddressLabel;
private MirthIconTextField localAddressField;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.connectors.http;

Expand All @@ -15,8 +9,6 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;

import org.apache.commons.lang3.StringUtils;

import com.mirth.connect.client.core.api.MirthApiException;
import com.mirth.connect.server.api.MirthServlet;
import com.mirth.connect.server.util.ConnectorUtil;
Expand All @@ -36,9 +28,22 @@ public HttpConnectorServlet(@Context HttpServletRequest request, @Context Securi
public ConnectionTestResponse testConnection(String channelId, String channelName, HttpDispatcherProperties properties) {
try {
URL url = new URL(replacer.replaceValues(properties.getHost(), channelId, channelName));
int port = url.getPort();
// If no port was provided, default to port 80 or 443.
return ConnectorUtil.testConnection(url.getHost(), (port == -1) ? (StringUtils.equalsIgnoreCase(url.getProtocol(), "https") ? 443 : 80) : port, TIMEOUT);
final int port;
if (url.getPort() != -1) {
port = url.getPort();
} else if ("https".equalsIgnoreCase(url.getProtocol())) {
port = 443;
} else {
port = 80;
}

if (!properties.isOverrideLocalBinding()) {
return ConnectorUtil.testConnection(url.getHost(), port, TIMEOUT);
} else {
String localAddr = replacer.replaceValues(properties.getLocalAddress(), channelId, channelName);
return ConnectorUtil.testConnection(url.getHost(), port, TIMEOUT, localAddr);
}
} catch (Exception e) {
throw new MirthApiException(e);
}
Expand Down
29 changes: 16 additions & 13 deletions server/src/com/mirth/connect/connectors/http/HttpDispatcher.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.connectors.http;

import java.io.File;
import java.net.InetAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand All @@ -27,6 +22,7 @@
import javax.mail.util.ByteArrayDataSource;

import com.mirth.connect.client.core.BrandingConstants;
import com.mirth.connect.util.TcpUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.fileupload.FileUploadBase;
Expand Down Expand Up @@ -192,6 +188,7 @@ public void replaceConnectorProperties(ConnectorProperties connectorProperties,
httpDispatcherProperties.setHost(replacer.replaceValues(httpDispatcherProperties.getHost(), connectorMessage));
httpDispatcherProperties.setProxyAddress(replacer.replaceValues(httpDispatcherProperties.getProxyAddress(), connectorMessage));
httpDispatcherProperties.setProxyPort(replacer.replaceValues(httpDispatcherProperties.getProxyPort(), connectorMessage));
httpDispatcherProperties.setLocalAddress(replacer.replaceValues(httpDispatcherProperties.getLocalAddress(), connectorMessage));
httpDispatcherProperties.setResponseBinaryMimeTypes(replacer.replaceValues(httpDispatcherProperties.getResponseBinaryMimeTypes(), connectorMessage));
httpDispatcherProperties.setHeadersMap(replacer.replaceKeysAndValuesInMap(httpDispatcherProperties.getHeadersMap(), connectorMessage));
httpDispatcherProperties.setHeadersVariable(replacer.replaceValues(httpDispatcherProperties.getHeadersVariable(), connectorMessage));
Expand Down Expand Up @@ -258,9 +255,9 @@ public Response send(ConnectorProperties connectorProperties, ConnectorMessage c

/*
* If a charset is set in the Content Type field, use that.
*
*
* If the charset is NONE, keep it as null.
*
*
* Otherwise, use the charset from the Character Encoding drop-down menu.
*/
Charset charset = null;
Expand Down Expand Up @@ -312,8 +309,14 @@ public Response send(ConnectorProperties connectorProperties, ConnectorMessage c
logger.debug("using authentication with credentials: " + credentials);
}

RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(socketTimeout).setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(true).build();
context.setRequestConfig(requestConfig);
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectTimeout(socketTimeout)
.setSocketTimeout(socketTimeout)
.setStaleConnectionCheckEnabled(true);
Comment thread
jbeckers marked this conversation as resolved.
if (httpDispatcherProperties.isOverrideLocalBinding()) {
requestConfigBuilder.setLocalAddress(InetAddress.getByName(TcpUtil.getFixedHost(httpDispatcherProperties.getLocalAddress())));
}
context.setRequestConfig(requestConfigBuilder.build());

// Set proxy information
if (httpDispatcherProperties.isUseProxyServer()) {
Expand Down Expand Up @@ -444,7 +447,7 @@ public boolean isBinaryContentType(ContentType contentType) {

return new Response(responseStatus, responseData, responseStatusMessage, responseError, validateResponse);
}

protected boolean shouldParseMultipart(HttpDispatcherProperties httpDispatcherProperties, String mimeType) {
// Only parse multipart if XML Body is selected and Parse Multipart is enabled
return httpDispatcherProperties.isResponseXmlBody() && httpDispatcherProperties.isResponseParseMultipart() && mimeType.startsWith(FileUploadBase.MULTIPART);
Expand Down
Loading
Loading