diff options
Diffstat (limited to 'branches/sca-java-1.x/modules')
6 files changed, 149 insertions, 20 deletions
diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java index b8e5330007..6abc28adde 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java @@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; import java.net.URLConnection; @@ -119,10 +120,18 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements try { URLConnection connection = url.openConnection(); connection.setUseCaches(false); - scdlStream = connection.getInputStream(); + try { + scdlStream = connection.getInputStream(); + } catch (IOException e) { + if (e.getClass() == IOException.class && connection instanceof HttpURLConnection + && ((HttpURLConnection)connection).getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { + error("HttpServerError", url, ((HttpURLConnection)connection).getResponseMessage()); + } + throw e; + } } catch (IOException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", url, ce); + error("ContributionReadException", url, e); throw ce; } return read(uri, scdlStream); @@ -161,11 +170,11 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements } } catch ( IOException e ) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", scdlStream, ce); + error("ContributionReadException", scdlStream, e); throw ce; } catch ( Exception e ) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", scdlStream, ce); + error("ContributionReadException", scdlStream, e); //throw ce; } @@ -203,7 +212,7 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error("ContributionReadException", inputFactory, e); throw ce; } finally { try { diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties b/branches/sca-java-1.x/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties index f68925c6f4..f0d5b0a201 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties @@ -28,3 +28,4 @@ ContributionReadException = ContributionReadException occured due to : {0} ContributionResolveException = ContributionResolveException occured due to : {0} ContributionWriteException = ContributionWriteException occured due to : {0} XMLStreamException = XMLStreamException occured due to : {0} +HttpServerError = HTTP Server Error : {0} diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java index 27eb80b3ad..5de0002086 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java @@ -87,6 +87,9 @@ import org.apache.tuscany.sca.implementation.node.builder.impl.NodeCompositeBuil import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.MonitorRuntimeException; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; @@ -275,8 +278,13 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se try { String dependencyLocation = dependencyItem.getAlternate(); dependency = contribution(workspace, dependencyURI, dependencyLocation); - } catch (ContributionReadException e) { - continue; + } catch (Exception e) { + if (contributionURI.equals(dependencyURI)) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getDescription(e)); + return; + } else { + continue; + } } workspace.getContributions().add(dependency); contributionMap.put(dependencyURI, dependency); @@ -313,9 +321,10 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se // Fuse includes into the deployable composite try { compositeIncludeBuilder.build(deployable); - } catch (CompositeBuilderException e) { - e.printStackTrace(); //[nash] - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + analyzeProblems(); + } catch (Exception e) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getDescription(e)); + return; } // Store away the requested composite @@ -387,9 +396,9 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se contractMapper, aggregatedDefinitions, monitor); try { compositeBuilder.build(domainComposite); - } catch (CompositeBuilderException e) { - e.printStackTrace(); //[nash] - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + analyzeProblems(); + } catch (Exception e) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getDescription(e)); return; } @@ -455,9 +464,7 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se QName formatName = new QName(format.substring(0, s), format.substring(s +1)); processor = (StAXArtifactProcessor<Composite>)staxProcessors.getProcessor(formatName); if (processor == null) { - Exception e = new IllegalArgumentException(queryString); //[nash] - e.printStackTrace(); //[nash] - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); //[nash] + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, new IllegalArgumentException(queryString).toString()); return; } } else { @@ -468,7 +475,6 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se XMLStreamWriter writer = outputFactory.createXMLStreamWriter(response.getOutputStream()); processor.write(requestedComposite, writer); } catch (Exception e) { - e.printStackTrace(); //[nash] response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } @@ -541,12 +547,27 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se try { URI uri = URI.create(contributionURI); URL location = locationURL(contributionLocation); + Contribution contribution = (Contribution)contributionProcessor.read(null, uri, location); + try { + analyzeProblems(); + } catch (ServiceRuntimeException e) { + throw e; + } catch (Exception e) { + throw new ContributionReadException(e); + } // Resolve the contribution dependencies contributionDependencyBuilder.buildContributionDependencies(contribution, workspace); contributionProcessor.resolve(contribution, workspace.getModelResolver()); + try { + analyzeProblems(); + } catch (ServiceRuntimeException e) { + throw e; + } catch (Exception e) { + throw new ContributionReadException(e); + } return contribution; } catch (ContributionReadException e) { @@ -558,6 +579,29 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se } } + private void analyzeProblems() throws Exception { + + for (Problem problem : monitor.getProblems()) { + if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) { + if (problem.getCause() != null) { + throw new ServiceRuntimeException(new MonitorRuntimeException(problem.getCause())); + } else { + throw new ServiceRuntimeException(new MonitorRuntimeException(problem.toString())); + } + } + } + } + + private String getDescription(Exception e) { + if (e instanceof ServiceRuntimeException && e.getCause() instanceof MonitorRuntimeException) { + Throwable ce = e.getCause(); + return ce.getCause() != null ? ce.getCause().toString() : ce.getMessage(); + } else { + return e.toString(); + } + } + + /** * The following code was copied from RuntimeBootStrapper to fix TUSCANY-3171 * diff --git a/branches/sca-java-1.x/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorRuntimeException.java b/branches/sca-java-1.x/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorRuntimeException.java new file mode 100644 index 0000000000..90cbe99688 --- /dev/null +++ b/branches/sca-java-1.x/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorRuntimeException.java @@ -0,0 +1,55 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.monitor;
+
+
+/**
+ * Denotes an exception that has been logged and recorded in the monitor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MonitorRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = 8972044333077591932L;
+
+ public MonitorRuntimeException() {
+ super();
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public MonitorRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public MonitorRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public MonitorRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 7d64857306..4a93993560 100644 --- a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -58,6 +58,7 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtens import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionService; import org.apache.tuscany.sca.contribution.service.util.FileHelper; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -68,6 +69,7 @@ import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation; import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.MonitorRuntimeException; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.node.SCAClient; @@ -140,6 +142,8 @@ public class NodeImpl implements SCANode, SCAClient { // Configure the node configureNode(configuration); + } catch (ServiceRuntimeException e) { + throw e; } catch (Exception e) { throw new ServiceRuntimeException(e); } @@ -376,6 +380,8 @@ public class NodeImpl implements SCANode, SCAClient { // Configure the node configureNode(configuration); + } catch (ServiceRuntimeException e) { + throw e; } catch (Exception e) { throw new ServiceRuntimeException(e); } @@ -440,6 +446,8 @@ public class NodeImpl implements SCANode, SCAClient { // Configure the node configureNode(configuration); + } catch (ServiceRuntimeException e) { + throw e; } catch (Exception e) { throw new ServiceRuntimeException(e); } @@ -584,7 +592,11 @@ public class NodeImpl implements SCANode, SCAClient { logger.log(Level.INFO, "Loading composite: " + compositeURL); // InputStream is = compositeURL.openStream(); // XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - composite = compositeDocProcessor.read(null, uri, compositeURL); + try { + composite = compositeDocProcessor.read(null, uri, compositeURL); + } catch (ContributionReadException e) { + // ignore - errors will be detected by analyzeProblems() call below + } // reader.close(); analyzeProblems(); @@ -696,9 +708,9 @@ public class NodeImpl implements SCANode, SCAClient { for (Problem problem : monitor.getProblems()) { if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) { if (problem.getCause() != null) { - throw problem.getCause(); + throw new ServiceRuntimeException(new MonitorRuntimeException(problem.getCause())); } else { - throw new ServiceRuntimeException(problem.toString()); + throw new ServiceRuntimeException(new MonitorRuntimeException(problem.toString())); } } } diff --git a/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java index 7be1e14988..59d050734c 100644 --- a/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java +++ b/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.io.IOException; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -376,6 +377,13 @@ final class NodeLauncherUtil { return node; } catch (Exception e) { + Throwable ce = e instanceof InvocationTargetException ? e.getCause() : e; + if (ce.getClass().getName().equals("org.osoa.sca.ServiceRuntimeException") && + ce.getCause() != null && + ce.getCause().getClass().getName().equals("org.apache.tuscany.sca.monitor.MonitorRuntimeException")) { + NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created"); + throw new LauncherException("SCA Node could not be created"); + } NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e); throw new LauncherException(e); } finally { |