Package com.betfair.cougar.util.stream

Examples of com.betfair.cougar.util.stream.ByteCountingOutputStream


                        responseMediaType = MediaType.APPLICATION_XML_TYPE;
                    }
                    response.setContentType(responseMediaType.toString());
                    DataBindingFactory dataBindingFactory = DataBindingManager.getInstance().getFactory(responseMediaType);
                    FaultMarshaller marshaller = dataBindingFactory.getFaultMarshaller();
                    ByteCountingOutputStream out = null;
                    try {
                        out = new ByteCountingOutputStream(response.getOutputStream());
                        marshaller.marshallFault(out, error.getFault(), getContentTypeNormaliser().getNormalisedEncoding(request));
                        bytesWritten = out.getCount();
                    } catch (IOException e) {
                        handleResponseWritingIOException(e, error.getClass());
                    } finally {
                        closeStream(out);
                    }
View Full Code Here


                        MediaType responseMediaType = getContentTypeNormaliser().getNormalisedResponseMediaType(request);
                        DataBindingFactory dataBindingFactory = DataBindingManager.getInstance().getFactory(responseMediaType);
                        Marshaller marshaller = dataBindingFactory.getMarshaller();
                        String encoding = getContentTypeNormaliser().getNormalisedEncoding(request);
                        response.setContentType(responseMediaType.toString());
                        ByteCountingOutputStream out = null;
                        try {
                            out = new ByteCountingOutputStream(response.getOutputStream());
                            Object toMarshall = responseWrapper;
                            if (responseMediaType.getSubtype().equals("json")) {
                                toMarshall = responseWrapper.getResult();
                            }
                            marshaller.marshall(out, toMarshall, encoding, false);
                            logAccess(command,
                                    context, bytesRead,
                                    out.getCount(), requestMediaType,
                                    responseMediaType, ResponseCode.Ok);
                        } finally {
                            closeStream(out);
                        }
                    }
View Full Code Here

    try {
            long bytesWritten = 0;
            if(error.getResponseCode() != ResponseCode.CantWriteToSocket) {

                ResponseCodeMapper.setResponseStatus(response, error.getResponseCode());
                ByteCountingOutputStream out = null;
                try {
                    int jsonErrorCode = mapServerFaultCodeToJsonErrorCode(error.getServerFaultCode());
                    JsonRpcError rpcError = new JsonRpcError(jsonErrorCode, error.getFault().getErrorCode(), null);
                    JsonRpcErrorResponse jsonRpcErrorResponse = JsonRpcErrorResponse.buildErrorResponse(null, rpcError);

                    out = new ByteCountingOutputStream(response.getOutputStream());
                    mapper.writeValue(out, jsonRpcErrorResponse);
                    bytesWritten = out.getCount();
                } catch (IOException ex) {
                    handleResponseWritingIOException(ex, error.getClass());
                } finally {
                    closeStream(out);
                }
View Full Code Here

                                return tokenResolver.isRewriteSupported();
                            }
                        });
                  }
          response.setContentType(MediaType.APPLICATION_JSON);
                  ByteCountingOutputStream out = null;
                  try {
                      out = new ByteCountingOutputStream(response.getOutputStream());
                      mapper.writeValue(out, isBatch ? responses : responses.get(0));
                  } finally {
                        closeStream(out);
                  }

                    logAccess(command,
                            context, bytesRead,
                            out.getCount(), MediaType.APPLICATION_JSON_TYPE,
                            MediaType.APPLICATION_JSON_TYPE, ResponseCode.Ok);

        } catch (Exception e) {
                    writeErrorResponse(command, context, handleResponseWritingIOException(e, JsonRpcResponse.class));
        } finally {
View Full Code Here

    }

    private void writeResponse(HttpCommand command, SoapOperationBinding binding, Object result, CougarException error,
                               ExecutionContextWithTokens context, long bytesRead) {
        MediaType mediaType = MediaType.TEXT_XML_TYPE;
        ByteCountingOutputStream out = null;
        long bytesWritten = 0;
        boolean logAccess = true;
        try {
            command.getResponse().setContentType(mediaType.toString());
            out = new ByteCountingOutputStream(command.getResponse().getOutputStream());
            SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope envelope = factory.createSOAPEnvelope();
            SOAPHeader header = factory.createSOAPHeader(envelope);
            writeHeaders(factory, header, command, context);
            SOAPBody body = factory.createSOAPBody(envelope);
            writeError(factory, binding, body, error);
            writeBody(factory, binding, body, result);
            envelope.serialize(out);
            bytesWritten = out.getCount();
        } catch (Exception e) {
            CougarException ce = handleResponseWritingIOException(e, result.getClass());

            if (ce.getResponseCode() == ResponseCode.CantWriteToSocket) {
                // Log in the access log what's happened and end it all.
View Full Code Here

                        responseMediaType = MediaType.APPLICATION_XML_TYPE;
                    }
                    response.setContentType(responseMediaType.toString());
                    DataBindingFactory dataBindingFactory = DataBindingManager.getInstance().getFactory(responseMediaType);
                    FaultMarshaller marshaller = dataBindingFactory.getFaultMarshaller();
                    ByteCountingOutputStream out = null;
                    try {
                        out = new ByteCountingOutputStream(response.getOutputStream());
                        marshaller.marshallFault(out, error.getFault(), getContentTypeNormaliser().getNormalisedEncoding(request));
                        bytesWritten = out.getCount();
                    } catch (IOException e) {
                        handleResponseWritingIOException(e, error.getClass());
                    } finally {
                        closeStream(out);
                    }
View Full Code Here

                        MediaType responseMediaType = getContentTypeNormaliser().getNormalisedResponseMediaType(request);
                        DataBindingFactory dataBindingFactory = DataBindingManager.getInstance().getFactory(responseMediaType);
                        Marshaller marshaller = dataBindingFactory.getMarshaller();
                        String encoding = getContentTypeNormaliser().getNormalisedEncoding(request);
                        response.setContentType(responseMediaType.toString());
                        ByteCountingOutputStream out = null;
                        try {
                            out = new ByteCountingOutputStream(response.getOutputStream());
                            Object toMarshall = responseWrapper;
                            if (responseMediaType.getSubtype().equals("json")) {
                                toMarshall = responseWrapper.getResult();
                            }
                            marshaller.marshall(out, toMarshall, encoding);
                            logAccess(command,
                                    context, bytesRead,
                                    out.getCount(), requestMediaType,
                                    responseMediaType, ResponseCode.Ok);
                        } finally {
                            closeStream(out);
                        }
                    }
View Full Code Here

    }

    private void writeResponse(HttpCommand command, SoapOperationBinding binding, Object result, CougarException error,
                               ExecutionContextWithTokens context, long bytesRead) {
        MediaType mediaType = MediaType.TEXT_XML_TYPE;
        ByteCountingOutputStream out = null;
        long bytesWritten = 0;
        boolean logAccess = true;
        try {
            command.getResponse().setContentType(mediaType.toString());
            out = new ByteCountingOutputStream(command.getResponse().getOutputStream());
            SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope envelope = factory.createSOAPEnvelope();
            SOAPHeader header = factory.createSOAPHeader(envelope);
            writeHeaders(factory, header, command, context);
            SOAPBody body = factory.createSOAPBody(envelope);
            writeError(factory, binding, body, error);
            writeBody(factory, binding, body, result);
            envelope.serialize(out);
            bytesWritten = out.getCount();
        } catch (Exception e) {
            CougarException ce = handleResponseWritingIOException(e, result.getClass());

            if (ce.getResponseCode() == ResponseCode.CantWriteToSocket) {
                // Log in the access log what's happened and end it all.
View Full Code Here

    try {
            long bytesWritten = 0;
            if(error.getResponseCode() != ResponseCode.CantWriteToSocket) {

                ResponseCodeMapper.setResponseStatus(response, error.getResponseCode());
                ByteCountingOutputStream out = null;
                try {
                    int jsonErrorCode = mapServerFaultCodeToJsonErrorCode(error.getServerFaultCode());
                    JsonRpcError rpcError = new JsonRpcError(jsonErrorCode, error.getFault().getErrorCode(), null);
                    JsonRpcErrorResponse jsonRpcErrorResponse = JsonRpcErrorResponse.buildErrorResponse(null, rpcError);

                    out = new ByteCountingOutputStream(response.getOutputStream());
                    mapper.writeValue(out, jsonRpcErrorResponse);
                    bytesWritten = out.getCount();
                } catch (IOException ex) {
                    handleResponseWritingIOException(ex, error.getClass());
                } finally {
                    closeStream(out);
                }
View Full Code Here

                                return tokenResolver.isRewriteSupported();
                            }
                        });
                  }
          response.setContentType(MediaType.APPLICATION_JSON);
                  ByteCountingOutputStream out = null;
                  try {
                      out = new ByteCountingOutputStream(response.getOutputStream());
                      mapper.writeValue(out, isBatch ? responses : responses.get(0));
                  } finally {
                        closeStream(out);
                  }

                    logAccess(command,
                            context, bytesRead,
                            out.getCount(), MediaType.APPLICATION_JSON_TYPE,
                            MediaType.APPLICATION_JSON_TYPE, ResponseCode.Ok);

        } catch (Exception e) {
                    writeErrorResponse(command, context, handleResponseWritingIOException(e, JsonRpcResponse.class));
        } finally {
View Full Code Here

TOP

Related Classes of com.betfair.cougar.util.stream.ByteCountingOutputStream

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.