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.skeleton;
031:
032: import com.caucho.jaxb.JAXBContextImpl;
033:
034: import com.caucho.soap.wsdl.MIMEContentType;
035: import com.caucho.soap.wsdl.MIMEMultipartRelated;
036: import com.caucho.soap.wsdl.MIMEPart;
037: import com.caucho.soap.wsdl.WSDLBindingOperationMessage;
038: import com.caucho.soap.wsdl.WSDLDefinitions;
039:
040: import com.caucho.util.L10N;
041:
042: import javax.jws.WebParam;
043:
044: import javax.xml.bind.JAXBException;
045: import javax.xml.bind.Marshaller;
046: import javax.xml.bind.Unmarshaller;
047: import javax.xml.stream.XMLStreamException;
048: import javax.xml.stream.XMLStreamReader;
049: import javax.xml.stream.XMLStreamWriter;
050: import javax.xml.ws.WebServiceException;
051: import java.lang.reflect.Method;
052: import java.io.IOException;
053: import java.util.Map;
054: import java.util.logging.Logger;
055:
056: /**
057: * Behaves like a DocumentWrappedAction most of the time, but also allows
058: * attachments.
059: */
060: public class RpcAction extends DocumentWrappedAction {
061: private final static Logger log = Logger.getLogger(RpcAction.class
062: .getName());
063: public static final L10N L = new L10N(RpcAction.class);
064:
065: public RpcAction(Method method, Method eiMethod,
066: JAXBContextImpl jaxbContext, String targetNamespace,
067: WSDLDefinitions wsdl, Marshaller marshaller,
068: Unmarshaller unmarshaller) throws JAXBException,
069: WebServiceException {
070: super (method, eiMethod, jaxbContext, targetNamespace, wsdl,
071: marshaller, unmarshaller);
072: }
073:
074: protected String attachmentContentType(WebParam webParam) {
075: if (_bindingOperation == null)
076: return null;
077:
078: WSDLBindingOperationMessage message = null;
079:
080: if (webParam.mode() == WebParam.Mode.IN
081: || webParam.mode() == WebParam.Mode.INOUT) {
082: String contentType = attachmentContentType(
083: _bindingOperation.getInput(), webParam.partName());
084:
085: if (contentType != null)
086: return contentType;
087: }
088:
089: if (webParam.mode() == WebParam.Mode.OUT
090: || webParam.mode() == WebParam.Mode.INOUT) {
091: String contentType = attachmentContentType(
092: _bindingOperation.getOutput(), webParam.partName());
093:
094: if (contentType != null)
095: return contentType;
096: }
097:
098: return null;
099: }
100:
101: private String attachmentContentType(
102: WSDLBindingOperationMessage message, String partName) {
103: for (Object o : _bindingOperation.getInput().getAny()) {
104: if (o instanceof MIMEMultipartRelated) {
105: MIMEMultipartRelated related = (MIMEMultipartRelated) o;
106:
107: for (MIMEPart part : related.getParts()) {
108:
109: for (Object subpart : part.getAny()) {
110: if (subpart instanceof MIMEContentType) {
111: MIMEContentType content = (MIMEContentType) subpart;
112:
113: if (partName.equals(content.getPart()))
114: return content.getType();
115: }
116: }
117:
118: }
119: }
120: }
121:
122: return null;
123: }
124: }
|