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.activation.DataHandler;
041: import javax.activation.DataSource;
042:
043: import javax.mail.util.ByteArrayDataSource;
044:
045: import javax.xml.bind.JAXBContext;
046: import javax.xml.bind.JAXBException;
047: import javax.xml.bind.Marshaller;
048: import javax.xml.bind.Unmarshaller;
049: import javax.xml.namespace.QName;
050:
051: import static javax.xml.soap.SOAPConstants.*;
052:
053: import javax.xml.ws.AsyncHandler;
054: import javax.xml.ws.Binding;
055: import javax.xml.ws.BindingProvider;
056: import javax.xml.ws.Dispatch;
057: import javax.xml.ws.Response;
058: import javax.xml.ws.Service;
059: import javax.xml.ws.WebServiceException;
060: import javax.xml.ws.handler.HandlerResolver;
061: import javax.xml.ws.spi.ServiceDelegate;
062:
063: import java.io.ByteArrayInputStream;
064: import java.io.ByteArrayOutputStream;
065: import java.io.InputStream;
066: import java.io.IOException;
067: import java.io.OutputStream;
068: import java.io.OutputStreamWriter;
069:
070: import java.lang.reflect.Proxy;
071:
072: import java.net.MalformedURLException;
073: import java.net.URL;
074: import java.net.URLConnection;
075:
076: import java.util.Iterator;
077: import java.util.Map;
078: import java.util.concurrent.Executor;
079: import java.util.concurrent.Future;
080: import java.util.logging.Logger;
081:
082: import org.w3c.dom.Document;
083: import org.w3c.dom.Node;
084:
085: /**
086: * Dispatch
087: */
088: public class JAXBDispatch extends AbstractDispatch<Object> {
089: private final static Logger log = Logger
090: .getLogger(JAXBDispatch.class.getName());
091: private final static L10N L = new L10N(JAXBDispatch.class);
092:
093: private final JAXBContext _context;
094: private final Marshaller _marshaller;
095: private final Unmarshaller _unmarshaller;
096:
097: public JAXBDispatch(String bindingId, Binding binding,
098: Service.Mode mode, Executor executor, JAXBContext context)
099: throws WebServiceException {
100: super (bindingId, binding, mode, executor);
101:
102: _context = context;
103:
104: try {
105: _marshaller = _context.createMarshaller();
106:
107: if (mode == Service.Mode.PAYLOAD)
108: _marshaller.setProperty(Marshaller.JAXB_FRAGMENT,
109: Boolean.TRUE);
110:
111: _unmarshaller = _context.createUnmarshaller();
112: } catch (JAXBException e) {
113: throw new WebServiceException(e);
114: }
115: }
116:
117: protected void writeRequest(Object msg, OutputStream out)
118: throws WebServiceException {
119: try {
120: _marshaller.marshal(msg, out);
121: } catch (JAXBException e) {
122: throw new WebServiceException(e);
123: }
124: }
125:
126: protected Object formatResponse(byte[] response)
127: throws WebServiceException {
128: try {
129: return _unmarshaller.unmarshal(new ByteArrayInputStream(
130: response));
131: } catch (JAXBException e) {
132: throw new WebServiceException(e);
133: }
134: }
135: }
|