Package org.eclipse.jetty.io

Examples of org.eclipse.jetty.io.ByteArrayBuffer


                // serialized java object
                Serializable obj = exchange.getIn().getMandatoryBody(Serializable.class);
                // write object to output stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                HttpHelper.writeObjectToStream(bos, obj);
                httpExchange.setRequestContent(new ByteArrayBuffer(bos.toByteArray()));
                IOHelper.close(bos);
            } else {
                Object body = exchange.getIn().getBody();
                if (body instanceof String) {
                    String data = (String) body;
                    // be a bit careful with String as any type can most likely be converted to String
                    // so we only do an instanceof check and accept String if the body is really a String
                    // do not fallback to use the default charset as it can influence the request
                    // (for example application/x-www-form-urlencoded forms being sent)
                    String charset = IOHelper.getCharsetName(exchange, false);
                    if (charset != null) {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data, charset));
                    } else {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data));
                    }
                } else {
                    // then fallback to input stream
                    InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, exchange.getIn().getBody());
                    httpExchange.setRequestContentSource(is);
View Full Code Here


            try {

                LOG.info("Logging clientId: {} into Salesforce url: {}", config.getClientId(), url);

                // set form content
                loginPost.setRequestContent(new ByteArrayBuffer(
                        nvps.encode(StringUtil.__UTF8, true).getBytes(StringUtil.__UTF8)));
                httpClient.send(loginPost);

                // wait for the login to finish
                final int exchangeState = loginPost.waitForDone();
View Full Code Here

    @Override
    public void createBatchQuery(String jobId, String soqlQuery, ContentType jobContentType,
        final BatchInfoResponseCallback callback) {
        final ContentExchange post = getContentExchange(HttpMethods.POST, batchUrl(jobId, null));
        byte[] queryBytes = soqlQuery.getBytes(StringUtil.__UTF8_CHARSET);
        post.setRequestContent(new ByteArrayBuffer(queryBytes));
        post.setRequestContentType(getContentType(jobContentType) + ";charset=" + StringUtil.__UTF8);

        // make the call and parse the result
        doHttpRequest(post, new ClientResponseCallback() {
            @Override
View Full Code Here

    private void marshalRequest(Object input, ContentExchange request, String contentType) throws SalesforceException {
        try {
            Marshaller marshaller = context.createMarshaller();
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            marshaller.marshal(input, byteStream);
            request.setRequestContent(new ByteArrayBuffer(byteStream.toByteArray()));
            request.setRequestContentType(contentType);
        } catch (JAXBException e) {
            throw new SalesforceException(
                    String.format("Error marshaling request for {%s:%s} : %s",
                            request.getMethod(), request.getRequestURI(), e.getMessage()),
View Full Code Here

                Serializable obj = exchange.getIn().getMandatoryBody(Serializable.class);
                // write object to output stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                try {
                    HttpHelper.writeObjectToStream(bos, obj);
                    httpExchange.setRequestContent(new ByteArrayBuffer(bos.toByteArray()));
                } finally {
                    IOHelper.close(bos, "body", LOG);
                }
            } else {
                Object body = exchange.getIn().getBody();
                if (body instanceof String) {
                    String data = (String) body;
                    // be a bit careful with String as any type can most likely be converted to String
                    // so we only do an instanceof check and accept String if the body is really a String
                    // do not fallback to use the default charset as it can influence the request
                    // (for example application/x-www-form-urlencoded forms being sent)
                    String charset = IOHelper.getCharsetName(exchange, false);
                    if (charset != null) {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data, charset));
                    } else {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data));
                    }
                } else {
                    // then fallback to input stream
                    InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, exchange.getIn().getBody());
                    httpExchange.setRequestContentSource(is);
View Full Code Here

                // serialized java object
                Serializable obj = exchange.getIn().getMandatoryBody(Serializable.class);
                // write object to output stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                HttpHelper.writeObjectToStream(bos, obj);
                httpExchange.setRequestContent(new ByteArrayBuffer(bos.toByteArray()));
                IOHelper.close(bos);
            } else {
                Object body = exchange.getIn().getBody();
                if (body instanceof String) {
                    String data = (String) body;
                    // be a bit careful with String as any type can most likely be converted to String
                    // so we only do an instanceof check and accept String if the body is really a String
                    // do not fallback to use the default charset as it can influence the request
                    // (for example application/x-www-form-urlencoded forms being sent)
                    String charset = IOHelper.getCharsetName(exchange, false);
                    if (charset != null) {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data, charset));
                    } else {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data));
                    }
                } else {
                    // then fallback to input stream
                    InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, exchange.getIn().getBody());
                    httpExchange.setRequestContentSource(is);
View Full Code Here

                // serialized java object
                Serializable obj = exchange.getIn().getMandatoryBody(Serializable.class);
                // write object to output stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                HttpHelper.writeObjectToStream(bos, obj);
                httpExchange.setRequestContent(new ByteArrayBuffer(bos.toByteArray()));
                IOHelper.close(bos);
            } else {
                // try with String at first
                String data = exchange.getIn().getBody(String.class);
                if (data != null) {
                    String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
                    if (charset != null) {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data, charset));
                    } else {
                        httpExchange.setRequestContent(new ByteArrayBuffer(data));
                    }
                } else {
                    // then fallback to input stream
                    InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, exchange.getIn().getBody());
                    httpExchange.setRequestContentSource(is);
View Full Code Here

                    ContentExchange exchange = new ContentExchange(true);
                    exchange.setMethod(HttpMethods.POST);
                    exchange.setAddress(address);
                    exchange.setURI(server.getContext().getContextPath()+GatewayServer.DFT_EXT_PATH + "/" + URLEncoder.encode(targetId, "UTF-8"));
                    String requestContent = "body";
                    exchange.setRequestContent(new ByteArrayBuffer(requestContent.getBytes("UTF-8")));
                    httpClient.send(exchange);

                    int status = exchange.waitForDone();
                    assertEquals(HttpExchange.STATUS_COMPLETED, status);
                    assertEquals(HttpServletResponse.SC_GATEWAY_TIMEOUT, exchange.getResponseStatus());
View Full Code Here

            exchange.setAddress(address);
            exchange.setMethod(request.getMethod());
            exchange.setURI(request.getURI());
            for (Map.Entry<String, String> header : request.getHeaders().entrySet())
                exchange.setRequestHeader(header.getKey(), header.getValue());
            exchange.setRequestContent(new ByteArrayBuffer(request.getBody()));
            int status = syncSend(exchange);
            if (status == HttpExchange.STATUS_COMPLETED)
            {
                int statusCode = exchange.getResponseStatus();
                String statusMessage = exchange.getResponseMessage();
View Full Code Here

                    ContentExchange exchange = new ContentExchange(true);
                    exchange.setMethod(HttpMethods.POST);
                    exchange.setAddress(address);
                    exchange.setURI(server.getContext().getContextPath()+GatewayServer.DFT_EXT_PATH + "/" + URLEncoder.encode(targetId, "UTF-8"));
                    String requestContent = "body";
                    exchange.setRequestContent(new ByteArrayBuffer(requestContent.getBytes("UTF-8")));
                    httpClient.send(exchange);

                    int status = exchange.waitForDone();
                    assertEquals(HttpExchange.STATUS_COMPLETED, status);
                    assertEquals(HttpServletResponse.SC_OK, exchange.getResponseStatus());
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.io.ByteArrayBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.