use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method getInputStream.
/*
private DOMSource toDOMSource(Source source) throws Exception {
if (source instanceof DOMSource) {
return (DOMSource)source;
}
Transformer trans = TransformerFactory.newInstance().newTransformer();
DOMResult result = new DOMResult();
trans.transform(source, result);
return new DOMSource(result.getNode());
}
*/
private InputStream getInputStream(Source source) throws Exception {
Transformer trans = TransformerFactory.newInstance().newTransformer();
ByteArrayBuffer bab = new ByteArrayBuffer();
StreamResult result = new StreamResult(bab);
trans.transform(source, result);
return bab.newInputStream();
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class XMLHTTPBindingCodec method transformDataSource.
public static DataSource transformDataSource(DataSource in, boolean isFastInfoset, boolean useFastInfoset, WSFeatureList f) {
try {
if (isFastInfoset && !useFastInfoset) {
// Convert from Fast Infoset to XML
Codec codec = new XMLHTTPBindingCodec(f);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
} else if (!isFastInfoset && useFastInfoset) {
// Convert from XML to Fast Infoset
Codec codec = new XMLHTTPBindingCodec(f);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.contentNegotiation = ContentNegotiation.optimistic;
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
com.sun.xml.ws.api.pipe.ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
}
} catch (Exception ex) {
throw new WebServiceException(ex);
}
return in;
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method decodePacket.
/*
*
* @param con
* @param codec
* @return
* @throws IOException
* ExceptionHasMessage exception that contains particular fault message
* UnsupportedMediaException to indicate to send 415 error code
*/
private Packet decodePacket(@NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
String ct = con.getRequestHeader("Content-Type");
InputStream in = con.getInput();
Packet packet = new Packet();
packet.soapAction = fixQuotesAroundSoapAction(con.getRequestHeader("SOAPAction"));
packet.wasTransportSecure = con.isSecure();
packet.acceptableMimeTypes = con.getRequestHeader("Accept");
packet.addSatellite(con);
addSatellites(packet);
packet.isAdapterDeliversNonAnonymousResponse = true;
packet.component = this;
packet.transportBackChannel = new Oneway(con);
packet.webServiceContextDelegate = con.getWebServiceContextDelegate();
packet.setState(Packet.State.ServerRequest);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
buf.write(in);
in.close();
dump(buf, "HTTP request", con.getRequestHeaders());
in = buf.newInputStream();
}
codec.decode(in, ct, packet);
return packet;
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method encodePacket.
private void encodePacket(@NotNull Packet packet, @NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
if (isNonAnonymousUri(packet.endpointAddress) && packet.getMessage() != null) {
try {
// Message is targeted to non-anonymous response endpoint.
// After call to non-anonymous processor, typically, packet.getMessage() will be null
// however, processors could use this pattern to modify the response sent on the back-channel,
// e.g. send custom HTTP headers with the HTTP 202
packet = getNonAnonymousResponseProcessor().process(packet);
} catch (RuntimeException re) {
// if processing by NonAnonymousResponseProcessor fails, new SOAPFaultMessage is created to be sent
// to back-channel client
SOAPVersion soapVersion = packet.getBinding().getSOAPVersion();
Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, re);
packet = packet.createServerResponse(faultMsg, packet.endpoint.getPort(), null, packet.endpoint.getBinding());
}
}
if (con.isClosed()) {
// Connection is already closed
return;
}
Message responseMessage = packet.getMessage();
addStickyCookie(con);
addReplicaCookie(con, packet);
if (responseMessage == null) {
if (!con.isClosed()) {
// for example, 415 may have been set earlier for Unsupported Content-Type
if (con.getStatus() == 0) {
con.setStatus(WSHTTPConnection.ONEWAY);
}
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
// close the response channel now
try {
// no payload
os.close();
} catch (IOException e) {
throw new WebServiceException(e);
}
}
} else {
if (con.getStatus() == 0) {
// if the appliation didn't set the status code,
// set the default one.
con.setStatus(responseMessage.isFault() ? HttpURLConnection.HTTP_INTERNAL_ERROR : HttpURLConnection.HTTP_OK);
}
if (isClientErrorStatus(con.getStatus())) {
OutputStream os = con.getOutput();
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
writeClientError(con.getStatus(), buf, packet);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
writeClientError(con.getStatus(), os, packet);
}
os.close();
return;
}
ContentType contentType = codec.getStaticContentType(packet);
if (contentType != null) {
con.setContentTypeResponseHeader(contentType.getContentType());
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
os.close();
} else {
ByteArrayBuffer buf = new ByteArrayBuffer();
contentType = codec.encode(packet, buf);
con.setContentTypeResponseHeader(contentType.getContentType());
if (dump || LOGGER.isLoggable(Level.FINER)) {
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
}
OutputStream os = con.getOutput();
buf.writeTo(os);
os.close();
}
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class AbstractSchemaValidationTube method createDOM.
private Document createDOM(SDDocument doc) {
// Get infoset
ByteArrayBuffer bab = new ByteArrayBuffer();
try {
doc.writeTo(null, resolver, bab);
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
// Convert infoset to DOM
Transformer trans = XmlUtil.newTransformer();
// doc.getURL().toExternalForm());
Source source = new StreamSource(bab.newInputStream(), null);
DOMResult result = new DOMResult();
try {
trans.transform(source, result);
} catch (TransformerException te) {
throw new WebServiceException(te);
}
return (Document) result.getNode();
}
Aggregations