001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.jbi.servicemix.http;
022:
023: import java.io.IOException;
024:
025: import java.util.Enumeration;
026:
027: import javax.jbi.JBIException;
028: import javax.jbi.messaging.ExchangeStatus;
029: import javax.jbi.messaging.InOut;
030: import javax.jbi.messaging.NormalizedMessage;
031:
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import javax.xml.transform.TransformerException;
037:
038: /**
039: * <a href="HttpInOutBinding.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Charles May
042: *
043: */
044: public class HttpInOutBinding extends
045: org.apache.servicemix.components.http.HttpInOutBinding {
046:
047: public void processInOut(HttpServletRequest req,
048: HttpServletResponse res) throws IOException, JBIException,
049: ServletException {
050:
051: InOut exchange = getExchangeFactory().createInOutExchange();
052:
053: NormalizedMessage in = exchange.createMessage();
054:
055: try {
056: getMarshaler().toNMS(exchange, in, req);
057:
058: Enumeration enu = req.getParameterNames();
059:
060: while (enu.hasMoreElements()) {
061: try {
062: String name = (String) enu.nextElement();
063:
064: String value = req.getParameter(name);
065:
066: in.setProperty(name, value);
067: } catch (Exception e) {
068: }
069: }
070:
071: exchange.setInMessage(in);
072:
073: boolean result = getDeliveryChannel().sendSync(exchange);
074:
075: if (result) {
076: if (exchange.getStatus() == ExchangeStatus.ERROR) {
077: if (exchange.getError() != null) {
078: throw new ServletException(exchange.getError());
079: } else {
080: throw new ServletException(
081: "Exchange status is ERROR");
082: }
083: }
084:
085: getMarshaler().toResponse(exchange,
086: exchange.getOutMessage(), res);
087: }
088:
089: done(exchange);
090:
091: res.setStatus(HttpServletResponse.SC_OK);
092: } catch (IOException ioe) {
093: fail(exchange, ioe);
094: outputException(res, ioe);
095: } catch (TransformerException te) {
096: fail(exchange, te);
097: outputException(res, te);
098: }
099: }
100:
101: }
|