Repository: cxf Updated Branches: refs/heads/master ffd30fee7 -> 3225f35c5 http://git-wip-us.apache.org/repos/asf/cxf/blob/a63b9462/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java ---------------------------------------------------------------------- diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java deleted file mode 100644 index a6ad4f1..0000000 --- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpFrameHeader.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 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); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/a63b9462/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpMessage.java ---------------------------------------------------------------------- diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpMessage.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpMessage.java deleted file mode 100644 index d5f500c..0000000 --- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/tcp/frames/SoapTcpMessage.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -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.tcp.DataCodingUtils; -import org.apache.cxf.binding.soap.tcp.SoapTcpOutputStream; - -public final class SoapTcpMessage { - private List frames; - - private SoapTcpMessage() { - frames = new ArrayList(); - } - - public static SoapTcpMessage createSoapTcpMessage(SoapTcpFrame frame) { - SoapTcpMessage soapTcpMessage = new SoapTcpMessage(); - soapTcpMessage.getFrames().add(frame); - return soapTcpMessage; - } - - public static SoapTcpMessage createSoapTcpMessage(List frames) { - SoapTcpMessage soapTcpMessage = new SoapTcpMessage(); - soapTcpMessage.getFrames().addAll(frames); - return soapTcpMessage; - } - - public static SoapTcpMessage createSoapTcpMessage(String message, int channelId) { - SoapTcpMessage soapTcpMessage = new SoapTcpMessage(); - try { - byte[] msgContent = message.getBytes("UTF-8"); - int numOfFrames = (int)Math.ceil((float)msgContent.length - / (float)SoapTcpOutputStream.CHUNK_SIZE); - if (numOfFrames > 1) { - int offset = 0; - byte[] payload = new byte[SoapTcpOutputStream.CHUNK_SIZE]; - for (int i = 1; i <= numOfFrames; i++) { - if (i == numOfFrames) { - payload = new byte[msgContent.length % SoapTcpOutputStream.CHUNK_SIZE]; - } - - for (int j = 0; j < payload.length; j++) { - payload[j] = msgContent[offset + j]; - } - - SoapTcpFrame frame = null; - if (i == 1) { - frame = createSoapTcpFrame(SoapTcpFrameHeader.MESSAGE_START_CHUNK, - payload, channelId); - } else if (i < numOfFrames) { - frame = createSoapTcpFrame(SoapTcpFrameHeader.MESSAGE_CHUNK, payload, channelId); - } else { - frame = createSoapTcpFrame(SoapTcpFrameHeader.MESSAGE_END_CHUNK, payload, channelId); - } - - soapTcpMessage.frames.add(frame); - offset += SoapTcpOutputStream.CHUNK_SIZE; - } - - } else { - soapTcpMessage.frames. - add(createSoapTcpFrame(SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE, msgContent, channelId)); - } - return soapTcpMessage; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return null; - } - - public static SoapTcpMessage createErrorMessage(int code, int subCode, String description, - int channelId) { - SoapTcpMessage soapTcpMessage = new SoapTcpMessage(); - SoapTcpFrame frame = new SoapTcpFrame(); - SoapTcpFrameHeader header = new SoapTcpFrameHeader(); - header.setChannelId(channelId); - header.setFrameType(SoapTcpFrameHeader.ERROR_MESSAGE); - frame.setHeader(header); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - DataCodingUtils.writeInts4(baos, code, subCode); - byte[] strByteArray = description.getBytes("UTF-8"); - DataCodingUtils.writeInt8(baos, strByteArray.length); - baos.write(strByteArray); - } catch (IOException e) { - e.printStackTrace(); - } - frame.setPayload(baos.toByteArray()); - soapTcpMessage.getFrames().add(frame); - - return soapTcpMessage; - } - - public void setChannelId(int channelId) { - for (SoapTcpFrame frame : frames) { - frame.setChannelId(channelId); - } - } - - public int getChannelId() { - if (frames.size() > 0) { - return frames.get(0).getChannelId(); - } - return -1; - } - - public void setFrames(List frames) { - this.frames = frames; - } - - public List getFrames() { - return frames; - } - - public String getContent() { - StringBuilder result = new StringBuilder(); - - try { - for (SoapTcpFrame frame : frames) { - result.append(new String(frame.getPayload(), "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - return result.toString(); - } - - public InputStream getContentAsStream() { - int buffLength = 0; - for (SoapTcpFrame frame : frames) { - buffLength += frame.getPayload().length; - } - byte buffer[] = new byte[buffLength]; - int index = 0; - byte payload[] = null; - for (SoapTcpFrame frame : frames) { - payload = frame.getPayload(); - for (int i = 0; i < payload.length; i++) { - buffer[index] = payload[i]; - index++; - } - } - return new ByteArrayInputStream(buffer); - } - - private static SoapTcpFrame createSoapTcpFrame(int frameType, byte[] payload, int channelId) { - SoapTcpFrame frame = new SoapTcpFrame(); - SoapTcpFrameHeader header = new SoapTcpFrameHeader(); - SoapTcpFrameContentDescription contentDesc = null; - if (frameType == SoapTcpFrameHeader.SINGLE_FRAME_MESSAGE - || frameType == SoapTcpFrameHeader.MESSAGE_START_CHUNK) { - contentDesc = new SoapTcpFrameContentDescription(); - contentDesc.setContentId(0); - - final Map parameters = new Hashtable(); - parameters.put(0, "utf-8"); - - contentDesc.setParameters(parameters); - } - header.setChannelId(channelId); - header.setFrameType(frameType); - header.setContentDescription(contentDesc); - frame.setHeader(header); - frame.setPayload(payload); - return frame; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/a63b9462/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java ---------------------------------------------------------------------- diff --git a/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java b/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java deleted file mode 100644 index e6076af..0000000 --- a/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/tcp/TCPConduitTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * 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.List; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.cxf.binding.soap.SoapMessage; -import org.apache.cxf.message.Message; -import org.apache.cxf.message.MessageImpl; -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.assertNotNull; - -@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 = "" - + "http://tempuri.org/ICalculator/add" - + "urn:uuid:e2606099-5bef-4db2-b661-19a883bab4e7" - + "http://www.w3.org/2005/08/addressing/anonymous" - + "soap.tcp://localhost:9999/calculator" - + "" - + "" + num1 + "" - + "" + num2 + "" - + ""; - */ - - - /*final String messageData = "" - + "" - + num1 + "" + num2 + "";*/ - String name = new String("CXF"); - /*for (int i = 0; i < 6000; i++) { - name += "A"; - }*/ - final String messageData = "" - + "" + name + ""; - - final AttributedURIType a = new AttributedURIType(); - //a.setValue("soap.tcp://localhost:8080/CalculatorApp/CalculatorWSService"); - a.setValue("soap.tcp://localhost:9999/HelloWorld"); - 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> headers = new TreeMap>(String.CASE_INSENSITIVE_ORDER); - List contentTypes = new ArrayList(); - 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); - String s = new String(response, "UTF-8"); - System.out.println(s); - } 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(); - }*/ - } - - } -}