001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.soap.jaxws;
031:
032: import com.caucho.soap.reflect.WebServiceIntrospector;
033: import com.caucho.soap.skeleton.Skeleton;
034: import com.caucho.util.L10N;
035: import com.caucho.util.ThreadPool;
036: import com.caucho.xml.stream.StaxUtil;
037: import com.caucho.xml.stream.XMLStreamReaderImpl;
038: import com.caucho.xml.stream.XMLStreamWriterImpl;
039:
040: import javax.xml.bind.JAXBContext;
041: import javax.xml.namespace.QName;
042:
043: import static javax.xml.soap.SOAPConstants.*;
044:
045: import javax.xml.transform.OutputKeys;
046: import javax.xml.transform.Source;
047: import javax.xml.transform.Transformer;
048: import javax.xml.transform.TransformerConfigurationException;
049: import javax.xml.transform.TransformerException;
050: import javax.xml.transform.TransformerFactory;
051: import javax.xml.transform.dom.DOMResult;
052: import javax.xml.transform.dom.DOMSource;
053: import javax.xml.transform.stream.StreamResult;
054: import javax.xml.transform.stream.StreamSource;
055:
056: import javax.xml.ws.AsyncHandler;
057: import javax.xml.ws.Binding;
058: import javax.xml.ws.BindingProvider;
059: import javax.xml.ws.Dispatch;
060: import javax.xml.ws.Response;
061: import javax.xml.ws.Service;
062: import javax.xml.ws.WebServiceException;
063: import javax.xml.ws.handler.HandlerResolver;
064: import javax.xml.ws.spi.ServiceDelegate;
065:
066: import java.io.ByteArrayInputStream;
067: import java.io.ByteArrayOutputStream;
068: import java.io.CharArrayReader;
069: import java.io.CharArrayWriter;
070: import java.io.InputStream;
071: import java.io.IOException;
072: import java.io.OutputStream;
073: import java.io.OutputStreamWriter;
074:
075: import java.lang.reflect.Proxy;
076:
077: import java.net.MalformedURLException;
078: import java.net.URL;
079: import java.net.URLConnection;
080:
081: import java.util.Iterator;
082: import java.util.Map;
083: import java.util.concurrent.Executor;
084: import java.util.concurrent.Future;
085: import java.util.logging.Logger;
086:
087: import org.w3c.dom.Document;
088: import org.w3c.dom.Node;
089:
090: /**
091: * Dispatch
092: */
093: public class SourceDispatch extends AbstractDispatch<Source> {
094: private final static Logger log = Logger
095: .getLogger(SourceDispatch.class.getName());
096: private final static L10N L = new L10N(SourceDispatch.class);
097:
098: private final static TransformerFactory _transformerFactory = TransformerFactory
099: .newInstance();
100:
101: private final Transformer _transformer;
102:
103: public SourceDispatch(String bindingId, Binding binding,
104: Service.Mode mode, Executor executor)
105: throws WebServiceException {
106: super (bindingId, binding, mode, executor);
107:
108: try {
109: _transformer = _transformerFactory.newTransformer();
110:
111: if (mode == Service.Mode.PAYLOAD)
112: _transformer.setOutputProperty(
113: OutputKeys.OMIT_XML_DECLARATION, "yes");
114: } catch (TransformerConfigurationException e) {
115: throw new WebServiceException(e);
116: }
117: }
118:
119: protected void writeRequest(Source msg, OutputStream out)
120: throws WebServiceException {
121: try {
122: _transformer.transform(msg, new StreamResult(out));
123: } catch (TransformerException e) {
124: throw new WebServiceException(e);
125: }
126: }
127:
128: protected Source formatResponse(byte[] response) {
129: return new StreamSource(new ByteArrayInputStream(response));
130: }
131: }
|