Thanks for your reply.
I have removed the entire maven repository which was created at my local
machine. Now the problem is resolved. But now while building I am facing a
new issue.
I was using
import org.apache.servicemix.client.Destination;
this class in my code. The code looks like this:
package com.in2m.servicemix.common.errorhandling;
import java.io.IOException;
import java.io.StringReader;
import javax.jbi.JBIException;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.camel.Exchange;
import org.apache.servicemix.camel.JbiExchange;
import org.apache.servicemix.client.ClientFactory;
import org.apache.servicemix.client.Destination;
import org.apache.servicemix.client.ServiceMixClient;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.thoughtworks.xstream.XStream;
/**
* @author pghogale
*
*/
public class ErrorEnrich {
/**
* @param exchange
* @throws TransformerException
*/
public static void sendErrorToErrorHandler(Exchange exchange) throws
TransformerException {
try {
String errorMessage=createErrorMessageForErrorHandler(exchange);
sendMessageToErrorHandler(exchange,errorMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param exchange
* @return
* @throws SAXException
* @throws IOException
* @throws ParserConfigurationException
* @throws XPathExpressionException
* @throws MessagingException
* @throws TransformerException
*/
private static String getErrorMessage(Exchange exchange) throws
SAXException, IOException, ParserConfigurationException,
XPathExpressionException, MessagingException, TransformerException {
String errorMessage=null;
if(exchange.getProperty(ErrorConstants.ERROR)!=null){
return
exchange.getProperty(ErrorConstants.ERROR).toString();
}
String outMessage=exchange.getOut().getBody(String.class);
if(!(outMessage.equals(ErrorConstants.NULL))){
Document
responseDocument=createDocumentByString(outMessage);
errorMessage=getErrorMessageFromResponse(responseDocument);
}
return errorMessage;
}
/**
* @param exchange
* @param errorMessage
* @throws NamingException
* @throws JBIException
*/
private static void sendMessageToErrorHandler(Exchange exchange, String
errorMessage) throws NamingException, JBIException {
String errorCode=getErrorCode(exchange);
JbiExchange jbiexchange = (JbiExchange) exchange;
String appName=
jbiexchange.getIn().getHeader(ErrorConstants.APPLICATION_NAME).toString();
ClientFactory factory = (ClientFactory) new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
ServiceMixClient client = factory.createClient();
Destination destination;
if(errorCode.equals(ErrorConstants.BUSINESS_ERROR) ||
(errorCode.equals(ErrorConstants.SOCKET_ERROR))){
destination =
client.createDestination("service:http://servicemix.in2m.com/operations/errorhandler/ApplicationErrorService");
}else{
destination =
client.createDestination("service:http://servicemix.in2m.com/operations/errorhandler/SystemErrorService");
}
InOnly newExchange = destination.createInOnlyExchange();
NormalizedMessage request = newExchange.getInMessage();
request.setContent(new StreamSource(new StringReader(errorMessage)));
String
serviceName="jbi:service:http://servicemix.in2m.com/operations/errorhandler/"+appName;
request.setProperty(ErrorConstants.APPLICATION_NAME,appName);
request.setProperty(ErrorConstants.SERVICE_NAME,serviceName);
client.send(newExchange);
}
/**
* @param exchange
* @param errorMessage
* @return
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
* @throws TransformerException
* @throws MessagingException
* @throws XPathExpressionException
*/
private static String createErrorMessageForErrorHandler(Exchange
exchange)
throws IOException, ParserConfigurationException, SAXException,
XPathExpressionException, MessagingException, TransformerException {
String errorMessage=getErrorMessage(exchange);
String errorCode=getErrorCode(exchange);
JbiExchange jbiexchange = (JbiExchange) exchange;
String request=exchange.getIn().getBody(String.class);
String
message=createErrorMessage(errorMessage,errorCode,request);
return message;
}
/**
* @param exchange
* @return
*/
private static String getErrorCode(Exchange exchange) {
return (String) exchange.getProperty(ErrorConstants.ERROR_CODE);
}
/**
* @param errorMessage
* @param errorCode
* @param request
* @param serviceName
* @return
*/
private static String createErrorMessage(String errorMessage, String
errorCode, String request) {
XStream xstream = new XStream();
xstream.alias(ErrorConstants.ERROR_MESSAGE_ROOT,
ErrorMessage.class);
ErrorMessage error = new ErrorMessage();
error.setErrorCode(errorCode);
error.setMessage(errorMessage);
error.setRequestData(request);
String xml = xstream.toXML(error);
return xml;
}
/**
* @param responseDocument
* @return
* @throws XPathExpressionException
*/
private static String getErrorMessageFromResponse(Document
responseDocument) throws XPathExpressionException {
String errorMessage=null;
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr =
xpath.compile("//response[status!='"+ErrorConstants.SUCCESS+"']/message/text()");
Object result = expr.evaluate(responseDocument,
XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
if(nodes.getLength()>0){
errorMessage= nodes.item(0).getNodeValue();
}
return errorMessage;
}
/**
* @param outMessage
* @return
* @throws SAXException
* @throws IOException
* @throws ParserConfigurationException
*/
private static Document createDocumentByString(String outMessage) throws
SAXException, IOException, ParserConfigurationException {
Document doc=
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
InputSource(new StringReader(outMessage)));
doc.normalize();
return doc;
}
}
Now it gives me following error:
INFO]
------------------------------------------------------------------------
[INFO] Compilation failure
/home/pghogale/dev/smxesb/common/errorhandling/src/main/java/com/in2m/servicemix/common/errorhandling/ErrorEnrich.java:[87,44]
incompatible types
found : org.apache.servicemix.jbi.api.Destination
required: org.apache.servicemix.client.Destination
/home/pghogale/dev/smxesb/common/errorhandling/src/main/java/com/in2m/servicemix/common/errorhandling/ErrorEnrich.java:[89,44]
incompatible types
found : org.apache.servicemix.jbi.api.Destination
required: org.apache.servicemix.client.Destination
Why is this error when I am using org.apache.servicemix.client.Destination
this itself.
Please help,
Thanks,
Pratibha
--
View this message in context:
http://old.nabble.com/Error-while-building-the-project-with-maven-while-using-servicemix3.3.1-tp27714850p27715939.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.