use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method byteAsAttachmentMaxSize.
@Test
public void byteAsAttachmentMaxSize() throws IOException {
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Byte.MAX_VALUE, cos);
replay(cos);
cos.setMaxSize(Byte.MAX_VALUE);
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method longAsAttachmentMaxSize.
@Test
public void longAsAttachmentMaxSize() throws IOException {
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Long.MAX_VALUE, cos);
replay(cos);
cos.setMaxSize(Long.MAX_VALUE);
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentUtilTest method fileAsAttachmentDirectory.
@Test
public void fileAsAttachmentDirectory() throws IOException {
File attachmentDirectory = new File("/dev/null");
CachedOutputStream cos = createMock(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory, cos);
replay(cos);
cos.setOutputDir(attachmentDirectory);
cos.setThreshold(102400L);
verify(cos);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class Client method getStringFromInputStream.
private static String getStringFromInputStream(InputStream in) throws Exception {
CachedOutputStream bos = new CachedOutputStream();
IOUtils.copy(in, bos);
in.close();
bos.close();
return bos.getOut().toString();
}
use of org.apache.cxf.io.CachedOutputStream in project ddf by codice.
the class EndpointOperationInfoResourceComparator method compare.
@Override
public int compare(OperationResourceInfo oper1, OperationResourceInfo oper2, Message message) {
if (null == oper1 || null == oper2 || null == message) {
LOGGER.debug("Found NULL parameters in the compare method.");
return -1;
}
String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD);
LOGGER.debug("HTTP METHOD = {}", httpMethod);
String requestName = null;
String requestedService = null;
if (HTTP_GET.equalsIgnoreCase(httpMethod)) {
String queryString = (String) message.get(Message.QUERY_STRING);
if (StringUtils.isNotEmpty(queryString)) {
MultivaluedMap<String, String> allQueryParams = JAXRSUtils.getStructuredParams(queryString, QUERY_PARAM_DELIMITER, false, false);
// Loop through the keys and do a case insensitive check
for (Entry<String, List<String>> queryParam : allQueryParams.entrySet()) {
if ((REQUEST_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam.getValue().isEmpty()) && requestName == null) {
// We should never have more than one "request" query
// param so ignore them if we do
requestName = queryParam.getValue().get(0);
LOGGER.debug("Request Query Param = {}", requestName);
}
if ((SERVICE_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam.getValue().isEmpty()) && requestedService == null) {
// We should never have more than one "service" query
// param so ignore them if we do
requestedService = queryParam.getValue().get(0);
LOGGER.debug("Service Query Param = {}", requestedService);
}
}
}
} else if (HTTP_POST.equalsIgnoreCase(httpMethod)) {
// Get the payload
try (InputStream is = message.getContent(InputStream.class)) {
if (is != null) {
try (CachedOutputStream bos = new CachedOutputStream()) {
// We need to make a copy and put it back for later
// processing
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
XMLSource xml = new XMLSource(bos.getInputStream());
xml.setBuffering();
// The request name will be the root node name
requestName = xml.getValue("local-name(/*)");
requestedService = xml.getValue("/*/@service");
LOGGER.debug("ROOT NODE = {}", requestName);
LOGGER.debug("Service Name = {}", requestedService);
}
}
} catch (IOException ioe) {
LOGGER.info("Unable to read message contents", ioe);
}
} else {
LOGGER.info("Got unknown HTTP Method {}", httpMethod);
return -1;
}
int op1Rank = getOperationRank(oper1, requestName, requestedService);
int op2Rank = getOperationRank(oper2, requestName, requestedService);
if (op1Rank == -1 && op2Rank == -1) {
return -1;
}
return (op1Rank == op2Rank) ? 0 : (op1Rank < op2Rank) ? 1 : -1;
}
Aggregations