📄 webservicesamplergui.java
字号:
readResponse.setSelected(false);
useProxy.setSelected(false);
soapXmlFile.setFilename(""); //$NON-NLS-1$
}
/**
* init() adds soapAction to the mainPanel. The class reuses logic from
* SOAPSampler, since it is common.
*/
private void init() {
setLayout(new BorderLayout(0, 5));
setBorder(makeBorder());
add(makeTitlePanel(), BorderLayout.NORTH);
wsdlMessage.setFont(plainText);
wsdlMessage2.setFont(plainText);
wsdlMessage3.setFont(plainText);
wsdlMessage4.setFont(plainText);
wsdlMessage5.setFont(plainText);
readMessage.setFont(plainText);
readMessage2.setFont(plainText);
readMessage3.setFont(plainText);
// MAIN PANEL
JPanel mainPanel = new JPanel();
Border margin = new EmptyBorder(10, 10, 5, 10);
mainPanel.setBorder(margin);
mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.BOTH));
// Button for browsing webservice wsdl
JPanel wsdlEntry = new JPanel();
mainPanel.add(wsdlEntry);
wsdlEntry.add(wsdlField);
wsdlEntry.add(wsdlButton);
wsdlButton.addActionListener(this);
// Web Methods
JPanel listPanel = new JPanel();
JLabel selectLabel = new JLabel("Web Methods");
wsdlMethods = new JLabeledChoice();
mainPanel.add(listPanel);
listPanel.add(selectLabel);
listPanel.add(wsdlMethods);
listPanel.add(selectButton);
selectButton.addActionListener(this);
mainPanel.add(protocol);
mainPanel.add(domain);
mainPanel.add(port);
mainPanel.add(path);
mainPanel.add(connectTimeout);
mainPanel.add(soapAction);
// OPTIONAL TASKS
// we create a preferred size for the soap text area
// the width is the same as the soap file browser
Dimension pref = new Dimension(400, 200);
soapXml.setPreferredSize(pref);
mainPanel.add(soapXml);
mainPanel.add(soapXmlFile);
mainPanel.add(wsdlMessage);
mainPanel.add(wsdlMessage2);
mainPanel.add(wsdlMessage3);
mainPanel.add(wsdlMessage4);
mainPanel.add(wsdlMessage5);
mainPanel.add(randomXmlFile);
mainPanel.add(memCache);
mainPanel.add(readResponse);
mainPanel.add(readMessage);
mainPanel.add(readMessage2);
mainPanel.add(readMessage3);
// add the proxy elements
mainPanel.add(useProxy);
useProxy.addActionListener(this);
mainPanel.add(proxyHost);
mainPanel.add(proxyPort);
// add the proxy notes
proxyMessage.setFont(plainText);
proxyMessage2.setFont(plainText);
proxyMessage3.setFont(plainText);
mainPanel.add(proxyMessage);
mainPanel.add(proxyMessage2);
mainPanel.add(proxyMessage3);
this.add(mainPanel);
}
/**
* the implementation loads the URL and the soap action for the request.
*/
public void configure(TestElement el) {
super.configure(el);
WebServiceSampler sampler = (WebServiceSampler) el;
wsdlField.setText(sampler.getWsdlURL());
protocol.setText(sampler.getProtocol());
domain.setText(sampler.getDomain());
port.setText(sampler.getPropertyAsString(HTTPSamplerBase.PORT));
path.setText(sampler.getPath());
soapAction.setText(sampler.getSoapAction());
soapXml.setText(sampler.getXmlData());
soapXmlFile.setFilename(sampler.getXmlFile());
randomXmlFile.setText(sampler.getXmlPathLoc());
connectTimeout.setText(sampler.getTimeout());
memCache.setSelected(sampler.getMemoryCache());
readResponse.setSelected(sampler.getReadResponse());
useProxy.setSelected(sampler.getUseProxy());
if (sampler.getProxyHost().length() == 0) {
proxyHost.setEnabled(false);
} else {
proxyHost.setText(sampler.getProxyHost());
}
if (sampler.getProxyPort() == 0) {
proxyPort.setEnabled(false);
} else {
proxyPort.setText(String.valueOf(sampler.getProxyPort()));
}
}
/**
* configure the sampler from the WSDL. If the WSDL did not include service
* node, it will use the original URL minus the querystring. That may not be
* correct, so we should probably add a note. For Microsoft webservices it
* will work, since that's how IIS works.
*/
public void configureFromWSDL() {
if (HELPER != null) {
if(HELPER.getBinding() != null) {
this.protocol.setText(HELPER.getProtocol());
this.domain.setText(HELPER.getBindingHost());
if (HELPER.getBindingPort() > 0) {
this.port.setText(String.valueOf(HELPER.getBindingPort()));
} else {
this.port.setText("80"); // $NON-NLS-1$
}
this.path.setText(HELPER.getBindingPath());
}
this.soapAction.setText(HELPER.getSoapAction(this.wsdlMethods.getText()));
}
}
/**
* The method uses WSDLHelper to get the information from the WSDL. Since
* the logic for getting the description is isolated to this method, we can
* easily replace it with a different WSDL driver later on.
*
* @param url
* @return array of web methods
*/
public String[] browseWSDL(String url) {
try {
// We get the AuthManager and pass it to the WSDLHelper
// once the sampler is updated to Axis, all of this stuff
// should not be necessary. Now I just need to find the
// time and motivation to do it.
WebServiceSampler sampler = (WebServiceSampler) this.createTestElement();
AuthManager manager = sampler.getAuthManager();
HELPER = new WSDLHelper(url, manager);
HELPER.parse();
return HELPER.getWebMethods();
} catch (Exception exception) {
JOptionPane.showConfirmDialog(this,
JMeterUtils.getResString("wsdl_helper_error"), // $NON-NLS-1$
"Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
return null;
}
}
/**
* method from ActionListener
*
* @param event
* that occurred
*/
public void actionPerformed(ActionEvent event) {
final Object eventSource = event.getSource();
if (eventSource == selectButton) {
this.configureFromWSDL();
} else if (eventSource == useProxy) {
// if use proxy is checked, we enable
// the text fields for the host and port
boolean use = useProxy.isSelected();
if (use) {
proxyHost.setEnabled(true);
proxyPort.setEnabled(true);
} else {
proxyHost.setEnabled(false);
proxyPort.setEnabled(false);
}
} else if (eventSource == wsdlButton){
final String wsdlText = wsdlField.getText();
if (wsdlText != null && wsdlText.length() > 0) {
String[] wsdlData = browseWSDL(wsdlText);
if (wsdlData != null) {
wsdlMethods.setValues(wsdlData);
wsdlMethods.repaint();
}
} else {
JOptionPane.showConfirmDialog(this,
JMeterUtils.getResString("wsdl_url_error"), // $NON-NLS-1$
"Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -