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.namespace.QName;
047:
048: import static javax.xml.soap.SOAPConstants.*;
049: import javax.xml.soap.*;
050:
051: import javax.xml.ws.AsyncHandler;
052: import javax.xml.ws.Binding;
053: import javax.xml.ws.BindingProvider;
054: import javax.xml.ws.Dispatch;
055: import javax.xml.ws.Response;
056: import javax.xml.ws.Service;
057: import javax.xml.ws.WebServiceException;
058: import javax.xml.ws.handler.HandlerResolver;
059: import javax.xml.ws.soap.SOAPBinding;
060: import javax.xml.ws.spi.ServiceDelegate;
061:
062: import java.io.ByteArrayInputStream;
063: import java.io.ByteArrayOutputStream;
064: import java.io.InputStream;
065: import java.io.IOException;
066: import java.io.OutputStream;
067: import java.io.OutputStreamWriter;
068:
069: import java.lang.reflect.Proxy;
070:
071: import java.net.MalformedURLException;
072: import java.net.URL;
073: import java.net.URLConnection;
074:
075: import java.util.Iterator;
076: import java.util.Map;
077: import java.util.concurrent.Executor;
078: import java.util.concurrent.Future;
079: import java.util.logging.Logger;
080:
081: import org.w3c.dom.Document;
082: import org.w3c.dom.Node;
083:
084: /**
085: * Dispatch
086: */
087: public class SOAPMessageDispatch extends AbstractDispatch<SOAPMessage> {
088: private final static Logger log = Logger
089: .getLogger(SOAPMessageDispatch.class.getName());
090: private final static L10N L = new L10N(SOAPMessageDispatch.class);
091:
092: private final MessageFactory _factory;
093:
094: public SOAPMessageDispatch(String bindingId, Binding binding,
095: Service.Mode mode, Executor executor)
096: throws WebServiceException {
097: super (bindingId, binding, mode, executor);
098:
099: try {
100: if (SOAPBinding.SOAP11HTTP_BINDING.equals(bindingId)
101: || SOAPBinding.SOAP11HTTP_MTOM_BINDING
102: .equals(bindingId))
103: _factory = MessageFactory
104: .newInstance(SOAP_1_1_PROTOCOL);
105: else if (SOAPBinding.SOAP12HTTP_BINDING.equals(bindingId)
106: || SOAPBinding.SOAP12HTTP_MTOM_BINDING
107: .equals(bindingId))
108: _factory = MessageFactory
109: .newInstance(SOAP_1_2_PROTOCOL);
110: else
111: throw new WebServiceException(L.l(
112: "Unsupported binding id: {0}", bindingId));
113: } catch (SOAPException e) {
114: throw new WebServiceException(e);
115: }
116:
117: if (mode != Service.Mode.MESSAGE)
118: throw new WebServiceException(
119: L
120: .l("Instances of Dispatch<SOAPMessage> can only have mode MESSAGE"));
121: }
122:
123: protected void writeRequest(SOAPMessage msg, OutputStream out) {
124: try {
125: msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
126: msg.writeTo(out);
127: } catch (SOAPException e) {
128: throw new WebServiceException(e);
129: } catch (IOException e) {
130: throw new WebServiceException(e);
131: }
132: }
133:
134: protected SOAPMessage formatResponse(byte[] response) {
135: try {
136: InputStream is = new ByteArrayInputStream(response);
137: return _factory.createMessage(new MimeHeaders(), is);
138: } catch (SOAPException e) {
139: throw new WebServiceException(e);
140: } catch (IOException e) {
141: throw new WebServiceException(e);
142: }
143: }
144: }
|