3069N/A/*
3069N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3069N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3069N/A *
3069N/A * This code is free software; you can redistribute it and/or modify it
3069N/A * under the terms of the GNU General Public License version 2 only, as
3069N/A * published by the Free Software Foundation. Oracle designates this
3069N/A * particular file as subject to the "Classpath" exception as provided
3069N/A * by Oracle in the LICENSE file that accompanied this code.
3069N/A *
3069N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3069N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3069N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3069N/A * version 2 for more details (a copy is included in the LICENSE file that
3069N/A * accompanied this code).
3069N/A *
3069N/A * You should have received a copy of the GNU General Public License version
3069N/A * 2 along with this work; if not, write to the Free Software Foundation,
3069N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3069N/A *
3069N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3069N/A * or visit www.oracle.com if you need additional information or have any
3069N/A * questions.
3069N/A */
3069N/A
3069N/Apackage com.sun.xml.internal.messaging.saaj.soap;
3069N/A
3069N/Aimport java.io.*;
3069N/Aimport java.util.logging.Logger;
3069N/A
3069N/Aimport javax.xml.soap.*;
3069N/A
3069N/Aimport com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
3069N/Aimport com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ParseException;
3069N/Aimport com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
3069N/Aimport com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl;
3069N/Aimport com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl;
3069N/Aimport com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
3069N/Aimport com.sun.xml.internal.messaging.saaj.util.TeeInputStream;
3069N/A
3069N/A/**
3069N/A * A factory for creating SOAP messages.
3069N/A *
3069N/A * Converted to a placeholder for common functionality between SOAP
3069N/A * implementations.
3069N/A *
3069N/A * @author Phil Goodwin (phil.goodwin@sun.com)
3069N/A */
3069N/Apublic class MessageFactoryImpl extends MessageFactory {
3069N/A
3069N/A protected static final Logger log =
3069N/A Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
3069N/A "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
3069N/A
3069N/A protected OutputStream listener;
3069N/A
3069N/A protected boolean lazyAttachments = false;
3069N/A
3069N/A public OutputStream listen(OutputStream newListener) {
3069N/A OutputStream oldListener = listener;
3069N/A listener = newListener;
3069N/A return oldListener;
3069N/A }
3069N/A
3069N/A public SOAPMessage createMessage() throws SOAPException {
3069N/A throw new UnsupportedOperationException();
3069N/A }
3069N/A
3069N/A public SOAPMessage createMessage(boolean isFastInfoset,
3069N/A boolean acceptFastInfoset) throws SOAPException
3069N/A {
3069N/A throw new UnsupportedOperationException();
3069N/A }
public SOAPMessage createMessage(MimeHeaders headers, InputStream in)
throws SOAPException, IOException {
String contentTypeString = MessageImpl.getContentType(headers);
if (listener != null) {
in = new TeeInputStream(in, listener);
}
try {
ContentType contentType = new ContentType(contentTypeString);
int stat = MessageImpl.identifyContentType(contentType);
if (MessageImpl.isSoap1_1Content(stat)) {
return new Message1_1Impl(headers,contentType,stat,in);
} else if (MessageImpl.isSoap1_2Content(stat)) {
return new Message1_2Impl(headers,contentType,stat,in);
} else {
log.severe("SAAJ0530.soap.unknown.Content-Type");
throw new SOAPExceptionImpl("Unrecognized Content-Type");
}
} catch (ParseException e) {
log.severe("SAAJ0531.soap.cannot.parse.Content-Type");
throw new SOAPExceptionImpl(
"Unable to parse content type: " + e.getMessage());
}
}
protected static final String getContentType(MimeHeaders headers) {
String[] values = headers.getHeader("Content-Type");
if (values == null)
return null;
else
return values[0];
}
public void setLazyAttachmentOptimization(boolean flag) {
lazyAttachments = flag;
}
}