1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.workbench;
2021import java.awt.BorderLayout;
22import java.awt.Component;
23import java.awt.Dimension;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26import java.io.IOException;
27import java.net.MalformedURLException;
28import java.net.URISyntaxException;
29import java.net.UnknownHostException;
30import java.util.Locale;
3132import javax.net.ssl.SSLException;
33import javax.swing.BorderFactory;
34import javax.swing.BoxLayout;
35import javax.swing.JButton;
36import javax.swing.JDialog;
37import javax.swing.JEditorPane;
38import javax.swing.JPanel;
39import javax.swing.JScrollPane;
40import javax.swing.ScrollPaneConstants;
41import javax.swing.WindowConstants;
42import javax.xml.stream.XMLStreamException;
4344import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
45import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
46import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
47import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
48import org.apache.chemistry.opencmis.commons.exceptions.CmisProxyAuthenticationException;
49import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
50import org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException;
51import org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException;
52import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException;
53import org.xml.sax.SAXParseException;
5455publicclassConnectionErrorDialogextends JDialog {
5657privatestaticfinallong serialVersionUID = 1L;
5859publicstaticfinal String HTTP_PROXY_HOST = "http.proxyHost";
60publicstaticfinal String HTTP_PROXY_PORT = "http.proxyPort";
61publicstaticfinal String HTTPS_PROXY_HOST = "https.proxyHost";
62publicstaticfinal String HTTPS_PROXY_PORT = "https.proxyPort";
63publicstaticfinal String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
6465privatefinal Exception exception;
6667publicConnectionErrorDialog(JDialog owner, Exception exception) {
68super(owner, "Connection Error", true);
69this.exception = exception;
7071 ClientHelper.logError(exception);
7273 createGUI();
74 }
7576privatevoid createGUI() {
77 setMinimumSize(new Dimension(WorkbenchScale.scaleInt(600), WorkbenchScale.scaleInt(400)));
78 setPreferredSize(new Dimension(WorkbenchScale.scaleInt(600), WorkbenchScale.scaleInt(450)));
7980 setLayout(new BorderLayout());
8182 StringBuilder hint = new StringBuilder(1024);
83 hint.append("<h2><font color=\"red\">Exception: <em>" + exception.getClass().getSimpleName()
84 + "</em></font><br>");
85 ClientHelper.encodeHtml(hint, exception.getMessage());
86 hint.append("</h2>");
87if (exception.getCause() != null) {
88 hint.append("<h3><font color=\"red\">Cause: <em>" + exception.getCause().getClass().getSimpleName()
89 + "</em></font><br>");
90 ClientHelper.encodeHtml(hint, exception.getCause().getMessage());
91 hint.append("</h3>");
92 }
93 hint.append("<hr><br>");
94 hint.append(getHint());
9596// hint area97 JPanel hintsPanel = new JPanel();
98 hintsPanel.setLayout(new BoxLayout(hintsPanel, BoxLayout.PAGE_AXIS));
99 hintsPanel.setBorder(WorkbenchScale.scaleBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)));
100 add(hintsPanel, BorderLayout.CENTER);
101102 JEditorPane hints = new JEditorPane("text/html", hint.toString());
103 hints.setEditable(false);
104 hints.setCaretPosition(0);
105106 hintsPanel.add(new JScrollPane(hints, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
107 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
108109// close button110 JPanel buttonPanel = new JPanel();
111 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS));
112 buttonPanel.setBorder(WorkbenchScale.scaleBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)));
113 add(buttonPanel, BorderLayout.PAGE_END);
114115 JButton closeButton = new JButton("Close");
116 closeButton.setPreferredSize(new Dimension(Short.MAX_VALUE, WorkbenchScale.scaleInt(30)));
117 closeButton.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
118 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
119120 closeButton.addActionListener(new ActionListener() {
121 @Override
122publicvoid actionPerformed(ActionEvent e) {
123 ConnectionErrorDialog.this.dispose();
124 }
125 });
126127 buttonPanel.add(closeButton);
128129 getRootPane().setDefaultButton(closeButton);
130131 ClientHelper.installEscapeBinding(this, getRootPane(), true);
132133 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
134 pack();
135 setLocationRelativeTo(getOwner());
136137 setVisible(true);
138 }
139140private String getHint() {
141if (exception instanceof CmisObjectNotFoundException || exception instanceof CmisNotSupportedException) {
142return"The CMIS Workbench could connect to the server but the provided URL is not a CMIS endpoint URL."143 + "<br>Check your URL and proxy settings." + getProxyConfig();
144 } elseif (exception instanceof CmisUnauthorizedException) {
145return"The provided credentials are invalid.<br>Check your credentials.";
146 } elseif (exception instanceof CmisPermissionDeniedException) {
147return"The provided credentials are invalid or the user has no permission to connect."148 + "<br>Check your credentials.";
149 } elseif (exception instanceof CmisProxyAuthenticationException) {
150return"The proxy server requires valid credentials.<br>Check the session parameters "151 + "'org.apache.chemistry.opencmis.binding.proxyuser' and "152 + "'org.apache.chemistry.opencmis.binding.proxypassword'." + getProxyConfig();
153 } elseif (exception instanceof CmisTooManyRequestsException) {
154return"The server indicated that you made too many request. Wait or contact the server administrator.";
155 } elseif (exception instanceof CmisRuntimeException) {
156return"Something fatal happend on the client or server side."157 + "<br>Check your URL, the binding, and your proxy settings."158 + "<br><br>Also see the CMIS Workbench log for more details." + getProxyConfig();
159 } elseif (exception instanceof CmisConnectionException) {
160 Throwable cause = exception.getCause();
161while (cause instanceof CmisConnectionException) {
162 cause = cause.getCause();
163 }
164165if (cause instanceof MalformedURLException || cause instanceof URISyntaxException) {
166return"The provided URL is not a valid URL.<br>Check your URL.";
167 } elseif (cause instanceof UnknownHostException) {
168return"The CMIS Workbench could not connect to the server."169 + "<br>Check your URL and your network and proxy settings." + getProxyConfig();
170 } elseif (cause instanceof SSLException) {
171return"The CMIS Workbench could not establish a SSL connection to the server."172 + "<br>Check your network and proxy settings."173 + "<br><br>If you want to connect to a server with a self-signed certificate, "174 + "add the parameter <code>-Dcmis.workbench.acceptSelfSignedCertificates=true</code> "175 + "to the JAVA_OPTS in the CMIS Workbench start script and restart."176 + "<br><b>WARNING:</b> It disables <em>all</em> SSL certificate checks!" + getProxyConfig();
177 } elseif (cause instanceof JSONParseException) {
178return"The provided URL does not return a JSON response."179 + "<br>Check your URL, the binding, and your proxy settings."180 + "<br><br>Some servers return a HTML login page if the credentials are incorrect."181 + "<br>Check your credentials." + getProxyConfig();
182 } elseif (cause instanceof XMLStreamException) {
183return"The provided URL does not return an AtomPub response."184 + "<br>Check your URL, the binding, and your proxy settings."185 + "<br><br>Some servers return a HTML login page if the credentials are incorrect."186 + "<br>Check your credentials." + getProxyConfig();
187 } elseif (cause instanceof SAXParseException) {
188return"The provided URL does not return a WSDL."189 + "<br>Check your URL, the binding, and your proxy settings."190 + "<br><br>Some servers return a HTML login page if the credentials are incorrect."191 + "<br>Check your credentials." + getProxyConfig();
192 } elseif (cause instanceof IOException) {
193return"A network problem occured.<br>Check your URL and your network and proxy settings."194 + getProxyConfig();
195 }
196197if (exception.getMessage().toLowerCase(Locale.ENGLISH).startsWith("unexpected document")) {
198return"The provided URL does not return a AtomPub response."199 + "<br>Check your URL, the binding, and your proxy settings."200 + "<br><br>Some servers return a HTML login page if the credentials are incorrect."201 + "<br>Check your credentials." + getProxyConfig();
202 }
203204return"Check the URL, the binding, and the credentials.";
205 }
206207return exception.getMessage();
208 }
209210private String getProxyConfig() {
211 StringBuilder sb = new StringBuilder(256);
212213 sb.append("<br><br><hr><br><em>Current proxy settings:</em><br><br>");
214215if (System.getProperty(HTTP_PROXY_HOST) == null && System.getProperty(HTTPS_PROXY_HOST) == null) {
216 sb.append("<b>- no proxy settings -</b>");
217 } else {
218 sb.append("<table>");
219if (System.getProperty(HTTP_PROXY_HOST) != null) {
220 sb.append("<tr><td><b>HTTP proxy:</b></td><td>");
221 sb.append(System.getProperty(HTTP_PROXY_HOST) + ":" + System.getProperty(HTTP_PROXY_PORT));
222 sb.append("</td></tr>");
223 }
224225if (System.getProperty(HTTPS_PROXY_HOST) != null) {
226 sb.append("<tr><td><b>HTTPS proxy:</b></td><td>");
227 sb.append(System.getProperty(HTTPS_PROXY_HOST) + ":" + System.getProperty(HTTPS_PROXY_PORT));
228 sb.append("</td></tr>");
229 }
230231if (System.getProperty(HTTP_NON_PROXY_HOSTS) != null) {
232 sb.append("<tr><td><b>Non proxy hosts:</b></td><td>");
233 sb.append(System.getProperty(HTTP_NON_PROXY_HOSTS));
234 sb.append("</td></tr>");
235 }
236 }
237238return sb.toString();
239 }
240 }