Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SWITCHARD-1904 Fix findbugs issues and provide exceptions

  • Loading branch information...
commit e59d7820ccea7194797c1cf3826f95aa933e3ce4 1 parent d274d5f
@cunningt cunningt authored
Showing with 318 additions and 87 deletions.
  1. +160 −0 build/src/main/resources/findbugs/findbugs-exclude.xml
  2. +7 −6 bus/camel/src/main/java/org/switchyard/bus/camel/DefaultErrorListener.java
  3. +1 −1  bus/camel/src/main/java/org/switchyard/bus/camel/processors/InterceptProcessor.java
  4. +1 −1  common/core/src/main/java/org/switchyard/common/io/resource/ResourceType.java
  5. +4 −4 common/core/src/main/java/org/switchyard/common/lang/Strings.java
  6. +14 −8 common/core/src/main/java/org/switchyard/common/type/classpath/ClasspathScanner.java
  7. +31 −10 common/core/src/main/java/org/switchyard/common/type/reflect/FieldAccess.java
  8. +3 −2 config/src/main/java/org/switchyard/config/model/NamespaceComparator.java
  9. +3 −3 config/src/main/java/org/switchyard/config/model/composite/v1/PolicyConfig.java
  10. +3 −5 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeReferenceModel.java
  11. +1 −3 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeServiceModel.java
  12. +0 −1  remote/src/main/java/org/switchyard/remote/cluster/RoundRobinStrategy.java
  13. +3 −3 runtime/src/main/java/org/switchyard/handlers/PolicyHandler.java
  14. +3 −3 runtime/src/main/java/org/switchyard/internal/DefaultHandlerChain.java
  15. +3 −2 runtime/src/main/java/org/switchyard/internal/DefaultServiceRegistry.java
  16. +1 −1  serial/base/src/main/java/org/switchyard/serial/graph/Graph.java
  17. +6 −0 serial/base/src/main/java/org/switchyard/serial/graph/node/InputStreamNode.java
  18. +7 −2 serial/base/src/main/java/org/switchyard/serial/graph/node/MapNode.java
  19. +13 −14 tools/forge/common/src/main/java/org/switchyard/tools/forge/GenericTestForge.java
  20. +13 −4 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/SwitchYardFacet.java
  21. +5 −1 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/SwitchYardPlugin.java
  22. +5 −5 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/TemplateResource.java
  23. +9 −1 transform/src/main/java/org/switchyard/transform/internal/TransformerRegistryLoader.java
  24. +2 −1  transform/src/main/java/org/switchyard/transform/internal/TransformerUtil.java
  25. +3 −3 transform/src/main/java/org/switchyard/transform/ootb/lang/ExceptionTransforms.java
  26. +7 −1 transform/src/main/java/org/switchyard/transform/xslt/internal/TransformerPool.java
  27. +2 −1  validate/src/main/java/org/switchyard/validate/internal/ValidatorUtil.java
  28. +8 −1 validate/src/main/java/org/switchyard/validate/xml/internal/XmlValidator.java
View
160 build/src/main/resources/findbugs/findbugs-exclude.xml
@@ -1,7 +1,167 @@
<FindBugsFilter>
+
+ <Match>
+ <Bug pattern="NP_BOOLEAN_RETURN_NULL"/>
+ </Match>
+
<!-- InputStreamGraph uses this without side effects -->
<Match>
<Class name="org.switchyard.internal.io.graph.InputStreamGraph" />
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2" />
</Match>
+
+ <!-- ignore the generated logger/bundle classes generated by the log tool. -->
+ <!-- see https://issues.jboss.org/browse/LOGTOOL-81 -->
+ <Match>
+ <Or>
+ <Class name="~.*\_\$+logger"/>
+ <Class name="~.*\_\$+bundle"/>
+ </Or>
+ <Bug pattern="NM_CLASS_NAMING_CONVENTION"/>
+ </Match>
+
+ <!-- Throwing an exception on null, findbugs doesn't realize it -->
+ <Match>
+ <Class name="org.switchyard.transform.internal.TransformerRegistryLoader"/>
+ <Method name="getTransformerFactory"/>
+ <Bug pattern="NP_NULL_ON_SOME_PATH"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.standalone.SwitchYard"/>
+ <Bug pattern="WA_NOT_IN_LOOP"/>
+ </Match>
+
+ <!-- Occurs in test, okay to test for null here -->
+ <Match>
+ <Class name="org.switchyard.test.SwitchYardRunner"/>
+ <Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
+ </Match>
+
+ <!-- SWITCHYARD-1901 -->
+ <Match>
+ <Bug pattern="IS2_INCONSISTENT_SYNC"/>
+ </Match>
+
+ <!-- SWITCHYARD-1903 -->
+ <Match>
+ <Bug pattern="DM_DEFAULT_ENCODING"/>
+ </Match>
+
+ <!-- Give an exception to explicit garbage collection because of -->
+ <!-- SWITCHYARD-874 -->
+ <Match>
+ <Class name="org.switchyard.component.test.mixins.jca.SwitchYardIronJacamarHandler"/>
+ <Method name="startup"/>
+ <Bug pattern="DM_GC"/>
+ </Match>
+
+ <!-- SWITCHYARD-1887 -->
+ <Match>
+ <Or>
+ <Bug pattern="EI_EXPOSE_REP"/>
+ <Bug pattern="EI_EXPOSE_REP2"/>
+ </Or>
+ </Match>
+
+ <!-- Findbugs not taking into account other methods of class -->
+ <Match>
+ <Or>
+ <Class name="org.switchyard.component.camel.model.RouteScanner$RouteFilter"/>
+ <Class name="org.switchyard.transform.config.model.TransformSwitchYardScanner$TransformerInstanceOfFilter"/>
+ <Class name="org.switchyard.transform.xslt.internal.XsltTransformFactory$XsltTransformFactoryErrorListener"/>
+ <Class name="org.switchyard.validate.config.model.ValidateSwitchYardScanner$ValidatorInstanceOfFilter"/>
+ <Class name="org.switchyard.validate.xml.internal.XmlValidator$XmlValidatorLSInput"/>
+ <Class name="org.switchyard.component.rules.exchange.RulesExchangeHandler$FireUntilHalt"/>
+ <Class name="org.switchyard.validate.xml.internal.XmlValidator"/>
+ <Class name="org.switchyard.validate.config.model.ValidateSwitchYardScanner"/>
+ </Or>
+ <Bug pattern="SIC_INNER_SHOULD_BE_STATIC"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.common.version.Queries$Projects"/>
+ <Bug pattern="MS_PKGPROTECT"/>
+ </Match>
+
+ <!-- SWITCHYARD-1902 -->
+ <!-- Should we be creating ClassLoaders inside doPrivileged blocks?
+ Not sure what WildFly is doing here, we should do the same -->
+ <Match>
+ <Bug pattern="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"/>
+ </Match>
+
+ <!-- SWITCHYARD-1895 -->
+ <!-- Changing the name of the class may be changing public API - adding
+ a task and an exception for now -->
+ <Match>
+ <Class name="org.switchyard.security.principal.Group"/>
+ <Bug pattern="NM_SAME_SIMPLE_NAME_AS_INTERFACE"/>
+ </Match>
+
+ <!-- Logged SWITCHYARD-1894 -->
+ <Match>
+ <Class name="org.switchyard.security.credential.AssertionCredential"/>
+ <Bug pattern="SE_BAD_FIELD"/>
+ </Match>
+
+ <!-- SWITCHYARD-1898 -->
+ <!-- Investigate non-transient/non-serializable instance fields in
+ Serializable class -->
+ <Match>
+ <Class name="org.switchyard.component.bean.deploy.CDIBeanServiceDescriptor"/>
+ <Bug pattern="SE_BAD_FIELD"/>
+ </Match>
+
+ <!-- SWITCHYARD-1899 -->
+ <!-- Investigate non-transient/non-serializable instance fields in
+ Serializable class -->
+ <Match>
+ <Class name="org.switchyard.component.test.mixins.jca.MockConnectionFactory"/>
+ <Bug pattern="SE_BAD_FIELD"/>
+ </Match>
+
+ <!-- Investigate non-transient/non-serializable instance fields in
+ Serializable class -->
+ <Match>
+ <Class name="org.switchyard.component.sca.SwitchYardRemotingServlet"/>
+ <Bug pattern="SE_BAD_FIELD"/>
+ </Match>
+
+ <!-- In this instance, findbugs is just plain wrong. It complains that
+ Exception is not thrown within the try/catch, but it is clearly thrown
+ by MessageComposer.compose(). -->
+ <Match>
+ <Class name="org.switchyard.component.http.OutboundHandler"/>
+ <Bug pattern="REC_CATCH_EXCEPTION"/>
+ </Match>
+
+ <!-- In this instance findbugs, is wrong also - there are multiple accesses
+ so the AtomicInteger needs to be synchronized. -->
+ <Match>
+ <Class name="org.switchyard.remote.cluster.RoundRobinStrategy"/>
+ <Bug pattern="JLM_JSR166_UTILCONCURRENT_MONITORENTER"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.component.soap.AddressingInterceptor"/>
+ <Bug pattern="NP_ALWAYS_NULL"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.component.soap.composer.SOAPMessageComposer"/>
+ <Bug pattern="REC_CATCH_EXCEPTION"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.component.bpel.deploy.BPELComponent"/>
+ <Bug pattern="LI_LAZY_INIT_STATIC"/>
+ </Match>
+
+ <Match>
+ <Class name="org.switchyard.component.camel.SwitchYardProducer"/>
+ <Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
+ </Match>
+
+
</FindBugsFilter>
View
13 bus/camel/src/main/java/org/switchyard/bus/camel/DefaultErrorListener.java
@@ -34,23 +34,24 @@
public void notify(Exchange exchange, Throwable throwable) {
ExchangePattern pattern = exchange.getContract().getConsumerOperation().getExchangePattern();
- String message = String.format("%s\nCaught exception of type %s with message: %s", ExchangeFormatter.format(exchange, false), throwable.getClass().getName(), throwable.getMessage());
- String causeTrace = "";
+ String message = String.format("%s%nCaught exception of type %s with message: %s", ExchangeFormatter.format(exchange, false), throwable.getClass().getName(), throwable.getMessage());
+ StringBuilder causeTrace = new StringBuilder();
if (throwable.getCause() != null) {
- String causedBy = "\n%sCaused by exception of type %s, message: %s";
+ String causedBy = "%n%sCaused by exception of type %s, message: %s";
Throwable cause = throwable.getCause();
int depth = 0;
+
while (cause != null) {
- causeTrace += String.format(causedBy, Strings.repeat(" ", ++depth), cause.getClass().getName(), cause.getMessage());
+ causeTrace.append(String.format(causedBy, Strings.repeat(" ", ++depth), cause.getClass().getName(), cause.getMessage()));
cause = cause.getCause();
}
}
if (pattern == ExchangePattern.IN_ONLY) {
- LOG.error(message + causeTrace, throwable);
+ LOG.error(message + causeTrace.toString(), throwable);
} else {
- LOG.debug(message + causeTrace, throwable);
+ LOG.debug(message + causeTrace.toString(), throwable);
}
}
View
2  bus/camel/src/main/java/org/switchyard/bus/camel/processors/InterceptProcessor.java
@@ -144,7 +144,7 @@ boolean traceEnabled(Exchange ex) {
if (traceProp != null) {
boolean enabled = false;
if (Boolean.class.isAssignableFrom(traceProp.getClass())) {
- enabled = Boolean.valueOf((Boolean)traceProp);
+ enabled = ((Boolean)traceProp).booleanValue();
} else if (String.class.isAssignableFrom(traceProp.getClass())) {
enabled = Boolean.valueOf((String)traceProp);
} else {
View
2  common/core/src/main/java/org/switchyard/common/io/resource/ResourceType.java
@@ -431,7 +431,7 @@ public static ResourceType forLocation(String location) {
*/
public static void main(String... args) {
for (ResourceType type : values()) {
- System.out.printf("%s: %s %s\n", type.getName(), type.getDescription(), type.getExtensions());
+ System.out.printf("%s: %s %s%n", type.getName(), type.getDescription(), type.getExtensions());
}
}
View
8 common/core/src/main/java/org/switchyard/common/lang/Strings.java
@@ -78,15 +78,15 @@ public static String trimToNull(String str) {
* @return The repeated String.
*/
public static String repeat(String str, int repeatCount) {
- String repeated = "";
+ StringBuilder repeated = new StringBuilder();
if (str.isEmpty() || repeatCount <= 0) {
- return repeated;
+ return repeated.toString();
}
do {
- repeated += str;
+ repeated.append(str);
} while (--repeatCount > 0);
- return repeated;
+ return repeated.toString();
}
/**
View
22 common/core/src/main/java/org/switchyard/common/type/classpath/ClasspathScanner.java
@@ -110,16 +110,22 @@ private void handleArchive(File file) throws IOException {
}
ZipFile zip = new ZipFile(file);
- Enumeration<? extends ZipEntry> entries = zip.entries();
+ try {
+ Enumeration<? extends ZipEntry> entries = zip.entries();
- while (entries.hasMoreElements()) {
- if (!_filter.continueScanning()) {
- break;
- }
+ while (entries.hasMoreElements()) {
+ if (!_filter.continueScanning()) {
+ break;
+ }
- ZipEntry entry = entries.nextElement();
- String name = entry.getName();
- _filter.filter(name);
+ ZipEntry entry = entries.nextElement();
+ String name = entry.getName();
+ _filter.filter(name);
+ }
+ } catch (IllegalStateException ise) {
+ throw new IOException(ise);
+ } finally {
+ zip.close();
}
}
View
41 common/core/src/main/java/org/switchyard/common/type/reflect/FieldAccess.java
@@ -45,9 +45,7 @@ public FieldAccess(Field field) {
public FieldAccess(Class<?> clazz, String fieldName) {
Field field;
fieldName = Strings.trimToNull(fieldName);
- if (fieldName == null) {
- field = null;
- } else {
+ if (fieldName != null) {
try {
field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException nsfe1) {
@@ -57,13 +55,16 @@ public FieldAccess(Class<?> clazz, String fieldName) {
field = null;
}
}
+
+ if (field != null) {
+ setField(field);
+ }
}
- setField(field);
}
private void setField(Field field) {
_field = field;
- if (!_field.isAccessible()) {
+ if ((field != null) && (!_field.isAccessible())) {
_field.setAccessible(true);
}
}
@@ -73,7 +74,11 @@ private void setField(Field field) {
*/
@Override
public String getName() {
- return _field.getName();
+ if (_field != null) {
+ return _field.getName();
+ } else {
+ return null;
+ }
}
/**
@@ -82,7 +87,11 @@ public String getName() {
@Override
@SuppressWarnings("unchecked")
public Class<T> getType() {
- return (Class<T>)_field.getType();
+ if (_field != null) {
+ return (Class<T>)_field.getType();
+ } else {
+ return null;
+ }
}
/**
@@ -90,7 +99,11 @@ public String getName() {
*/
@Override
public boolean isReadable() {
- return !Modifier.isStatic(_field.getModifiers());
+ if (_field != null) {
+ return !Modifier.isStatic(_field.getModifiers());
+ } else {
+ return false;
+ }
}
/**
@@ -98,8 +111,12 @@ public boolean isReadable() {
*/
@Override
public boolean isWriteable() {
- int mod = _field.getModifiers();
- return !Modifier.isStatic(mod) && !Modifier.isFinal(mod);
+ if (_field != null) {
+ int mod = _field.getModifiers();
+ return !Modifier.isStatic(mod) && !Modifier.isFinal(mod);
+ } else {
+ return false;
+ }
}
/**
@@ -112,6 +129,8 @@ public T read(Object target) {
return (T)_field.get(target);
} catch (IllegalAccessException iae) {
throw new RuntimeException(iae);
+ } catch (NullPointerException npe) {
+ throw new RuntimeException(npe);
}
}
@@ -124,6 +143,8 @@ public void write(Object target, T value) {
_field.set(target, value);
} catch (IllegalAccessException iae) {
throw new RuntimeException(iae);
+ } catch (NullPointerException npe) {
+ throw new RuntimeException(npe);
}
}
View
5 config/src/main/java/org/switchyard/config/model/NamespaceComparator.java
@@ -13,6 +13,7 @@
*/
package org.switchyard.config.model;
+import java.io.Serializable;
import java.util.Comparator;
/**
@@ -20,8 +21,8 @@
*
* @author David Ward &lt;<a href="mailto:dward@jboss.org">dward@jboss.org</a>&gt; &copy; 2011 Red Hat Inc.
*/
-class NamespaceComparator implements Comparator<String> {
-
+class NamespaceComparator implements Comparator<String>, Serializable {
+ private final static long serialVersionUID = 1L;
private static final String W3 = "http://www.w3.org/";
private static final String OASIS_WSS = "http://docs.oasis-open.org/wss/";
View
6 config/src/main/java/org/switchyard/config/model/composite/v1/PolicyConfig.java
@@ -58,11 +58,11 @@ public static void setRequires(Model model, Set<String> requiredSet) {
return;
}
Iterator<String> it = requiredSet.iterator();
- String requires = it.next();
+ StringBuilder requires = new StringBuilder(it.next());
while (it.hasNext()) {
- requires += " " + it.next();
+ requires.append(" " + it.next());
}
- model.getModelConfiguration().setAttribute(REQUIRES, requires);
+ model.getModelConfiguration().setAttribute(REQUIRES, requires.toString());
}
}
View
8 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeReferenceModel.java
@@ -103,11 +103,9 @@ public CompositeModel getComposite() {
} else if (namesCount == 2) {
for (ComponentReferenceModel componentReference : componentReferences) {
if (componentReferenceName.equals(componentReference.getName())) {
- if (componentReference != null) {
- list.add(componentReference);
- componentMissing = false;
- break componentLoop;
- }
+ list.add(componentReference);
+ componentMissing = false;
+ break componentLoop;
}
}
}
View
4 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeServiceModel.java
@@ -103,9 +103,7 @@ public ComponentServiceModel getComponentService() {
} else if (namesCount == 2) {
for (ComponentServiceModel componentService : componentServices) {
if (componentServiceName.equals(componentService.getName())) {
- if (componentService != null) {
- return componentService;
- }
+ return componentService;
}
}
}
View
1  remote/src/main/java/org/switchyard/remote/cluster/RoundRobinStrategy.java
@@ -58,5 +58,4 @@ public RemoteEndpoint selectEndpoint(QName serviceName) {
return selectedEp;
}
-
}
View
6 runtime/src/main/java/org/switchyard/handlers/PolicyHandler.java
@@ -54,11 +54,11 @@ public void handleMessage(Exchange exchange) throws HandlerException {
if (!required.isEmpty()) {
// Required policies are missing. Format the list for fault message.
Iterator<Policy> missing = required.iterator();
- String requires = missing.next().getName();
+ StringBuilder requires = new StringBuilder(missing.next().getName());
while (missing.hasNext()) {
- requires += " " + missing.next().getName();
+ requires.append(" " + missing.next().getName());
}
- throw RuntimeMessages.MESSAGES.requiredPolicesNeeded(requires);
+ throw RuntimeMessages.MESSAGES.requiredPolicesNeeded(requires.toString());
}
}
}
View
6 runtime/src/main/java/org/switchyard/internal/DefaultHandlerChain.java
@@ -154,12 +154,12 @@ public void handleMessage(Exchange exchange) {
}
}
} catch (HandlerException handlerEx) {
- String errorMsg = handlerEx.getClass().getName() + " was thrown by handler(" + handlerRef.getName() + "): " + handlerEx.getMessage();
+ StringBuilder errorMsg = new StringBuilder(handlerEx.getClass().getName() + " was thrown by handler(" + handlerRef.getName() + "): " + handlerEx.getMessage());
Throwable cause = handlerEx;
while ((cause = cause.getCause()) != null) {
- errorMsg += " --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage();
+ errorMsg.append(" --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage());
}
- _logger.error(errorMsg);
+ _logger.error(errorMsg.toString());
_logger.debug("", handlerEx);
Message faultMessage = exchange.createMessage().setContent(handlerEx);
View
5 runtime/src/main/java/org/switchyard/internal/DefaultServiceRegistry.java
@@ -94,10 +94,11 @@ public synchronized void unregisterService(Service service) {
@Override
public void registerServiceReference(ServiceReference reference) {
- _references.putIfAbsent(reference.getName(), reference);
+ ServiceReference ref = _references.putIfAbsent(reference.getName(), reference);
if (_logger.isDebugEnabled()) {
- _logger.debug("Registered ServiceReference '" + reference.getName() + "'.");
+ _logger.debug("Registered ServiceReference '" + reference.getName() + "', "
+ + "found previous map value of " + ref + ".");
}
}
View
2  serial/base/src/main/java/org/switchyard/serial/graph/Graph.java
@@ -31,7 +31,7 @@
*/
@SuppressWarnings("serial")
public final class Graph implements Serializable {
-
+ private final static long serialVersionUID = 1L;
private Integer _root;
private Map<Integer, Object> _references = new LinkedHashMap<Integer, Object>();
private transient Map<Object, Integer> _ids;
View
6 serial/base/src/main/java/org/switchyard/serial/graph/node/InputStreamNode.java
@@ -73,6 +73,12 @@ public void compose(Object obj, Graph graph) {
bos.flush();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
+ } finally {
+ try {
+ bis.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
setBase64(Base64.encode(baos.toByteArray()));
}
View
9 serial/base/src/main/java/org/switchyard/serial/graph/node/MapNode.java
@@ -13,6 +13,7 @@
*/
package org.switchyard.serial.graph.node;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -57,10 +58,14 @@ public void setIds(LinkedHashMap<Integer, Integer> ids) {
public void compose(Object obj, Graph graph) {
_ids = new LinkedHashMap<Integer, Integer>();
Map map = (Map)obj;
- for (Object key : map.keySet()) {
+
+ Iterator it = map.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry pairs = (Map.Entry)it.next();
+ Object key = pairs.getKey();
Integer key_id = NodeBuilder.build(key, graph);
if (!(graph.getReference(key_id) instanceof NoopNode)) {
- Object val = map.get(key);
+ Object val = pairs.getValue();
Integer val_id = NodeBuilder.build(val, graph);
if (!(graph.getReference(val_id) instanceof NoopNode)) {
_ids.put(key_id, val_id);
View
27 tools/forge/common/src/main/java/org/switchyard/tools/forge/GenericTestForge.java
@@ -20,11 +20,12 @@
*/
public abstract class GenericTestForge extends AbstractShellTest {
- private static String switchyardVersion;
+ private static String switchyardVersion = Versions.getSwitchYardVersion();
- private static OutputStream outputStream;
+ private OutputStream _outputStream;
- private static String switchyardVersionSuccessMsg;
+ private static String switchyardVersionSuccessMsg = "SwitchYard version "
+ + Versions.getSwitchYardVersion();
private static final String FORGE_APP_NAME = "ForgeTestApp";
@@ -32,8 +33,6 @@
* Constructor.
*/
public GenericTestForge() {
- switchyardVersion = Versions.getSwitchYardVersion();
- switchyardVersionSuccessMsg = "SwitchYard version " + switchyardVersion;
}
/**
@@ -48,12 +47,12 @@ public void prepareSwitchyardForge() throws IOException {
queueInputLines(FORGE_APP_NAME);
getShell().execute("project install-facet switchyard");
getShell().execute("switchyard get-version");
- Assert.assertTrue(outputStream.toString().contains(switchyardVersionSuccessMsg));
- System.out.println(outputStream);
+ Assert.assertTrue(_outputStream.toString().contains(switchyardVersionSuccessMsg));
+ System.out.println(_outputStream);
resetOutputStream();
} catch (Exception e) {
e.printStackTrace();
- System.out.println(outputStream);
+ System.out.println(_outputStream);
}
}
@@ -85,16 +84,16 @@ protected void build() {
* 2 - Before invoking forge operations which will subsequently be asserted in order
* to avoid the assertion to wrongly match previous similar output lines
*/
- public void resetOutputStream() {
- if (outputStream != null) {
+ public synchronized void resetOutputStream() {
+ if (_outputStream != null) {
try {
- outputStream.close();
+ _outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
- outputStream = new OutputStream() {
+ _outputStream = new OutputStream() {
private StringBuilder _stringBuilder = new StringBuilder();
@Override
public void write(int b) throws IOException {
@@ -107,7 +106,7 @@ public String toString() {
TerminalFactory.configure(TerminalFactory.Type.AUTO);
Terminal terminal = TerminalFactory.get();
- BufferManager screenBuffer = new JLineScreenBuffer(terminal, outputStream);
+ BufferManager screenBuffer = new JLineScreenBuffer(terminal, _outputStream);
getShell().registerBufferManager(screenBuffer);
}
@@ -125,7 +124,7 @@ public static String getSwitchyardVersion() {
* latest reset output stream reset {@link #resetOutputStream()}
*/
public String getOutput() {
- return outputStream.toString();
+ return _outputStream.toString();
}
View
17 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/SwitchYardFacet.java
@@ -215,7 +215,10 @@ public synchronized SwitchYardModel getSwitchYardConfig() {
_shell.println("Error while reading SwitchYard configuration: " + ioEx.getMessage());
}
}
- config.orderModelChildren();
+
+ if (config != null) {
+ config.orderModelChildren();
+ }
return config;
}
@@ -440,8 +443,11 @@ void addSwitchYardToASConfig(String asConfigPath) throws Exception {
}
File backup = new File(asConfigPath + ".orig");
if (backup.exists()) {
- if (_shell.promptBoolean("backup standalone.xml '" + backup.getAbsolutePath() + "' already exists: remove it?")) {
- backup.delete();
+ if (_shell.promptBoolean("backup standalone.xml '" + backup.getAbsolutePath() + "' already exists: remove it?")) {
+ boolean result = backup.delete();
+ if (!result) {
+ throw new Exception("Unable to delete " + backup.getAbsolutePath());
+ }
} else {
throw new Exception("backup standalone.xml already exists " + backup.getAbsolutePath());
}
@@ -449,7 +455,10 @@ void addSwitchYardToASConfig(String asConfigPath) throws Exception {
if (!orig.renameTo(backup)) {
throw new Exception("Failed to create backup standalone.xml " + backup.getAbsolutePath());
}
- orig.createNewFile();
+ boolean createResult = orig.createNewFile();
+ if (!createResult) {
+ throw new Exception("Unable to create new file " + orig.getAbsolutePath());
+ }
// transform the original
InputStream xslStream = null;
View
6 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/SwitchYardPlugin.java
@@ -421,7 +421,11 @@ public void importArtifacts(
try {
File artifactDir = new File(ARTIFACT_DIR);
if (!artifactDir.exists()) {
- artifactDir.mkdirs();
+ boolean result = artifactDir.mkdirs();
+ if (!result) {
+ out.println(out.renderColor(ShellColor.RED, "Unable to create directory: "
+ + artifactDir.getAbsolutePath()));
+ }
}
// detect if this is a Guvnor repository
if (url.getProtocol().contains("http") && url.getPath().contains("rest/packages")) {
View
10 tools/forge/plugin/src/main/java/org/switchyard/tools/forge/plugin/TemplateResource.java
@@ -103,16 +103,16 @@ public String writeJavaSource(ResourceFacet resources,
packageName(packageName);
- String destDir = ".." + File.separator + ".." + File.separator
+ StringBuilder destDir = new StringBuilder(".." + File.separator + ".." + File.separator
+ File.separator + (isTest ? "test" : "main")
- + File.separator + "java";
+ + File.separator + "java");
if (packageName != null && packageName.length() > 0) {
for (String pkgDir : packageName.split("\\.")) {
- destDir += File.separator + pkgDir;
- }
+ destDir.append(File.separator + pkgDir);
+ }
}
String destFile = className + ".java";
- writeResource(resources.getResource(destDir + File.separator + destFile));
+ writeResource(resources.getResource(destDir.toString() + File.separator + destFile));
return destFile;
}
View
10 transform/src/main/java/org/switchyard/transform/internal/TransformerRegistryLoader.java
@@ -237,8 +237,16 @@ private String toDescription(Transformer<?, ?> transformer) {
}
return _transformerFactories.get(factoryClass);
- } catch (Exception e) {
+ } catch (ClassCastException e) {
throw TransformMessages.MESSAGES.failedCreateInstanceofTransformerFactory(factoryClass.getName());
+ } catch (IllegalArgumentException iae) {
+ throw TransformMessages.MESSAGES.failedCreateInstanceofTransformerFactory(factoryClass.getName());
+ } catch (NullPointerException npe) {
+ throw TransformMessages.MESSAGES.failedCreateInstanceofTransformerFactory(factoryClass.getName());
+ } catch (InstantiationException ie) {
+ throw TransformMessages.MESSAGES.failedCreateInstanceofTransformerFactory(factoryClass.getName());
+ } catch (IllegalAccessException iae) {
+ throw TransformMessages.MESSAGES.failedCreateInstanceofTransformerFactory(factoryClass.getName());
}
}
}
View
3  transform/src/main/java/org/switchyard/transform/internal/TransformerUtil.java
@@ -14,6 +14,7 @@
package org.switchyard.transform.internal;
+import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -336,7 +337,7 @@ public String toString() {
}
}
- private static final class TransformerTypesComparator implements Comparator<TransformerTypes> {
+ private static final class TransformerTypesComparator implements Comparator<TransformerTypes>, Serializable {
/**
* {@inheritDoc}
*/
View
6 transform/src/main/java/org/switchyard/transform/ootb/lang/ExceptionTransforms.java
@@ -35,10 +35,10 @@
@Transformer
public String toString(Throwable t) {
Throwable cause = t;
- String result = cause.getClass().getName() + ": " + cause.getMessage();
+ StringBuilder result = new StringBuilder(cause.getClass().getName() + ": " + cause.getMessage());
while ((cause = cause.getCause()) != null) {
- result += NL + " --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage();
+ result.append(NL + " --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage());
}
- return result;
+ return result.toString();
}
}
View
8 transform/src/main/java/org/switchyard/transform/xslt/internal/TransformerPool.java
@@ -21,6 +21,8 @@
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
+import org.jboss.logging.Logger;
+
/**
* Provides a pool of javax.xml.transform.Transformer instances which are
* created on demand and bounded by a pool maxSize. If a pooled instance
@@ -28,6 +30,7 @@
* to the pool.
*/
public class TransformerPool {
+ private Logger _logger = Logger.getLogger(TransformerPool.class);
private BlockingQueue<Transformer> _pool;
private Templates _templates;
@@ -95,7 +98,10 @@ private void addTransformer() throws Exception {
transformer.setErrorListener(_errorListener);
}
_count.incrementAndGet();
- _pool.offer(transformer);
+ boolean result = _pool.offer(transformer);
+ if ((!result) && (_logger.isDebugEnabled())) {
+ _logger.debug("Unable to add " + transformer.toString() + " to blocking queue");
+ }
}
}
View
3  validate/src/main/java/org/switchyard/validate/internal/ValidatorUtil.java
@@ -14,6 +14,7 @@
package org.switchyard.validate.internal;
+import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -402,7 +403,7 @@ public String toString() {
}
}
- private static final class ValidatorTypesComparator implements Comparator<ValidatorTypes> {
+ private static final class ValidatorTypesComparator implements Comparator<ValidatorTypes>, Serializable {
/**
* {@inheritDoc}
*/
View
9 validate/src/main/java/org/switchyard/validate/xml/internal/XmlValidator.java
@@ -100,8 +100,15 @@ public XmlValidator(QName name, XmlValidateModel model) {
_schemaTypeUri = XMLConstants.RELAXNG_NS_URI;
break;
default:
+ StringBuilder builder = new StringBuilder();
+ for (XmlSchemaType s : XmlSchemaType.values()) {
+ builder.append(s.name() + ", ");
+ }
+ if (builder.length() >= 2) {
+ builder.delete(builder.length()-2, builder.length());
+ }
throw ValidateMessages.MESSAGES.couldNotInstantiateXmlValidatorBadSchemaType(_schemaType.toString(),
- XmlSchemaType.values().toString());
+ builder.toString());
}
_failOnWarning = model.failOnWarning();
Please sign in to comment.
Something went wrong with that request. Please try again.