You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/07/30 18:16:47 UTC
svn commit: r799349 - in /cxf/trunk/rt/bindings/soap/src:
main/java/org/apache/cxf/binding/soap/
main/java/org/apache/cxf/binding/soap/tcp/
main/java/org/apache/cxf/binding/soap/tcp/frames/
test/java/org/apache/cxf/binding/soap/tcp/
Author: dkulp
Date: Thu Jul 30 16:16:46 2009
New Revision: 799349
URL: http://svn.apache.org/viewvc?rev=799349&view=rev
Log:
[CXF-2257] Start adding support for the soap-tcp stuff
Added:
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java (with props)
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java (with props)
cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/
cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java (with props)
Modified:
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapTransportFactory.java
Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapTransportFactory.java?rev=799349&r1=799348&r2=799349&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapTransportFactory.java (original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapTransportFactory.java Thu Jul 30 16:16:46 2009
@@ -21,8 +21,11 @@
import java.io.IOException;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.wsdl.Port;
@@ -33,6 +36,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusException;
import org.apache.cxf.binding.soap.model.SoapBindingInfo;
+import org.apache.cxf.binding.soap.tcp.TCPConduit;
import org.apache.cxf.binding.soap.wsdl11.SoapAddressPlugin;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.BindingInfo;
@@ -64,7 +68,9 @@
public SoapTransportFactory() {
super();
}
-
+ public Set<String> getUriPrefixes() {
+ return Collections.singleton("soap.tcp");
+ }
public String mapTransportURI(String s) {
if ("http://www.w3.org/2008/07/soap/bindings/JMS/".equals(s)) {
s = "http://cxf.apache.org/transports/jms";
@@ -145,6 +151,11 @@
}
public Conduit getConduit(EndpointInfo ei) throws IOException {
+ if (ei.getAddress().startsWith("soap.tcp://")) {
+ //TODO - examine policies and stuff to look for the sun tcp policies
+ return new TCPConduit(ei);
+ }
+
SoapBindingInfo binding = (SoapBindingInfo)ei.getBinding();
ConduitInitiator conduitInit;
try {
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public final class ChannelIdParser {
+
+ private ChannelIdParser() {
+
+ }
+
+ /**
+ * Method for retrieving channel id from OpenChannelResponse message.
+ *
+ * @param in a InputStream with message
+ * @return channel id value
+ */
+ public static int getChannelId(InputStream in) {
+ XMLStreamReader streamReader = StaxUtils.createXMLStreamReader(in, null);
+
+ try {
+ while (streamReader.hasNext()) {
+ streamReader.next();
+ int eventType = streamReader.getEventType();
+ if (eventType == XMLStreamReader.START_ELEMENT
+ && streamReader.getLocalName().equals("openChannelResponse")) {
+ while (streamReader.hasNext()) {
+ streamReader.next();
+ eventType = streamReader.getEventType();
+ if (eventType == XMLStreamReader.START_ELEMENT
+ && streamReader.getLocalName().equals("channelId")) {
+ return Integer.parseInt(streamReader.getElementText());
+ }
+ }
+ }
+ }
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ }
+
+ return 0;
+ }
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/ChannelIdParser.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,197 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.*;
+
+/**
+ * DataCodingUtils is a utility class for reading and writing integers in SOAP over TCP protocol.
+ */
+public final class DataCodingUtils {
+
+ private DataCodingUtils() {
+
+ }
+
+ /**
+ * Method for reading INTEGER4 values from InputStream
+ *
+ * @param inputStream a source stream
+ * @param array a buffer for read data
+ * @param count a number of integers to be read
+ * @throws IOException
+ */
+ public static void readInts4(final InputStream inputStream, final int[] array,
+ final int count) throws IOException {
+ int value = 0;
+ int octet = 0;
+ int readInts = 0;
+ int shVal = 0;
+ int neeble = 0;
+ int neebleNum = 0;
+
+ for (; readInts < count; neebleNum++) {
+ if (neebleNum % 2 == 0) {
+ octet = inputStream.read();
+ if (octet == -1) {
+ throw new EOFException();
+ }
+ neeble = octet >> 4;
+ } else {
+ neeble = octet & 0xF;
+ }
+
+ value |= (neeble & 7) << shVal;
+ if ((neeble & 8) == 0) {
+ array[readInts++] = value;
+ shVal = 0;
+ value = 0;
+ } else {
+ shVal += 3;
+ }
+ }
+ }
+
+ /**
+ * Method for reading single INTEGER8 value
+ *
+ * @param inputStream a source stream
+ * @return read integer
+ * @throws IOException
+ */
+ public static int readInt8(final InputStream inputStream) throws IOException {
+ int value = 0;
+ int shVal = 0;
+ for (int octet = 0x80; (octet & 0x80) != 0; shVal += 7) {
+ octet = inputStream.read();
+ if (octet == -1) {
+ throw new EOFException();
+ }
+
+ value |= (octet & 0x7F) << shVal;
+ }
+
+ return value;
+ }
+
+ /**
+ * Method for writing single INTEGER4 value into OutputStream
+ *
+ * @param outputStream a target stream
+ * @param intValue value that will be written
+ * @throws IOException
+ */
+ public static void writeInt8(final OutputStream outputStream, final int intValue) throws IOException {
+ int octet;
+ int value = intValue;
+ do {
+ octet = value & 0x7F;
+ value >>>= 7;
+
+ if (value != 0) {
+ octet |= 0x80;
+ }
+
+ outputStream.write(octet);
+ } while(value != 0);
+ }
+
+ /**
+ * Method for writing variable number of integer values as INTEGER4 values
+ *
+ * @param outputStream a target stream
+ * @param values a variable length list of integer values that will be written
+ * @throws IOException
+ */
+ public static void writeInts4(final OutputStream outputStream, final int ... values) throws IOException {
+ writeInts4(outputStream, values, 0, values.length);
+ }
+
+ /**
+ * Method for writing integers as INTEGER4 values
+ *
+ * @param outputStream a target stream
+ * @param array values that will be written
+ * @param offset an offset in array from method starts writing
+ * @param count a number of integers to be written
+ * @throws IOException
+ */
+ public static void writeInts4(final OutputStream outputStream, final int[] array,
+ final int offset, final int count) throws IOException {
+ int shiftValue = 0;
+ for (int i = 0; i < count - 1; i++) {
+ final int value = array[offset + i];
+ shiftValue = writeInt4(outputStream, value, shiftValue, false);
+ }
+
+ if (count > 0) {
+ writeInt4(outputStream, array[offset + count - 1], shiftValue, true);
+ }
+ }
+
+ private static int writeInt4(final OutputStream outputStream, final int intValue,
+ final int highValue, final boolean flush) throws IOException {
+ int nibbleL;
+ int nibbleH;
+ int value = intValue;
+ int hValue = highValue;
+
+ if (hValue > 0) {
+ hValue &= 0x70; // clear highest bit
+ nibbleL = value & 7;
+ value >>>= 3;
+ if (value != 0) {
+ nibbleL |= 8;
+ }
+
+ outputStream.write(hValue | nibbleL);
+
+ if (value == 0) {
+ return 0;
+ }
+ }
+
+ do {
+ // shift nibbleH to high byte's bits
+ nibbleH = (value & 7) << 4;
+ value >>>= 3;
+
+ if (value != 0) {
+ nibbleH |= 0x80;
+ nibbleL = value & 7;
+ value >>>= 3;
+ if (value != 0) {
+ nibbleL |= 8;
+ }
+ } else {
+ if (!flush) {
+ return nibbleH | 0x80;
+ }
+
+ nibbleL = 0;
+ }
+
+ outputStream.write(nibbleH | nibbleL);
+ } while(value != 0);
+
+ return 0;
+ }
+
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/DataCodingUtils.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,271 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.binding.soap.Soap11;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrame;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameContentDescription;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameHeader;
+import org.apache.cxf.io.AbstractThresholdOutputStream;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.transport.MessageObserver;
+
+/**
+ * SoapTCPOutPutStream is OutputStream for sending message in SOAP/TCP protocol.
+ * It sends single message in one or more SOAP/TCP frames.
+ */
+public class SoapTcpOutputStream extends AbstractThresholdOutputStream {
+ public static final int CHUNK_SIZE = 4096;
+
+ private int channelId;
+ private OutputStream outStream;
+ private InputStream inStream;
+ private boolean messageSent;
+ private Message outMessage;
+ private int chunkSize;
+
+ private MessageObserver incomingObserver;
+
+ public SoapTcpOutputStream(final InputStream inStream, final OutputStream outStream,
+ final Message message, final String targetWsURI,
+ final MessageObserver incomingObserver) {
+ this(inStream, outStream, message, targetWsURI, incomingObserver, CHUNK_SIZE);
+ }
+
+ public SoapTcpOutputStream(final InputStream inStream, final OutputStream outStream,
+ final Message message, final String targetWsURI,
+ final MessageObserver incomingObserver, final int chunkSize) {
+ super(chunkSize);
+ this.messageSent = false;
+ this.inStream = inStream;
+ this.outStream = outStream;
+ this.outMessage = message;
+ this.wrappedStream = null;
+ this.chunkSize = chunkSize;
+ this.incomingObserver = incomingObserver;
+
+ final List<String> mimeTypes = new ArrayList<String>();
+
+ SoapMessage m = (SoapMessage)message;
+
+ //mimeTypes.add("application/vnd.sun.stateful.fastinfoset");
+ mimeTypes.add(m.getVersion().getContentType());
+ //mimeTypes.add("multipart/related");
+
+
+ final List<String> supportedParams = new ArrayList<String>();
+ supportedParams.add("charset");
+ if (m.getVersion() == Soap11.getInstance()) {
+ supportedParams.add("SOAPAction");
+ } else {
+ supportedParams.add("action");
+ }
+
+ try {
+ channelId = openChannel(targetWsURI, mimeTypes, supportedParams);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private int openChannel(final String targetWsURI, final List<String> supportedMimeTypes,
+ final List<String> supportedParams) throws IOException {
+
+ String openChannelMsg = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<s:Body><openChannel xmlns=\"http://servicechannel.tcp.transport.ws.xml.sun.com/\""
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
+ openChannelMsg += "<targetWSURI xmlns=\"\">" + targetWsURI + "</targetWSURI>";
+
+ for (String mimeType : supportedMimeTypes) {
+ openChannelMsg += "<negotiatedMimeTypes xmlns=\"\">" + mimeType + "</negotiatedMimeTypes>";
+ }
+ for (String param : supportedParams) {
+ openChannelMsg += "<negotiatedParams xmlns=\"\">" + param + "</negotiatedParams>";
+ }
+
+ openChannelMsg += "</openChannel></s:Body></s:Envelope>";
+
+ SoapTcpFrameContentDescription contentDesc = new SoapTcpFrameContentDescription();
+ contentDesc.setContentId(0);
+
+ final Map<Integer, String> parameters = new Hashtable<Integer, String>();
+ parameters.put(0, "utf-8");
+
+ contentDesc.setParameters(parameters);
+
+ final SoapTcpFrameHeader header =
+ new SoapTcpFrameHeader(SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE, contentDesc);
+ final SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(0);
+ frame.setHeader(header);
+ try {
+ frame.setPayload(openChannelMsg.getBytes("UTF-8"));
+ SoapTcpUtils.writeMessageFrame(outStream, frame);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ final SoapTcpFrame response = SoapTcpUtils.readMessageFrame(inStream);
+ if (!SoapTcpUtils.checkSingleFrameResponse(response, "openChannelResponse")) {
+ throw new IOException("Couldn't open new channel.");
+ }
+ //SoapTcpUtils.printSoapTcpFrame(System.out, response);
+
+ return getChannelIdFromResponse(response);
+ }
+
+ private int getChannelIdFromResponse(final SoapTcpFrame frame) {
+ return ChannelIdParser.getChannelId(new ByteArrayInputStream(frame.getPayload()));
+ }
+
+ @Override
+ public void thresholdNotReached() throws IOException {
+ //Send single message if didn't send any message yet or end message if already send message
+ if (messageSent) {
+ SoapTcpFrameHeader header = new SoapTcpFrameHeader(SoapTcpFrameHeader.MESSAGE_END_CHUNK, null);
+ header.setChannelId(channelId);
+ SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(channelId);
+ frame.setHeader(header);
+ frame.setPayload(this.buffer.toByteArray());
+ SoapTcpUtils.writeMessageFrame(outStream, frame);
+ } else {
+ final SoapTcpFrameContentDescription contentDesc = new SoapTcpFrameContentDescription();
+ contentDesc.setContentId(0);
+
+ final Map<Integer, String> parameters = new Hashtable<Integer, String>();
+ parameters.put(0, "utf-8");
+
+ contentDesc.setParameters(parameters);
+
+ final SoapTcpFrameHeader header =
+ new SoapTcpFrameHeader(SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE, contentDesc);
+ header.setChannelId(channelId);
+ final SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(channelId);
+ frame.setHeader(header);
+ frame.setPayload(this.buffer.toByteArray());
+ SoapTcpUtils.writeMessageFrame(outStream, frame);
+ messageSent = true;
+ }
+ }
+
+ @Override
+ public void thresholdReached() throws IOException {
+ //Send start-chunk message if didn't send any message yet or message chunk if already send message
+ if (messageSent) {
+ SoapTcpFrameHeader header = new SoapTcpFrameHeader(SoapTcpFrameHeader.MESSAGE_CHUNK, null);
+ header.setChannelId(channelId);
+ SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(channelId);
+ frame.setHeader(header);
+ frame.setPayload(this.buffer.toByteArray());
+ SoapTcpUtils.writeMessageFrame(outStream, frame);
+ } else {
+ SoapTcpFrameContentDescription contentDesc = new SoapTcpFrameContentDescription();
+ contentDesc.setContentId(0);
+
+ Map<Integer, String> parameters = new Hashtable<Integer, String>();
+ parameters.put(0, "utf-8");
+
+ contentDesc.setParameters(parameters);
+
+ SoapTcpFrameHeader header =
+ new SoapTcpFrameHeader(SoapTcpFrameHeader.MESSAGE_START_CHUNK, contentDesc);
+ header.setChannelId(channelId);
+ SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(channelId);
+ frame.setHeader(header);
+ frame.setPayload(this.buffer.toByteArray());
+ SoapTcpUtils.writeMessageFrame(outStream, frame);
+ messageSent = true;
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ if (messageSent) {
+ InputStream inputStream = getResponse();
+ Exchange exchange = outMessage.getExchange();
+ Message inMessage = new MessageImpl();
+ inMessage.setExchange(exchange);
+ inMessage.setContent(InputStream.class, inputStream);
+
+ incomingObserver.onMessage(inMessage);
+ }
+ }
+
+ @Override
+ protected void onFirstWrite() throws IOException {
+
+ }
+
+ private InputStream getResponse() {
+ SoapTcpFrame responseMessage = null;
+ try {
+ responseMessage = SoapTcpUtils.readMessageFrame(inStream);
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ }
+ if (responseMessage != null) {
+ int frameType = responseMessage.getHeader().getFrameType();
+ if (frameType == SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE
+ || frameType == SoapTcpFrameHeader.ERROR_MESSAGE
+ || frameType == SoapTcpFrameHeader.NULL_MESSAGE) {
+ return new ByteArrayInputStream(responseMessage.getPayload());
+ } else if (frameType == SoapTcpFrameHeader.MESSAGE_START_CHUNK) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4 * chunkSize);
+ try {
+ baos.write(responseMessage.getPayload());
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ while (frameType != SoapTcpFrameHeader.MESSAGE_END_CHUNK) {
+ try {
+ SoapTcpFrame frame = SoapTcpUtils.readMessageFrame(inStream);
+ baos.write(frame.getPayload());
+ } catch (IOException e) {
+ break;
+ }
+ }
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,209 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrame;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameContentDescription;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameHeader;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public final class SoapTcpUtils {
+
+ private SoapTcpUtils() {
+
+ }
+
+ /**
+ * Method that writes single SoapTcpFrame
+ * @param out
+ * @param frame
+ * @throws IOException
+ */
+ public static void writeMessageFrame(final OutputStream out, final SoapTcpFrame frame) throws IOException
+ {
+ if (frame != null) {
+ final SoapTcpFrameHeader header = frame.getHeader();
+ final byte payload[] = frame.getPayload();
+ if (header != null && payload != null) {
+ header.write(out);
+ DataCodingUtils.writeInt8(out, payload.length);
+ out.write(payload);
+ out.flush();
+ }
+ }
+ }
+
+ /**
+ * Method that reads single SoapTcpFrame
+ * @param inputStream
+ * @return
+ * @throws IOException
+ */
+ public static SoapTcpFrame readMessageFrame(final InputStream inputStream) throws IOException
+ {
+ final SoapTcpFrame frame = new SoapTcpFrame();
+ final SoapTcpFrameHeader header = new SoapTcpFrameHeader();
+ frame.setHeader(header);
+
+ final int response[] = new int[2]; //[0] channel-id, [1] message-id
+ DataCodingUtils.readInts4(inputStream, response, 2);
+
+ frame.setChannelId(response[0]);
+ header.setChannelId(response[0]);
+ header.setFrameType(response[1]);
+ switch(response[1]) {
+ case SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE:
+ header.setContentDescription(readContentDescription(inputStream));
+ break;
+ case SoapTcpFrameHeader.MESSAGE_START_CHUNK:
+ header.setContentDescription(readContentDescription(inputStream));
+ break;
+ case SoapTcpFrameHeader.MESSAGE_CHUNK:
+ break;
+ case SoapTcpFrameHeader.MESSAGE_END_CHUNK:
+ break;
+ case SoapTcpFrameHeader.ERROR_MESSAGE:
+ break;
+ case SoapTcpFrameHeader.NULL_MESSAGE:
+ break;
+ default:
+ }
+
+ final int payloadLength = DataCodingUtils.readInt8(inputStream);
+ final byte payload[] = new byte[payloadLength];
+ inputStream.read(payload, 0, payload.length);
+ frame.setPayload(payload);
+
+ return frame;
+ }
+
+ private static SoapTcpFrameContentDescription readContentDescription(final InputStream inputStream) {
+ final int response[] = new int[2];
+ try {
+ DataCodingUtils.readInts4(inputStream, response, 2); //[0] content-id, [1] number-of-parameters
+
+ final SoapTcpFrameContentDescription contentDesc = new SoapTcpFrameContentDescription();
+ contentDesc.setContentId(response[0]);
+ final int numOfParams = response[1];
+
+ final Map<Integer, String> parameters = new Hashtable<Integer, String>();
+ for (int i = 0; i < numOfParams; i++) {
+ DataCodingUtils.readInts4(inputStream, response, 2); //[0] parameter-id, [1] string-length
+ if (response[1] > 0) {
+ final byte[] buffer = new byte[response[1]];
+ if (inputStream.read(buffer) > 0) {
+ final String value = new String(buffer, "UTF-8");
+ parameters.put(Integer.valueOf(response[0]), value);
+ //System.out.println("parameter-id = " + response[0] + " parameter-value = " + value);
+ }
+ }
+ }
+ contentDesc.setParameters(parameters);
+
+ return contentDesc;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Method that parse SoapTcpFrame payload to find important tag.
+ *
+ * @param responseFrame frame that will be examinated
+ * @param elementName a tag to look for
+ * @return true If payload contains that tag then method return true
+ * otherwise return false;
+ */
+ public static boolean checkSingleFrameResponse(final SoapTcpFrame responseFrame,
+ final String elementName) {
+ if (responseFrame != null
+ && responseFrame.getHeader().getFrameType() == SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE) {
+ ByteArrayInputStream bais = new ByteArrayInputStream(responseFrame.getPayload());
+ XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(bais);
+ try {
+ while (xmlReader.hasNext()) {
+ xmlReader.next();
+ if (xmlReader.getEventType() == XMLStreamReader.START_ELEMENT
+ && xmlReader.getLocalName().equals(elementName)) {
+ return true;
+ }
+ }
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Method that print SoapTcpFrame
+ * @param out
+ * @param frame
+ */
+ public static void printSoapTcpFrame(final OutputStream out, final SoapTcpFrame frame) {
+ if (frame != null) {
+ final PrintStream writer = (PrintStream)out;
+ writer.println("channel-id: " + frame.getChannelId());
+
+ final SoapTcpFrameHeader header = frame.getHeader();
+ if (header != null) {
+ writer.println("frameType: " + header.getFrameType());
+ final SoapTcpFrameContentDescription contentDesc = header.getContentDescription();
+ if (contentDesc != null) {
+ writer.println("content-id: " + contentDesc.getContentId());
+ final Map<Integer, String> parameters = contentDesc.getParameters();
+ if (parameters != null) {
+ final Iterator<Integer> keys = parameters.keySet().iterator();
+ writer.println("parameters");
+ while (keys.hasNext()) {
+ final Integer key = keys.next();
+ final String value = parameters.get(key);
+ writer.println(key + " : " + value);
+ }
+ }
+ }
+ }
+ final byte payload[] = frame.getPayload();
+ if (payload != null) {
+ try {
+ final String messageContent = new String(payload, "UTF-8");
+ writer.println("messageContent:");
+ writer.println(messageContent);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/SoapTcpUtils.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,185 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.Socket;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrame;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameContentDescription;
+import org.apache.cxf.binding.soap.tcp.frames.SoapTcpFrameHeader;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.Configurable;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractConduit;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.ws.policy.Assertor;
+
+public class TCPConduit
+ extends AbstractConduit
+ implements Configurable, Assertor {
+
+ private static final Logger LOG = LogUtils.getL7dLogger(TCPConduit.class);
+
+ private static final String MAGIC_IDENTIFIER = "vnd.sun.ws.tcp";
+ private static final int PROTOCOL_VERSION_MAJOR = 1;
+ private static final int PROTOCOL_VERSION_MINOR = 0;
+ private static final int CONNECTION_MANAGEMENT_VERSION_MAJOR = 1;
+ private static final int CONNECTION_MANAGEMENT_VERSION_MINOR = 0;
+
+ private Socket socket;
+ private InputStream in;
+ private OutputStream out;
+ private String endPointAddress;
+
+ public TCPConduit(EndpointInfo t) throws IOException {
+ this(t.getTarget());
+ }
+ public TCPConduit(EndpointReferenceType t) throws IOException {
+ super(t);
+
+ String hostName = null;
+ int port = 0;
+
+ String address = t.getAddress().getValue();
+ if (address.contains("soap.tcp://")) {
+ endPointAddress = address;
+ int beginIndex = address.indexOf("://");
+ int endIndex = address.indexOf(":", beginIndex + 1);
+ hostName = address.substring(beginIndex + 3, endIndex);
+ beginIndex = endIndex;
+ endIndex = address.indexOf("/", beginIndex);
+ port = Integer.parseInt(address.substring(beginIndex + 1, endIndex));
+ //System.out.println("hostName: " + hostName);
+ //System.out.println("port: " + port);
+ }
+
+ socket = new Socket(hostName, port);
+ in = socket.getInputStream();
+ out = socket.getOutputStream();
+
+ out.write(MAGIC_IDENTIFIER.getBytes("US-ASCII"));
+ DataCodingUtils.writeInts4(out, PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR,
+ CONNECTION_MANAGEMENT_VERSION_MAJOR,
+ CONNECTION_MANAGEMENT_VERSION_MINOR);
+ out.flush();
+
+ final int version[] = new int[4];
+ DataCodingUtils.readInts4(in, version, 4);
+
+ //System.out.println("serverProtocolVersionMajor = " + version[0]);
+ //System.out.println("serverProtocolVersionMinor = " + version[1]);
+ //System.out.println("serverConnectionManagementVersionMajor = " + version[2]);
+ //System.out.println("serverConnectionManagementVersionMinor = " + version[3]);
+
+ initSession();
+ }
+
+ private void initSession() throws IOException {
+ final String initSessionMessage = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<s:Body><initiateSession xmlns=\"http://servicechannel.tcp.transport.ws.xml.sun.com/\""
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"/></s:Body></s:Envelope>";
+ byte[] initSessionMessageBytes = null;
+ try {
+ initSessionMessageBytes = initSessionMessage.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ final SoapTcpFrameContentDescription contentDesc = new SoapTcpFrameContentDescription();
+ contentDesc.setContentId(0);
+
+ Map<Integer, String> parameters = new Hashtable<Integer, String>();
+ parameters.put(0, "utf-8");
+
+ contentDesc.setParameters(parameters);
+
+ final SoapTcpFrameHeader header =
+ new SoapTcpFrameHeader(SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE, contentDesc);
+ SoapTcpFrame frame = new SoapTcpFrame();
+ frame.setChannelId(0);
+ frame.setHeader(header);
+ frame.setPayload(initSessionMessageBytes);
+ try {
+ SoapTcpUtils.writeMessageFrame(out, frame);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ final SoapTcpFrame response = SoapTcpUtils.readMessageFrame(in);
+ if (!SoapTcpUtils.checkSingleFrameResponse(response, "initiateSessionResponse")) {
+ throw new IOException("Could not initiate SOAP/TCP connection.");
+ }
+ //SoapTcpUtils.printSoapTcpFrame(System.out, response);
+ }
+
+ @Override
+ protected Logger getLogger() {
+ return LOG;
+ }
+
+ public String getBeanName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void assertMessage(Message message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean canAssert(QName type) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void prepare(Message message) throws IOException {
+ final SoapTcpOutputStream soapTcpOutputStream =
+ new SoapTcpOutputStream(in, out, message, endPointAddress, incomingObserver);
+ message.setContent(OutputStream.class, soapTcpOutputStream);
+ }
+
+ @Override
+ public void close(Message message) {
+
+ }
+
+ @Override
+ public void close() {
+ try {
+ in.close();
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/TCPConduit.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp.frames;
+
+
+public class SoapTcpFrame {
+ private int channelId;
+ private SoapTcpFrameHeader header;
+ private byte[] payload;
+
+ public int getChannelId() {
+ return channelId;
+ }
+ public void setChannelId(int channelId) {
+ this.channelId = channelId;
+ }
+ public SoapTcpFrameHeader getHeader() {
+ return header;
+ }
+ public void setHeader(SoapTcpFrameHeader header) {
+ this.header = header;
+ }
+ public byte[] getPayload() {
+ return payload;
+ }
+ public void setPayload(byte[] payload) {
+ this.payload = payload;
+ }
+
+
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrame.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp.frames;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.cxf.binding.soap.tcp.DataCodingUtils;
+
+public class SoapTcpFrameContentDescription {
+ private int contentId;
+ private Map<Integer, String> parameters;
+
+ public int getContentId() {
+ return contentId;
+ }
+
+ public void setContentId(final int contentId) {
+ this.contentId = contentId;
+ }
+
+ public Map<Integer, String> getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(final Map<Integer, String> parameters) {
+ this.parameters = parameters;
+ }
+
+ public void write(final OutputStream output) throws IOException {
+ DataCodingUtils.writeInts4(output, contentId, parameters.size());
+ final Iterator<Integer> keys = parameters.keySet().iterator();
+ while (keys.hasNext()) {
+ final Integer paramId = keys.next();
+ final String paramValue = parameters.get(paramId);
+ final byte[] paramValueBytes = paramValue.getBytes("UTF-8");
+ DataCodingUtils.writeInts4(output, paramId.intValue(), paramValueBytes.length);
+ output.write(paramValueBytes);
+ }
+ }
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameContentDescription.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java (added)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp.frames;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.cxf.binding.soap.tcp.DataCodingUtils;
+
+public class SoapTcpFrameHeader {
+
+ //Message Frame Types
+ public static final int SINGLE_FRAME_MESSAGE = 0;
+ public static final int MESSAGE_START_CHUNK = 1;
+ public static final int MESSAGE_CHUNK = 2;
+ public static final int MESSAGE_END_CHUNK = 3;
+ public static final int ERROR_MESSAGE = 4;
+ public static final int NULL_MESSAGE = 5;
+
+ private int channelId;
+ private int frameType;
+ private SoapTcpFrameContentDescription contentDescription;
+
+ public SoapTcpFrameHeader(final int frameType, final SoapTcpFrameContentDescription contentDescription) {
+ this.frameType = frameType;
+ this.contentDescription = contentDescription;
+ }
+
+ public SoapTcpFrameHeader() {
+ this.frameType = NULL_MESSAGE;
+ this.contentDescription = null;
+ }
+
+ public int getChannelId() {
+ return channelId;
+ }
+
+ public void setChannelId(int channelId) {
+ this.channelId = channelId;
+ }
+
+ public int getFrameType() {
+ return frameType;
+ }
+
+ public void setFrameType(int frameType) {
+ this.frameType = frameType;
+ }
+
+ public SoapTcpFrameContentDescription getContentDescription() {
+ return contentDescription;
+ }
+
+ public void setContentDescription(SoapTcpFrameContentDescription contentDescription) {
+ this.contentDescription = contentDescription;
+ }
+
+ public void write(final OutputStream output) throws IOException {
+ DataCodingUtils.writeInts4(output, channelId, frameType);
+ if ((frameType == SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE
+ || frameType == SoapTcpFrameHeader.MESSAGE_START_CHUNK) && contentDescription != null) {
+ contentDescription.write(output);
+ }
+ }
+}
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java?rev=799349&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java (added)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java Thu Jul 30 16:16:46 2009
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.soap.tcp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@Ignore
+public class TCPConduitTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testTCPConduit() {
+ //TCPConduit tcpConduit = new TCPConduit(null);
+ }
+
+ @Test
+ public void testPrepare() {
+ int num1 = 2;
+ int num2 = 3;
+ /*
+ final String messageData = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\""
+ + " xmlns:a=\"http://www.w3.org/2005/08/addressing\"><s:Header><a:Action s:mustUnderstand=\"1\">"
+ + "http://tempuri.org/ICalculator/add</a:Action>"
+ + "<a:MessageID>urn:uuid:e2606099-5bef-4db2-b661-19a883bab4e7</a:MessageID><a:ReplyTo>"
+ + "<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>"
+ + "<a:To s:mustUnderstand=\"1\">soap.tcp://localhost:9999/calculator</a:To></s:Header><s:Body>"
+ + "<add xmlns=\"http://tempuri.org/\">"
+ + "<i>" + num1 + "</i>"
+ + "<j>" + num2 + "</j>"
+ + "</add></s:Body></s:Envelope>";
+ */
+
+
+ final String messageData = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<S:Body><ns2:add xmlns:ns2=\"http://calculator.me.org/\"><i>"
+ + num1 + "</i><j>" + num2 + "</j></ns2:add></S:Body></S:Envelope>";
+
+ final AttributedURIType a = new AttributedURIType();
+ a.setValue("soap.tcp://localhost:8080/CalculatorApp/CalculatorWSService");
+ final EndpointReferenceType t = new EndpointReferenceType();
+ t.setAddress(a);
+
+ try {
+ final TCPConduit tcpConduit = new TCPConduit(t);
+ tcpConduit.setMessageObserver(new TestMessageObserver());
+ final Message msg = getNewMessage();
+
+ tcpConduit.prepare(msg);
+
+ final OutputStream out = msg.getContent(OutputStream.class);
+ out.write(messageData.getBytes("UTF-8"));
+ out.flush();
+ out.close();
+ tcpConduit.close(msg);
+
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Message getNewMessage() {
+ Message message = new MessageImpl();
+ message = new SoapMessage(message);
+ Map<String, List<String>> headers = new HashMap<String, List<String>>();
+ List<String> contentTypes = new ArrayList<String>();
+ contentTypes.add("text/xml");
+ contentTypes.add("charset=utf8");
+ headers.put("content-type", contentTypes);
+ message.put(Message.PROTOCOL_HEADERS, headers);
+ return message;
+ }
+
+ private class TestMessageObserver implements MessageObserver {
+
+ public void onMessage(final Message message) {
+ int correctResult = 5;
+ assertNotNull(message);
+ InputStream input = message.getContent(InputStream.class);
+ byte response[] = null;
+ try {
+ response = new byte[input.available()];
+ input.read(response);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(response);
+
+ XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(bais, "UTF-8");
+ while (xmlReader.hasNext()) {
+ xmlReader.next();
+ if (xmlReader.getEventType() == XMLStreamReader.START_ELEMENT
+ && xmlReader.getLocalName().equals("addResult")) {
+ assertEquals(correctResult, Integer.parseInt(xmlReader.getElementText()));
+ }
+ }
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
Propchange: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date