[jboss-svn-commits] JBL Code SVN: r7446 - in labs/jbossesb/trunk/product/samples/trailblazer2/client: . src src/org src/org/jboss src/org/jboss/soa src/org/jboss/soa/esb src/org/jboss/soa/esb/samples src/org/jboss/soa/esb/samples/trailblazer src/org/jboss/soa/esb/samples/trailblazer/web
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 7 15:03:07 EST 2006
Author: daniel.brum at jboss.com
Date: 2006-11-07 15:03:06 -0500 (Tue, 07 Nov 2006)
New Revision: 7446
Added:
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/Launcher.java
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/LoanBrokerWS.java
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/WebCustomer.java
Log:
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/Launcher.java 2006-11-07 20:03:02 UTC (rev 7445)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/Launcher.java 2006-11-07 20:03:06 UTC (rev 7446)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.samples.trailblazer.web;
+
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.listeners.message.*;
+
+public class Launcher {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception
+ {
+// DOMConfigurator.configure("log4j.xml");
+// final String CONFIG_FILE = "conf/LoanBrokerConfig.xml";
+// String configFile=null;
+// if (args.length < 1) {
+// System.out.println("Going to use default path to config file:" + CONFIG_FILE);
+// configFile=CONFIG_FILE;
+// } else {
+// configFile=args[0];
+// }
+// System.out.println("Using configFile=" + configFile);
+// GpListener oProc = new GpListener(configFile);
+// oProc.run();
+// GpListener.State oS = oProc.getState();
+//
+// if (null!=oS.getException())
+// {
+// org.apache.log4j.Logger.getLogger(Launcher.class).error
+// ("GpListener <"+args[0]+"> FAILED\n",oS.getException());
+// }
+// System.exit(oS.getCompletionCode());
+
+ }
+
+}
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/LoanBrokerWS.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/LoanBrokerWS.java 2006-11-07 20:03:02 UTC (rev 7445)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/LoanBrokerWS.java 2006-11-07 20:03:06 UTC (rev 7446)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
+package org.jboss.soa.esb.samples.trailblazer.web;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.JmsQueueReplyListener;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.parameters.ParamRepository;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * The Loan broker web service, which will handle a loan request. First a credit
+ * score is obtained from a credit agency. Then 2 banks are send request for
+ * an interest rate quote.
+ */
+ at WebService(name = "LoanBrokerWS", targetNamespace = "http://localhost/loanbroker")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public class LoanBrokerWS
+{
+ @WebMethod
+ // method name is .NET friendly
+ public void RequestLoan(WebCustomer customer) {
+ try {
+ /**
+ * Use the JBoss ESB services to send the message onto it's destination.
+ * This is only possible with ESB Message Aware services -
+ * see the TODO: add name of package which interacts with banks
+ * to see how a non-Message aware situation is handled
+ */
+ logger.info("WebCustomer received: " + customer);
+ Message replyMessage = null;
+
+ if (config == null) {
+ readConfigurationFile();
+ }
+
+ //Step 1 - convert customer from web service into a ESB Message
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ message.getBody().setContents(Base64.encodeObject(customer).getBytes());
+
+ //step 2 - locate the service in the registry
+ Registry registry = RegistryFactory.getRegistry();
+ String serviceCategoryName = config.getAttribute(SERVICE_CAT);
+ String serviceName = config.getAttribute(SERVICE_NAME);
+
+ logger.debug("looking for the following service in the registry -- Category: " + serviceCategoryName);
+ logger.debug("looking for the following service in the registry -- Name: " + serviceName);
+
+ Collection<EPR> eprs = registry.findEPRs(serviceCategoryName, serviceName);
+
+ //Step 3 - use the service to send the message
+ for (Iterator<EPR> eprIterator=eprs.iterator();eprIterator.hasNext();){
+ //Just use the first EPR in the list.
+ EPR epr = eprIterator.next();
+ Courier courier = CourierFactory.getCourier(epr);
+ //If not successful try the next EPR
+ if (JMSEpr.class.equals(epr.getClass())) {
+ //create a reply-to EPR
+ JmsQueueReplyListener jmsQueueReplyListener = new JmsQueueReplyListener();
+ JMSEpr jpr = (JMSEpr)epr;
+ JMSEpr replyEpr = null;
+ replyEpr =
+ new JMSEpr(jpr.getDestinationType()
+ ,jpr.getDestinationName()
+ ,jpr.getConnectionFactory()
+ ,jpr.getJndiType()
+ ,jpr.getJndiURL()
+ ,jmsQueueReplyListener.getReplySelector()
+ );
+ message.getHeader().getCall().setReplyTo(replyEpr);
+ if (courier.deliver(message)) {
+ replyMessage = jmsQueueReplyListener.listen(replyEpr);
+ logger.info("reply from service received: " + replyMessage);
+ break;
+ } else {
+ logger.warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
+ }
+ } else {
+ logger.warn("Found a non-JMS EPR, but since we want a reply we need a JMS-EPR");
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error(e);
+ }
+
+ }
+
+ private void readConfigurationFile()
+ throws ParamRepositoryException, IOException, SAXException
+ {
+ //Reading the config file
+ ParamRepository parmRepository = ParamRepositoryFactory.getInstance();
+ String sXml = parmRepository.get(CONFIG_FILE);
+ config = ConfigTree.fromXml(sXml);
+ }
+
+// public static void main(String args[]) throws Exception {
+//
+// LoanBrokerWS ws = new LoanBrokerWS();
+// WebCustomer customer = new WebCustomer("John Doe", "123 My St.",
+// "JBoss", 50.00, 12, 100.00, 123456, "john at cashisking.com");
+// ws.RequestLoan(customer);
+// }
+
+ //class attributes
+ private static Logger logger = Logger.getLogger(LoanBrokerWS.class);
+ ConfigTree config = null;
+ private final String CONFIG_FILE = "jbossesb-trailblazer.xml";
+ private final String SERVICE_NAME = "org.jboss.soa.esb.trailblazer.request.service.epr.name";
+ private final String SERVICE_CAT = "org.jboss.soa.esb.trailblazer.request.service.category";
+
+}
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/WebCustomer.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/WebCustomer.java 2006-11-07 20:03:02 UTC (rev 7445)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/web/WebCustomer.java 2006-11-07 20:03:06 UTC (rev 7446)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+/*
+ * a simple web Customer to use in the web services call and not expose the internal esb Customer object
+ */
+package org.jboss.soa.esb.samples.trailblazer.web;
+
+import java.io.Serializable;
+
+ at SuppressWarnings("serial")
+public class WebCustomer implements Serializable
+{
+ public String name ,address ,employerName;
+ public double salary ,loanAmount;
+ public int loanDuration;
+ public int ssn;
+ public String email;
+
+
+ public WebCustomer(){}
+
+ public WebCustomer(String name, String address, String employerName, double salary, int loanDuration, double loanAmount, int ssn,String email)
+ {
+ this.name = name;
+ this.address = address;
+ this.employerName = employerName;
+ this.salary = salary;
+ this.loanAmount = loanAmount;
+ this.loanDuration = loanDuration;
+ this.ssn = ssn;
+ this.email = email;
+ }//_________________________________________
+
+ public String toString() {
+ String ret = "-- WebCustomer details -- \n";
+ ret += "name: " + name;
+ ret += "address: " + address;
+ ret += "employerName: " + employerName;
+ ret += "salary: " + salary;
+ ret += "loanAmount: " + loanAmount;
+ ret += "loanDuration: " + loanDuration;
+ ret += "ssn: " + ssn;
+ ret += "email: " + email;
+ ret += "--------------------------";
+
+ return ret;
+ }
+
+}
More information about the jboss-svn-commits
mailing list