Author: davsclaus Date: Fri Mar 4 07:12:40 2011 New Revision: 1077837 URL: http://svn.apache.org/viewvc?rev=1077837&view=rev Log: CAMEL-3741: Improved error handling when error during executing program call. Thanks to Luis Santos for patch.
Added: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java (with props) Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java Added: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java?rev=1077837&view=auto ============================================================================== --- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java (added) +++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java Fri Mar 4 07:12:40 2011 @@ -0,0 +1,28 @@ +/** + * 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.camel.component.jt400; + +import org.apache.camel.RuntimeCamelException; + +public class Jt400PgmCallException extends RuntimeCamelException { + + private static final long serialVersionUID = 1112933724598115479L; + + public Jt400PgmCallException(String message) { + super(message); + } +} Propchange: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmCallException.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java?rev=1077837&r1=1077836&r2=1077837&view=diff ============================================================================== --- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java (original) +++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java Fri Mar 4 07:12:40 2011 @@ -24,7 +24,6 @@ import com.ibm.as400.access.AS400Message import com.ibm.as400.access.AS400Text; import com.ibm.as400.access.ProgramCall; import com.ibm.as400.access.ProgramParameter; - import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; import org.apache.camel.impl.DefaultProducer; @@ -34,14 +33,14 @@ import org.slf4j.LoggerFactory; public class Jt400PgmProducer extends DefaultProducer { - private static final Logger LOG = LoggerFactory.getLogger(Jt400PgmProducer.class); + private static final Logger LOG = LoggerFactory.getLogger(Jt400PgmProducer.class); public Jt400PgmProducer(Jt400PgmEndpoint endpoint) { super(endpoint); } private Jt400PgmEndpoint getISeriesEndpoint() { - return (Jt400PgmEndpoint)super.getEndpoint(); + return (Jt400PgmEndpoint) super.getEndpoint(); } public void process(Exchange exchange) throws Exception { @@ -57,30 +56,27 @@ public class Jt400PgmProducer extends De if (LOG.isDebugEnabled()) { LOG.trace("Starting to call PGM '" + commandStr + "' in host '" + iSeries.getSystemName() - + "' authenticatin with the user '" + iSeries.getUserId() + "'"); + + "' authentication with the user '" + iSeries.getUserId() + "'"); } boolean result = pgmCall.run(); if (LOG.isTraceEnabled()) { - LOG.trace("Executed PGM '" + commandStr + "' in host '" + iSeries.getSystemName() + "'. Success?" - + result); + LOG.trace("Executed PGM '" + commandStr + "' in host '" + iSeries.getSystemName() + "'. Success? " + result); } if (result) { handlePGMOutput(exchange, pgmCall, parameterList); } else { - // TODO Do we need to throw an exception - handleMessages(pgmCall); + throw new Jt400PgmCallException(getOutputMessages(pgmCall)); } - } private ProgramParameter[] getParameterList(Exchange exchange) throws InvalidPayloadException { Object body = ExchangeHelper.getMandatoryInBody(exchange); - String[] params = (String[])body; + String[] params = (String[]) body; ProgramParameter[] parameterList = new ProgramParameter[params.length]; for (int i = 0; i < params.length; i++) { @@ -92,7 +88,7 @@ public class Jt400PgmProducer extends De byte[] inputData = null; int outputLength = -1; if (input) { - String value = (String)param; + String value = (String) param; inputData = new AS400Text(value.length()).toBytes(value); } if (output) { @@ -113,11 +109,10 @@ public class Jt400PgmProducer extends De return parameterList; } - private void handlePGMOutput(Exchange exchange, ProgramCall pgmCall, ProgramParameter[] inputs) - throws InvalidPayloadException { + private void handlePGMOutput(Exchange exchange, ProgramCall pgmCall, ProgramParameter[] inputs) throws InvalidPayloadException { Object bodyIN = ExchangeHelper.getMandatoryInBody(exchange); - String[] params = (String[])bodyIN; + String[] params = (String[]) bodyIN; List<String> results = new ArrayList<String>(); @@ -129,10 +124,9 @@ public class Jt400PgmProducer extends De if (output != null) { int length = pgmParam.getOutputDataLength(); - length = pgmParam.getOutputDataLength(); AS400Text text = new AS400Text(length); - value = (String)text.toObject(output); + value = (String) text.toObject(output); } results.add(value); @@ -145,16 +139,19 @@ public class Jt400PgmProducer extends De exchange.getOut().setBody(bodyOUT); } - private void handleMessages(ProgramCall pgmCall) throws Exception { + private String getOutputMessages(ProgramCall pgmCall) throws Exception { + StringBuilder outputMsg = new StringBuilder(); // Show messages. - if (LOG.isDebugEnabled()) { - AS400Message[] messageList = pgmCall.getMessageList(); - for (int i = 0; i < messageList.length; ++i) { - // Load additional message information. - messageList[i].load(); - // Show each message. - LOG.debug("The message list [" + i + "]" + messageList[i].getText() + ", help info: " + messageList[i].getHelp()); - } + AS400Message[] messageList = pgmCall.getMessageList(); + for (int i = 0; i < messageList.length; ++i) { + // Load additional message information. + messageList[i].load(); + outputMsg.append(i + ") "); + outputMsg.append(messageList[i].getText()); + outputMsg.append(" - "); + outputMsg.append(messageList[i].getHelp()); + outputMsg.append("\n"); } + return outputMsg.toString(); } }