001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.server.provider;
037:
038: import com.sun.xml.ws.api.SOAPVersion;
039: import com.sun.xml.ws.api.WSBinding;
040: import com.sun.xml.ws.api.message.Message;
041: import com.sun.xml.ws.api.message.Messages;
042: import com.sun.xml.ws.api.message.Packet;
043: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
044: import com.sun.xml.ws.encoding.xml.XMLMessage;
045: import com.sun.xml.ws.resources.ServerMessages;
046:
047: import javax.activation.DataSource;
048: import javax.xml.transform.Source;
049: import javax.xml.ws.Service;
050: import javax.xml.ws.WebServiceException;
051: import javax.xml.ws.handler.MessageContext;
052: import javax.xml.ws.http.HTTPException;
053:
054: /**
055: * @author Jitendra Kotamraju
056: */
057: abstract class XMLProviderArgumentBuilder<T> extends
058: ProviderArgumentsBuilder<T> {
059:
060: @Override
061: protected Packet getResponse(Packet request, Exception e,
062: WSDLPort port, WSBinding binding) {
063: Packet response = super .getResponse(request, e, port, binding);
064: if (e instanceof HTTPException) {
065: if (response.supports(MessageContext.HTTP_RESPONSE_CODE)) {
066: response.put(MessageContext.HTTP_RESPONSE_CODE,
067: ((HTTPException) e).getStatusCode());
068: }
069: }
070: return response;
071: }
072:
073: static XMLProviderArgumentBuilder createBuilder(
074: ProviderEndpointModel model, WSBinding binding) {
075: if (model.mode == Service.Mode.PAYLOAD) {
076: return new PayloadSource();
077: } else {
078: if (model.datatype == Source.class)
079: return new PayloadSource();
080: if (model.datatype == DataSource.class)
081: return new DataSourceParameter(binding);
082: throw new WebServiceException(ServerMessages
083: .PROVIDER_INVALID_PARAMETER_TYPE(model.implClass,
084: model.datatype));
085: }
086: }
087:
088: private static final class PayloadSource extends
089: XMLProviderArgumentBuilder<Source> {
090: public Source getParameter(Packet packet) {
091: return packet.getMessage().readPayloadAsSource();
092: }
093:
094: public Message getResponseMessage(Source source) {
095: return Messages.createUsingPayload(source,
096: SOAPVersion.SOAP_11);
097: }
098:
099: protected Message getResponseMessage(Exception e) {
100: return XMLMessage.create(e);
101: }
102: }
103:
104: private static final class DataSourceParameter extends
105: XMLProviderArgumentBuilder<DataSource> {
106: private final WSBinding binding;
107:
108: DataSourceParameter(WSBinding binding) {
109: this .binding = binding;
110: }
111:
112: public DataSource getParameter(Packet packet) {
113: Message msg = packet.getMessage();
114: return (msg instanceof XMLMessage.MessageDataSource) ? ((XMLMessage.MessageDataSource) msg)
115: .getDataSource()
116: : XMLMessage.getDataSource(msg, binding);
117: }
118:
119: public Message getResponseMessage(DataSource ds) {
120: return XMLMessage.create(ds, binding);
121: }
122:
123: protected Message getResponseMessage(Exception e) {
124: return XMLMessage.create(e);
125: }
126: }
127:
128: }
|