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.soa.encoding;
031:
032: import com.caucho.soap.reflect.WebServiceIntrospector;
033: import com.caucho.soap.skeleton.DirectSkeleton;
034:
035: import javax.annotation.PostConstruct;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038: import javax.xml.bind.JAXBException;
039: import javax.xml.stream.XMLInputFactory;
040: import javax.xml.stream.XMLOutputFactory;
041: import javax.xml.stream.XMLStreamException;
042: import javax.xml.stream.XMLStreamReader;
043: import javax.xml.stream.XMLStreamWriter;
044: import java.io.IOException;
045: import java.io.InputStream;
046: import java.io.OutputStream;
047: import java.util.logging.Logger;
048:
049: /**
050: * Invokes a service based on a Hessian-encoded request.
051: */
052: public class SoapEncoding implements ServiceEncoding {
053: private static final Logger log = Logger
054: .getLogger(SoapEncoding.class.getName());
055:
056: protected final XMLOutputFactory _xmlOutputFactory = XMLOutputFactory
057: .newInstance();
058: protected final XMLInputFactory _xmlInputFactory = XMLInputFactory
059: .newInstance();
060:
061: private Object _object;
062: private Class _class;
063: private DirectSkeleton _skeleton;
064: private String _wsdlLocation;
065:
066: public void setService(Object service) {
067: _object = service;
068:
069: if (_class == null)
070: _class = service.getClass();
071: }
072:
073: public void setSeparateSchema(boolean separateSchema)
074: throws JAXBException, IOException {
075: getSkeleton().setSeparateSchema(separateSchema);
076: }
077:
078: public void setInterface(Class cl) {
079: _class = cl;
080: }
081:
082: @PostConstruct
083: public void init() {
084: _xmlOutputFactory.setProperty(
085: XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
086: }
087:
088: public void invoke(InputStream is, OutputStream os)
089: throws Throwable {
090: }
091:
092: public void invoke(HttpServletRequest request,
093: HttpServletResponse response) throws Throwable {
094: getSkeleton().invoke(_object, request, response);
095: }
096:
097: public void dumpWSDL(OutputStream out) throws IOException,
098: XMLStreamException, JAXBException {
099: getSkeleton().dumpWSDL(out);
100: }
101:
102: private DirectSkeleton getSkeleton() throws JAXBException,
103: IOException {
104: if (_skeleton == null) {
105: _skeleton = WebServiceIntrospector.introspect(_class,
106: _wsdlLocation, null);
107: }
108:
109: return _skeleton;
110: }
111: }
|