TeldarRouteBuilder.java 26.6 KB
Newer Older
ED-DRIF committed
1 2 3

package com.fractalite.hermes.teldar.cfg;

ED-DRIF committed
4 5 6 7 8
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
ED-DRIF committed
9 10 11 12 13
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.xml.bind.JAXBContext;
ED-DRIF committed
14 15 16 17 18 19 20 21 22 23 24 25 26
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
ED-DRIF committed
27 28 29 30 31 32 33 34 35

import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.converter.jaxb.JaxbDataFormat;
import org.apache.camel.model.language.JXPathExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
ED-DRIF committed
36 37 38 39 40 41
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
ED-DRIF committed
42 43 44 45

import com.fractalite.hermes.services.stay.StayRouteBuilder;
import com.fractalite.hermes.teldar.Marshaller.MarshallingJAXB;
import com.fractalite.hermes.teldar.Marshaller.UnmarshallingJAXB;
ED-DRIF committed
46 47 48
import com.fractalite.hermes.teldar.parsers.ParseAddBookingTeldar;
import com.fractalite.hermes.teldar.parsers.ParseConfirmBookResponse;
import com.fractalite.hermes.teldar.parsers.ParseHoteldetailsResponse;
ED-DRIF committed
49
import com.fractalite.hermes.teldar.parsers.ParseTeldarHotelsPriceResponse;
ED-DRIF committed
50 51 52 53
import com.fractalite.hermes.teldar.services.ConfirmBookTeldarRequest;
import com.fractalite.hermes.teldar.services.GetHotelDetailsRequest;
import com.fractalite.hermes.teldar.services.HotelQuotesRequest;
import com.fractalite.hermes.teldar.services.PreBookingTeldarRequest;
ED-DRIF committed
54 55
import com.fractalite.hermes.teldar.services.SearchTeldarHotelPriceRequest;
import com.fractalite.models.commerce.QuoteTemplate;
ED-DRIF committed
56 57
import com.fractalite.models.commerce.RequestForQuote;
import com.fractalite.models.travel.stay.Hotel;
ED-DRIF committed
58 59
import com.fractalite.models.travel.stay.HotelStay;
import com.fractalite.models.travel.stay.StaySearchResults;
ED-DRIF committed
60 61 62 63 64 65 66 67 68 69 70
import com.gekko_holding.webservice.v2_4.CityBean;
import com.gekko_holding.webservice.v2_4.Facility;
import com.gekko_holding.webservice.v2_4.GeoLocalization;
import com.gekko_holding.webservice.v2_4.GetHotelDetailsResponse;
import com.gekko_holding.webservice.v2_4.HotelAvailability;
import com.gekko_holding.webservice.v2_4.HotelAvailabilityResponse;
import com.gekko_holding.webservice.v2_4.HotelBean;
import com.gekko_holding.webservice.v2_4.HotelBean.Facilities;
import com.gekko_holding.webservice.v2_4.HotelBean.Images;
import com.gekko_holding.webservice.v2_4.HotelChain;
import com.gekko_holding.webservice.v2_4.ImageUrl;
ED-DRIF committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

public class TeldarRouteBuilder extends RouteBuilder {
	public static final String EP_SEARCH = "teldar/hotel/search";
	public static final String EP_HOTEL_QUOTES = "teldar/hotel/quote";
	public static final String EP_HOTEL_ADDRESSE = "teldar/hotel/addresse";
	public static final String EP_HOTEL_INFO = "teldar/hotel/info";
	public static final String CHEK_AVAILABILITY = "teldar/hotel/chek";
	public static final String BOOK_HOTEL = "teldar/hotel/bookhotel";
	public static final String EP_HOTEL_QUOTE_CANCELLATION_POLICY = "teldar/hotel/hotelQuoteCancelleationFees";
	public static final String EP_CHARGE_CONDITIONS_BOOKING_LINE = "teldar/hotel/chargeConditionsBookingLine";
	public static final String EP_ORDER = "teldar/hotel/Order";
	public static final String EP_GET_ORDER = "teldar/hotel/getOrder";
	public static final String EP_BOOKING_CONFIRMATION = "teldar/hotel/bookingConfirmation";
	public static final String EP_CANCELLATION_FEES = "teldar/hotel/cancelleationFees";
	public static final String EP_CANCEL_ORDER = "teldar/hotel/cancelOrder";
	public static final String EP_MODIFY_ORDER = "teldar/hotel/modifyOrder";
	public static final String EP_MODIFY_ORDER_ITEM = "teldar/hotel/modifyOrderItem";
	public static final String EP_CANCEL_ORDER_ITEM = "teldar/hotel/cancelOrderItem";
	public static final String EP_SEARCH_ORDER = "teldar/hotel/searchOrder";
	public static final String EP_SEARCH_RESULT = "stay/searchResults";
ED-DRIF committed
91 92 93 94 95 96 97 98
	public static final String wsUrl = "http4://teldar.atlasvoyages.com/gekko-front/ws/v2_4/AvailabilityService";

//	public static final String wsUrl ="http4://teldar.atlasvoyages.com/gekko-front/ws/v2_4/AvailabilityService";
//	public static final String wsUrl ="https4://34.250.74.154:8082/search";
//	public static final String wsUrl = "https4://teldar.atlasvoyages.com/gekko-front/ws/v2_4/AvailabilityService";

//	public static final String wsUrl = "http4://api.infinitehotel.com/gekko-front/ws/v2_4/AvailabilityService";
//	public static final String wsUrl = "http4://api.infinitehotel.com/gekko-front/ws/v2_4/AvailabilityService";
ED-DRIF committed
99

ED-DRIF committed
100 101
//  public static final String wsUrl = "http4://hermes-scribe.fractalite.com/gekko-front/ws/v2_4/AvailabilityService";
//	public static final String WSURL_REF = "http4://hermes-scribe.fractalite.com/gekko-front/ws/v2_4/ReferentialService";
ED-DRIF committed
102 103 104 105 106 107 108

	public String status = "";
	// TEST

	// public static final String clientId ="atlasvoyages_test/xml";
	// public static final String password="RmsSj7tbKxUu";

ED-DRIF committed
109
	// PROD teldar
ED-DRIF committed
110 111 112

	public static final String clientId = "atlasvoyages/master/test";
	public static final String password = "p*TE*kH!e8$%dS";
ED-DRIF committed
113 114 115 116 117
	public static final String customerKey = "atlasvoyages/test";

	// PROD teldar
	// public static final String clientId = "atlasvoyages/xml";
	// public static final String password = "aPxsZ63NpyqPkEYs";
ED-DRIF committed
118 119 120 121 122 123 124 125 126

	org.apache.camel.spi.DataFormat jaxb = new org.apache.camel.converter.jaxb.JaxbDataFormat(
			"com.fractalite.hermes.teldar.api");

	private static final Logger logger = LoggerFactory.getLogger(TeldarRouteBuilder.class);

	private JaxbDataFormat hotelsDataFormat;

	private boolean test = false;
ED-DRIF committed
127 128
	// private static HashMap<String, HashMap<String, String>> hmap = new
	// HashMap<String, HashMap<String, String>>();
ED-DRIF committed
129 130

	/*
ED-DRIF committed
131 132
	 * public Object Convertion() throws JAXBException { JAXBContext jaxbContext
	 * =JAXBContext.newInstance(GetHotelDetailsResponse.class); Unmarshaller
ED-DRIF committed
133 134 135 136 137 138 139 140
	 * unmarshaller = jaxbContext.createUnmarshaller();
	 * 
	 * StringReader reader = new StringReader("xml string here");
	 * GetHotelDetailsResponse person = (GetHotelDetailsResponse)
	 * unmarshaller.unmarshal(reader); return person;
	 * 
	 * }
	 */
ED-DRIF committed
141

ED-DRIF committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
	// public static HashMap<String,String> BoardList = new
	// HashMap<String,String>();

	public TeldarRouteBuilder() {

		super();
	}

	/**
	 * Constructor specifying if the routeBuilder is ran as test on production,
	 * public endpoints are exposed through NMR component to enable inter bundle
	 * communication on test , public endpoints are exposed through Direct component
	 * (nmr testing is confusing)
	 *
	 * @param test true if test
	 */
	public TeldarRouteBuilder(boolean test) {

		super();
		this.test = test;
	}

ED-DRIF committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
	public static String soapMessageBodyContent(String message) throws Exception {
		// create message factory
		MessageFactory messageFactory = MessageFactory.newInstance();

		// converting string body to stream.
		InputStream responseInputStream = new ByteArrayInputStream(message.getBytes());

		// getting saop body stream to create soap message instance
		SOAPMessage soapMessage = messageFactory.createMessage(null, responseInputStream);

		// get the body
		SOAPBody soapBody = soapMessage.getSOAPBody();

		return convertToString(soapBody);
	}
	
ED-DRIF committed
180 181

	/**
ED-DRIF committed
182
	 * Notes on search and quote routes : Since teldar does not handle multi room
ED-DRIF committed
183 184 185 186 187
	 * type reservation, split/aggregate is used to make results per each room type
	 */
	@Override
	public void configure() throws Exception {
		String nmrOrDirect = (test) ? "direct:" : "nmr:";
ED-DRIF committed
188
	
ED-DRIF committed
189 190 191 192 193 194 195 196 197 198 199
		// XML Data Format
		JaxbDataFormat availabilityReqDF = new JaxbDataFormat();
		JAXBContext context = JAXBContext.newInstance(HotelAvailability.class);
		availabilityReqDF.setContext(context);

		JaxbDataFormat details = new JaxbDataFormat();
		JAXBContext contexts = JAXBContext.newInstance(GetHotelDetailsResponse.class);
		details.setContext(contexts);

		/*************** SearchHotelsPriceRequest ******************/

ED-DRIF committed
200
		JAXBContext hotelsContext = JAXBContext.newInstance(HotelAvailabilityResponse.class);
ED-DRIF committed
201 202 203 204 205
		hotelsDataFormat = new JaxbDataFormat();
		hotelsDataFormat.setContext(hotelsContext);
		hotelsDataFormat.setEncoding("UTF-8");

		from(nmrOrDirect + EP_SEARCH).routeId(EP_SEARCH).setExchangePattern(ExchangePattern.InOut)
ED-DRIF committed
206
				.log("Contacting search webservice !!!!!  ${body}").choice()
ED-DRIF committed
207
				// stop if morocco
ED-DRIF committed
208 209
				.when(new JXPathExpression("in/body/trip/content[1]/hotel/address/country/code = 'ma'")).otherwise()

ED-DRIF committed
210 211 212 213
				.process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
ED-DRIF committed
214 215 216 217 218 219 220
						QuoteTemplate q = exchange.getIn().getMandatoryBody(QuoteTemplate.class);
						HotelStay hotelstay = q.getTrip().getContent(HotelStay.class).get(0);
						if (hotelstay.getGiatacode() == null || hotelstay.getGiatacode().getGekko_infinite() == null
								|| hotelstay.getGiatacode().getGekko_infinite().size() == 0)
							exchange.getIn().setHeader("teldaremtygiata", true);
						else
							exchange.getIn().setHeader("teldaremtygiata", false);
ED-DRIF committed
221
					}
ED-DRIF committed
222
				}).choice()
ED-DRIF committed
223
				// stop if code empty
ED-DRIF committed
224 225
				.when(header("teldaremtygiata").isEqualTo(true)).log("teldar Giata code is null")
				.removeHeader("teldaremtygiata").process(new Processor() {
ED-DRIF committed
226 227 228 229 230 231 232 233 234

					@Override
					public void process(Exchange exchange) throws Exception {
						StaySearchResults result = new StaySearchResults();
						result.setQuery(exchange.getIn().getBody(QuoteTemplate.class));
						exchange.getIn().setBody(result);
					}
				}).to(nmrOrDirect + StayRouteBuilder.EP_SEARCH_RESULT).stop()

ED-DRIF committed
235
				.otherwise().log("teldar Giata code is NOT null")
ED-DRIF committed
236 237 238 239 240 241 242 243
				.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
				.setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
				.setHeader(Exchange.SOAP_ACTION, constant("")).process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {

						for (String h : exchange.getIn().getHeaders().keySet())
ED-DRIF committed
244 245
							logger.info("\n header before serach " + h + " : " + exchange.getIn().getHeader(h));
						exchange.setProperty("linkheader", exchange.getIn().getHeader("Link"));
ED-DRIF committed
246 247 248
						exchange.setProperty("hermessearchcompletionsize",
								exchange.getIn().getHeader("hermessearchcompletionsize"));
					}
ED-DRIF committed
249 250
				}).process(new SearchTeldarHotelPriceRequest()).bean(MarshallingJAXB.class, "marshallObject")
				.log("\n Request body content : \n ${body}").log("urlllll" + wsUrl)
ED-DRIF committed
251 252

				.to(wsUrl)// + "?throwExceptionOnFailure=false")
ED-DRIF committed
253
				.convertBodyTo(String.class, "ISO-8859-1").log("\n teldar response body --------------- : \n ${body}")
ED-DRIF committed
254 255 256 257 258 259 260 261
				.process(new Processor() {
					@Override
					public void process(Exchange exchange) throws Exception {
						exchange.getIn().setHeaders(new HashMap<String, Object>());
						exchange.getIn().setHeader("Link", exchange.getProperty("linkheader"));

						exchange.getIn().setHeader("hermessearchcompletionsize",
								exchange.getProperty("hermessearchcompletionsize"));
ED-DRIF committed
262 263 264 265 266

						soapMessageBodyContent(exchange.getIn().getBody(String.class));

						logger.info("unmarshledSoap" + soapMessageBodyContent(exchange.getIn().getBody(String.class)));

ED-DRIF committed
267 268 269
					}
				})

ED-DRIF committed
270
				/* Unmarshalling teldar response */
ED-DRIF committed
271
				.bean(UnmarshallingJAXB.class, "fromHotelAvailabilityResponse(${body})")
ED-DRIF committed
272
				// .bean(UnmarshallingJAXB.class)
ED-DRIF committed
273

ED-DRIF committed
274
				/* Converting teldar response. */
ED-DRIF committed
275

ED-DRIF committed
276
				.log("responsemarshllerrr --------------- : \n ${body}").process(new ParseTeldarHotelsPriceResponse())
ED-DRIF committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
				.end().to(nmrOrDirect + EP_SEARCH_RESULT);

		/***************** CityHotelRequest *******************/

		/*
		 * from(nmrOrDirect +
		 * EP_HOTEL_ADDRESSE).routeId(EP_HOTEL_ADDRESSE).setExchangePattern(
		 * ExchangePattern.InOut) .removeHeaders("*") .setHeader(Exchange.HTTP_METHOD,
		 * constant(org.apache.camel.component.http4.HttpMethods.POST))
		 * .setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
		 * .setHeader(Exchange.SOAP_ACTION, constant(""))
		 * .log("ConvertCcities : \n ${body}") .process(new
		 * CityHotelRequest()).log("ConvertCities : \n ${body}")
		 * .bean(MarshallingJAXB.class,
		 * "marshallObject").log("Marshalled body for cities : ${body}")
		 * 
		 * .to(WSURL_REF).convertBodyTo(String.class)
		 * 
		 * .log("Citie Response : \n " + body())
		 * 
		 * .bean(UnmarshallingJAXB.class, "fromGetCitiesResponse(${body})").process(new
		 * Processor() {
		 * 
		 * @Override public void process(Exchange exchange) throws Exception {
		 * exchange.getIn().setHeaders(new HashMap<String, Object>());
		 * 
		 * logger.info("contcity" + getCities(list1)); } })
		 * 
		 * .process(new ParserCityHotelResonse());
		 * 
		 * 
		 * 
		 */

		/***************** HotelQuotesRequest *******************/

ED-DRIF committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
		from(nmrOrDirect + EP_HOTEL_QUOTES).routeId(EP_HOTEL_QUOTES).setExchangePattern(ExchangePattern.InOut)
				
				
				.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
				.setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
				.setHeader(Exchange.SOAP_ACTION, constant(""))

				.process(new HotelQuotesRequest()).process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
						for (String h : exchange.getIn().getHeaders().keySet())
							logger.info("header before quote " + h + " :  " + exchange.getIn().getHeader(h));

					}
				})

				.bean(MarshallingJAXB.class, "marshallObject")
				// .log("Marshalled body for quotes : ${body}")
				.to(wsUrl)// + "?throwExceptionOnFailure=false")

				.convertBodyTo(String.class)

				.process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
						exchange.getIn().setHeaders(new HashMap<String, Object>());
						logger.info("UnmashalledQuoteeeee response body : ---------- \n "
								+ soapMessageBodyContent(exchange.getIn().getBody(String.class)));
					}
				})


				.bean(UnmarshallingJAXB.class, "fromHotelAvailabilityResponse(${body})")

				.log("ResponseMarshllerQuote --------------- : \n ${body}")

				.process(new com.fractalite.hermes.teldar.parsers.ParserQuotesresponse());
				
ED-DRIF committed
353 354 355

		/***************** HotelDetailsInfo *******************/

ED-DRIF committed
356 357
		from(nmrOrDirect + EP_HOTEL_INFO).routeId(EP_HOTEL_INFO).setExchangePattern(ExchangePattern.InOut)
			
ED-DRIF committed
358
		
ED-DRIF committed
359 360 361 362
	
				.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
				.setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
				.setHeader(Exchange.SOAP_ACTION, constant("")).process(new GetHotelDetailsRequest())
ED-DRIF committed
363

ED-DRIF committed
364
				.log("bodyDetailss : \n ${body}").bean(MarshallingJAXB.class, "marshallObject")
ED-DRIF committed
365

ED-DRIF committed
366
				.to(wsUrl + "?throwExceptionOnFailure=false")
ED-DRIF committed
367

ED-DRIF committed
368
				.convertBodyTo(String.class, "ISO-8859-1").log("ResponseDetails --------------- : \n ${body}")
ED-DRIF committed
369

ED-DRIF committed
370
				.process(new Processor() {
ED-DRIF committed
371

ED-DRIF committed
372 373 374
					@Override
					public void process(Exchange exchange) throws Exception {
						exchange.getIn().setHeaders(new HashMap<String, Object>());
ED-DRIF committed
375

ED-DRIF committed
376 377
						logger.info("ConvertionNodeDteails"
								+ ConvertionNode(soapMessageBodyContent(exchange.getIn().getBody(String.class))));
ED-DRIF committed
378

ED-DRIF committed
379 380
						exchange.getOut().setBody(
								ConvertionNode(soapMessageBodyContent(exchange.getIn().getBody(String.class))));
ED-DRIF committed
381

ED-DRIF committed
382 383
					}
				})
ED-DRIF committed
384

ED-DRIF committed
385 386 387 388
				// .bean(UnmarshallingJAXB.class, "fromGetDetailsResponse(${body})")
				// .bean(UnmarshallingJAXB.class)
				.removeHeader("camel*")
				.process(new ParseHoteldetailsResponse());
ED-DRIF committed
389 390 391



ED-DRIF committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
		/***************** PreBookingHotelRequest *******************/

		from(nmrOrDirect + EP_ORDER)
		.log("EP--PREORDER  ${body}")
	      //  from("timer://orderTimer?delay=6000&repeatCount=1")
				.routeId(EP_ORDER).setExchangePattern(ExchangePattern.InOut)
				.log("PreOrder webservice !!!!!  ${body}")
				.removeHeaders("*")
				.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
				.setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
				.setHeader(Exchange.SOAP_ACTION, constant(""))

			     .log("headerss")
				.process(new PreBookingTeldarRequest())
				.bean(MarshallingJAXB.class, "marshallObject")
				.log("PreBookTeldar body --------------- : \n ${body}")

				.to(wsUrl)

				.convertBodyTo(String.class)
				.log("ResponsePreOrderBOok --------------- : \n ${body}")
				.process(new Processor() {
ED-DRIF committed
414 415 416

					@Override
					public void process(Exchange exchange) throws Exception {
ED-DRIF committed
417 418 419 420 421
						exchange.getIn().setHeaders(new HashMap<String, Object>());
						soapMessageBodyContent(exchange.getIn().getBody(String.class));

						logger.info("unmarshledSoapPreBOOK" + soapMessageBodyContent(exchange.getIn().getBody(String.class)));

ED-DRIF committed
422
					}
ED-DRIF committed
423 424 425 426 427 428 429 430 431 432
				})
     			.bean(UnmarshallingJAXB.class, "fromPreBookingInfoResponse1(${body})")
				.log("ResponseMarshllerPreOder --------------- : \n ${body}")
				.process(new ParseAddBookingTeldar())
				.log("ResponseParserBook ---------- : \n ${body}");
				
		
		
///////////////////EP_BOOKING_CONFIRMATION////////////////////////////
		
ED-DRIF committed
433

ED-DRIF committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
		from(nmrOrDirect + EP_BOOKING_CONFIRMATION)
		.log("EP----CONFIRMATION ${body}")
				// from("timer://orderTimer?delay=6000&repeatCount=1")
				.routeId(EP_BOOKING_CONFIRMATION)
				.setExchangePattern(ExchangePattern.InOut)
				.log("ConfirmOrder webservice !!!!!  ${body}")
				.removeHeaders("*")
				.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
				.setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
				.setHeader(Exchange.SOAP_ACTION, constant(""))
				.process(new ConfirmBookTeldarRequest())
				.bean(MarshallingJAXB.class, "marshallObject")
				.log("ConfirmBookTeldarRequest Body --------------- : \n ${body}")
				.to(wsUrl)
				.convertBodyTo(String.class)
				.log("ConfirmBookTeldarRequest Response body --------------- : \n ${body}")
ED-DRIF committed
450

ED-DRIF committed
451 452 453 454 455
				.bean(UnmarshallingJAXB.class, "fromBookHotelResponse(${body})")
				.process(new ParseConfirmBookResponse());
		
		
		/***************** HotelChargeConditionsBookingRequest *******************/
ED-DRIF committed
456

ED-DRIF committed
457 458 459 460 461 462 463
		from(nmrOrDirect + EP_CANCELLATION_FEES).routeId(EP_CANCELLATION_FEES)
				.setExchangePattern(ExchangePattern.InOut);

		/***************** HotelQuotesCancellationPolicyRequest *******************/

		from(nmrOrDirect + EP_HOTEL_QUOTE_CANCELLATION_POLICY).routeId(EP_HOTEL_QUOTE_CANCELLATION_POLICY)
				.setExchangePattern(ExchangePattern.InOut);
ED-DRIF committed
464 465 466

		/***************** CancelBookingRequest *******************/

ED-DRIF committed
467
		from(nmrOrDirect + EP_CANCEL_ORDER).routeId(EP_CANCEL_ORDER).setExchangePattern(ExchangePattern.InOut);
ED-DRIF committed
468 469 470

	}

ED-DRIF committed
471
	private static GetHotelDetailsResponse ConvertionNode(String hoteldetail)
ED-DRIF committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
			throws ParserConfigurationException, SAXException, IOException, JAXBException, TransformerException {
		Logger logg = LoggerFactory.getLogger(TeldarRouteBuilder.class);
		// Document document = stringToXml(hoteldetail);
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder;
		builder = factory.newDocumentBuilder();
		Document document = builder.parse(new InputSource(new StringReader(hoteldetail)));
		Element rootElement = document.getDocumentElement();

		GetHotelDetailsResponse resp = new GetHotelDetailsResponse();

		NodeList nLhotelName = rootElement.getElementsByTagName("hotelName");

		Element elmnhotelName = (Element) nLhotelName.item(0);

ED-DRIF committed
487 488 489 490 491 492
		String hotelCode = "";
		NodeList nLhotelCodee = rootElement.getElementsByTagName("hotelCode");
		Element elmnhotelCodee = (Element) nLhotelCodee.item(0);
		if (elmnhotelCodee != null && elmnhotelCodee.getTextContent() != null) {
			hotelCode = elmnhotelCodee.getTextContent();
		}
ED-DRIF committed
493

ED-DRIF committed
494 495 496 497 498 499 500 501 502 503 504
		String hotelRating = "";
		NodeList nLhotelRating = rootElement.getElementsByTagName("hotelRating");
		Element elmnhotelRating = (Element) nLhotelRating.item(0);
		if (elmnhotelRating != null && elmnhotelRating.getTextContent() != null) {
			hotelRating = elmnhotelRating.getTextContent();
		}
		/*
		 * Node nLhotelRating = rootElement.getAttributeNode("hotelRating");
		 * 
		 * String hotelRating = nLhotelRating.getNodeValue();
		 */
ED-DRIF committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
		HotelChain htlChaine = new HotelChain();
		NodeList nLhotelChain = rootElement.getElementsByTagName("hotelChain");

		Element elmnhotelChain = (Element) nLhotelChain.item(0);
		if (elmnhotelChain != null && elmnhotelChain.getTextContent() != null) {
			String hotelChain = elmnhotelChain.getTextContent();
			htlChaine.setValue(hotelChain);
		}

		CityBean cityB = new CityBean();
		NodeList nLcity = rootElement.getElementsByTagName("city");

		Element elmncity = (Element) nLcity.item(0);
		Node nLCode = elmncity.getAttributeNode("code");

		String codeCity = nLCode.getNodeValue();
		cityB.setCode(codeCity);

		GeoLocalization geo = new GeoLocalization();
		NodeList nLgeoLocalization = rootElement.getElementsByTagName("geoLocalization");

		Element elmngeoLocalization = (Element) nLgeoLocalization.item(0);
		Node nLlatitude = elmngeoLocalization.getAttributeNode("latitude");
		double latitude = Double.valueOf(nLlatitude.getNodeValue().toString());
		Node nLlongitude = elmngeoLocalization.getAttributeNode("longitude");
		double longitude = Double.valueOf(nLlongitude.getNodeValue());
		geo.setLatitude(latitude);
		geo.setLongitude(longitude);

		NodeList nLaddress = rootElement.getElementsByTagName("address");

		Element elmnaddress = (Element) nLaddress.item(0);

		NodeList nLphone = rootElement.getElementsByTagName("phone");

		Element elmnphone = (Element) nLphone.item(0);

		NodeList nLfax = rootElement.getElementsByTagName("fax");

		Element elmnfax = (Element) nLfax.item(0);

		NodeList nLemail = rootElement.getElementsByTagName("email");

		Element elmnemail = (Element) nLemail.item(0);

		NodeList nLshortDescription = rootElement.getElementsByTagName("shortDescription");

		Element elmnshortDescription = (Element) nLshortDescription.item(0);

		NodeList nLthumbnailUrl = rootElement.getElementsByTagName("thumbnailUrl");

		Element elmnthumbnailUrl = (Element) nLthumbnailUrl.item(0);

		NodeList nLfacilities = rootElement.getElementsByTagName("facilities");
		Facilities fclt = new Facilities();
		for (int i = 0; i < nLfacilities.getLength(); i++) {
			Facility fac = new Facility();

			Element elmnfacilities = (Element) nLfacilities.item(i);
			NodeList nLfacility = elmnfacilities.getElementsByTagName("facility");
			Element elmnfacility = (Element) nLfacility.item(0);

			Node nLCodeFacilities = elmnfacility.getAttributeNode("code");

			for (int j = 0; j < nLfacility.getLength(); j++) {
				Element elmnFac = (Element) nLfacility.item(j);
				// String typeImage = elmnImage.getNodeValue();
				Node cd = elmnFac.getAttributeNode("code");

				String faci = cd.getNodeValue();
				String facivalue = elmnFac.getTextContent();

				Facility fct = new Facility();
				fct.setCode(faci);
				fct.setValue(facivalue);
				fclt.getFacility().add(fct);
			}
			String codeFacility = nLCodeFacilities.getNodeValue();

			fac.setCode(codeFacility);
			fclt.getFacility().add(fac);

		}

		NodeList nLimages = rootElement.getElementsByTagName("images");
		Images imges = new Images();
		List<ImageUrl> igs = new ArrayList<ImageUrl>();
		List<String> str = new ArrayList<String>();

		for (int i = 0; i < nLimages.getLength(); i++) {
			ImageUrl ig = new ImageUrl();
			Element elmnImages = (Element) nLimages.item(i);
			NodeList nLImage = elmnImages.getElementsByTagName("image");
			Element elmnfacility = (Element) nLImage.item(0);
			Node nLTypeImages = elmnfacility.getAttributeNode("type");

			for (int j = 0; j < nLImage.getLength(); j++) {
				Element elmnImage = (Element) nLImage.item(j);
				// String typeImage = elmnImage.getNodeValue();

				String urlImage = elmnImage.getTextContent();

				// ig.setType(typeImage);
				ig.setValue(urlImage);
				str.add(ig.getValue());
				// imges.getImage().add(j, ig);
				igs.add(ig);

				// logg.info("igggg63" + imges.getImage().get(j).getValue());

			}

		}

		for (int j = 0; j < str.size(); j++) {
			ImageUrl igt = new ImageUrl();
			igt.setValue(str.get(j));
			imges.getImage().add(igt);
		}

		// String strObject = result.getWriter().toString() ;
		String hotelName = elmnhotelName.getTextContent();
		String city = elmncity.getTextContent();
		String geoLocalization = elmngeoLocalization.getTextContent();
		String address = elmnaddress.getTextContent();
		String phone = elmnphone.getTextContent();
		String fax = "";
		String email = "";
		String shortDescription = "";
		String thumbnailUrl = "";

		if (elmnfax != null && elmnfax.getTextContent() != null)
			fax = elmnfax.getTextContent();

		if (elmnemail != null && elmnemail.getTextContent() != null)
			email = elmnemail.getTextContent();

		if (elmnshortDescription != null && elmnshortDescription.getTextContent() != null)
			shortDescription = elmnshortDescription.getTextContent();

		if (elmnthumbnailUrl != null && elmnthumbnailUrl.getTextContent() != null)
			thumbnailUrl = elmnthumbnailUrl.getTextContent();

		HotelBean htlB = new HotelBean();
		htlB.setHotelName(hotelName);
		htlB.setHotelCode(hotelCode);
		htlB.setHotelRating(hotelRating); //
		htlB.setHotelChain(htlChaine);
		htlB.setAddress(address);
		htlB.setFax(fax);

		htlB.setPhone(phone);
		htlB.setEmail(email);
		htlB.setGeoLocalization(geo);
		htlB.setFacilities(fclt);
		htlB.setImages(imges);
		htlB.setShortDescription(shortDescription);
		htlB.setThumbnailUrl(thumbnailUrl);
		htlB.setCity(cityB);

		resp.getHotel().add(htlB);

		return resp;
	}

	public static Document stringToXml(String line) throws ParserConfigurationException, SAXException, IOException {
		Logger logg = LoggerFactory.getLogger(TeldarRouteBuilder.class);

		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse(new InputSource(new StringReader(line)));

		return document;
	}

ED-DRIF committed
680
//hotelreponse
ED-DRIF committed
681
	private static String convertToString(SOAPBody message) throws Exception {
ED-DRIF committed
682

ED-DRIF committed
683 684 685 686 687 688 689 690 691 692 693 694 695
		Document doc = message.extractContentAsDocument();
		Element rootElement = doc.getDocumentElement();
		NodeList nList11 = rootElement.getElementsByTagName("hotel");
		Node m = nList11.item(0);
		Element s = (Element) m;

		StringWriter sw = new StringWriter();
		TransformerFactory tf = TransformerFactory.newInstance();
		Transformer transformer = tf.newTransformer();
		transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		transformer.setOutputProperty(OutputKeys.METHOD, "xml");
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
ED-DRIF committed
696
		transformer.transform(new DOMSource(rootElement), new StreamResult(sw));
ED-DRIF committed
697 698
		return sw.toString();

ED-DRIF committed
699
	}
ED-DRIF committed
700

ED-DRIF committed
701
}