01: /*
02: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: *
23: * Free Software Foundation, Inc.
24: * 59 Temple Place, Suite 330
25: * Boston, MA 02111-1307 USA
26: *
27: * @author Emil Ong
28: */
29:
30: package com.caucho.soa.encoding;
31:
32: import com.caucho.config.ConfigurationException;
33: import com.caucho.util.L10N;
34:
35: import javax.annotation.PostConstruct;
36: import javax.xml.soap.MessageFactory;
37: import javax.xml.soap.MimeHeaders;
38: import static javax.xml.soap.SOAPConstants.*;
39: import javax.xml.soap.SOAPException;
40: import javax.xml.soap.SOAPMessage;
41: import javax.xml.ws.BindingType;
42: import javax.xml.ws.Service;
43: import javax.xml.ws.ServiceMode;
44: import javax.xml.ws.soap.SOAPBinding;
45: import java.io.IOException;
46: import java.io.InputStream;
47: import java.io.OutputStream;
48: import java.util.logging.Logger;
49:
50: /**
51: * Invokes a service Provider.
52: */
53: public class SOAPMessageProviderEncoding extends ProviderEncoding {
54: private static final L10N L = new L10N(ProviderEncoding.class);
55:
56: private final MessageFactory _factory;
57:
58: protected SOAPMessageProviderEncoding(Object service)
59: throws ConfigurationException {
60: super (service);
61:
62: if (_mode != Service.Mode.MESSAGE)
63: throw new ConfigurationException(
64: L
65: .l(
66: "{0} implements Provider<SOAPMessage> must have @ServiceMode annotation with value Service.Mode == MESSAGE",
67: _class.getName()));
68:
69: try {
70: BindingType bindingType = (BindingType) _class
71: .getAnnotation(BindingType.class);
72:
73: if (bindingType != null
74: && bindingType.value().equals(
75: SOAPBinding.SOAP12HTTP_BINDING))
76: _factory = MessageFactory
77: .newInstance(SOAP_1_2_PROTOCOL);
78: else
79: _factory = MessageFactory
80: .newInstance(SOAP_1_1_PROTOCOL);
81: } catch (SOAPException e) {
82: throw new ConfigurationException(e);
83: }
84: }
85:
86: public void invoke(InputStream is, OutputStream os)
87: throws Throwable {
88: SOAPMessage request = _factory.createMessage(new MimeHeaders(),
89: is);
90: SOAPMessage response = (SOAPMessage) _provider.invoke(request);
91:
92: response.writeTo(os);
93: os.flush();
94: }
95: }
|