|
Apache CXF example source code file (SoapTcpUtils.java)
The Apache CXF SoapTcpUtils.java source code/** * 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.binding.soap.tcp.frames.SoapTcpMessage; import org.apache.cxf.staxutils.StaxUtils; public final class SoapTcpUtils { private SoapTcpUtils() { } public static void writeSoapTcpMessage(final OutputStream out, final SoapTcpMessage msg) throws IOException { for (SoapTcpFrame frame : msg.getFrames()) { writeMessageFrame(out, frame); } } /** * 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]; if (inputStream.read(payload, 0, payload.length) != payloadLength) { throw new IOException(); } frame.setPayload(payload); return frame; } private static SoapTcpFrameContentDescription readContentDescription(final InputStream inputStream) throws IOException { final int response[] = new int[2]; 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 Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF SoapTcpUtils.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.