Search in sources :

Example 81 with CachedOutputStream

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);
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 82 with CachedOutputStream

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);
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 83 with CachedOutputStream

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);
}
Also used : File(java.io.File) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 84 with CachedOutputStream

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();
}
Also used : CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 85 with CachedOutputStream

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;
}
Also used : InputStream(java.io.InputStream) List(java.util.List) IOException(java.io.IOException) XMLSource(org.apache.cxf.jaxrs.ext.xml.XMLSource) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

CachedOutputStream (org.apache.cxf.io.CachedOutputStream)105 InputStream (java.io.InputStream)38 IOException (java.io.IOException)35 Test (org.junit.Test)24 Message (org.apache.cxf.message.Message)22 OutputStream (java.io.OutputStream)18 Fault (org.apache.cxf.interceptor.Fault)18 MessageImpl (org.apache.cxf.message.MessageImpl)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 XMLStreamException (javax.xml.stream.XMLStreamException)10 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)10 PrintWriter (java.io.PrintWriter)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 StreamSource (javax.xml.transform.stream.StreamSource)6 Endpoint (org.apache.cxf.endpoint.Endpoint)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)6 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Source (javax.xml.transform.Source)5 ArrayList (java.util.ArrayList)4