@Override public void writeTo(final Object t, final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(t.toString().getBytes(MessageUtils.getCharset(mediaType))); }
@Override public void writeTo(final Set<String> s, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { final PrintStream ps = new PrintStream(entityStream, true, MessageUtils.getCharset(mediaType).name()); for (final String item : s) { ps.println(item); } } }
@Override public void writeTo(final Object t, final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(String.format("%s%s%s", JsonOpenning, t.toString(), JsonClosing) .getBytes(MessageUtils.getCharset(mediaType))); }
@Override public Object readFrom(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { return new ClipboardData(readStringFromStream(entityStream, MessageUtils.getCharset(mediaType))); } }
@Override public Set<String> readFrom(final Class<Set<String>> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { final BufferedReader br = new BufferedReader(new InputStreamReader(entityStream, MessageUtils.getCharset(mediaType))); final Set<String> result = new HashSet<>(); String line; while ((line = br.readLine()) != null) { result.add(line); } return result; } }
@Override public Object readFrom(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { final String jsonExpression = readStringFromStream(entityStream, MessageUtils.getCharset(mediaType)); return new ClipboardData(jsonExpression.replace(JsonOpenning, "").replace(JsonClosing, "")); } }
@Override public Reader readFrom( final Class<Reader> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream inputStream) throws IOException { final EntityInputStream entityStream = EntityInputStream.create(inputStream); if (entityStream.isEmpty()) { return new BufferedReader(new InputStreamReader( new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType))); } return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType))); }
@Override public Reader readFrom( final Class<Reader> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream inputStream) throws IOException { final EntityInputStream entityStream = EntityInputStream.create(inputStream); if (entityStream.isEmpty()) { return new BufferedReader(new InputStreamReader( new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType))); } return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType))); }
private enum State { SKIPPING_PREPENDED_EMPTY_EVENTS, NEW_LINE, COMMENT, FIELD, }
private void processField(final InboundEvent.Builder inboundEventBuilder, final String name, final MediaType mediaType, final byte[] value) { final String valueString = new String(value, MessageUtils.getCharset(mediaType)); if ("event".equals(name)) { inboundEventBuilder.name(valueString); } else if ("data".equals(name)) { inboundEventBuilder.write(value); inboundEventBuilder.write(EOL_DATA); } else if ("id".equals(name)) { inboundEventBuilder.id(valueString); } else if ("retry".equals(name)) { try { inboundEventBuilder.reconnectDelay(Long.parseLong(valueString)); } catch (final NumberFormatException ex) { LOGGER.log(Level.FINE, LocalizationMessages.IN_EVENT_RETRY_PARSE_ERROR(valueString), ex); } } else { LOGGER.fine(LocalizationMessages.IN_EVENT_FIELD_NOT_RECOGNIZED(name, valueString)); } } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
@Override public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY); writerInterceptorContext.proceed(); if (logger.isLoggable(level) && printEntity(verbosity, writerInterceptorContext.getMediaType())) { if (stream != null) { log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType()))); } } }
@Override public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY); writerInterceptorContext.proceed(); if (logger.isLoggable(level) && printEntity(verbosity, writerInterceptorContext.getMediaType())) { if (stream != null) { log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType()))); } } }
@Override public void filter(final ContainerRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } final long id = _id.incrementAndGet(); context.setProperty(LOGGING_ID_PROPERTY, id); final StringBuilder b = new StringBuilder(); printRequestLine(b, "Server has received a request", id, context.getMethod(), context.getUriInfo().getRequestUri()); printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getHeaders()); if (context.hasEntity() && printEntity(verbosity, context.getMediaType())) { context.setEntityStream( logInboundEntity(b, context.getEntityStream(), MessageUtils.getCharset(context.getMediaType()))); } log(b); }
@Override public void filter(final ContainerRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } final long id = _id.incrementAndGet(); context.setProperty(LOGGING_ID_PROPERTY, id); final StringBuilder b = new StringBuilder(); printRequestLine(b, "Server has received a request", id, context.getMethod(), context.getUriInfo().getRequestUri()); printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getHeaders()); if (context.hasEntity() && printEntity(verbosity, context.getMediaType())) { context.setEntityStream( logInboundEntity(b, context.getEntityStream(), MessageUtils.getCharset(context.getMediaType()))); } log(b); }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
@Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Client response received", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(b); } }
if (ds.getAlgorithm() == Algorithm.MD5_SESS) { ha1 = md5(md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())))); } else { ha1 = md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())));
if (ds.getAlgorithm() == Algorithm.MD5_SESS) { ha1 = md5(md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())))); } else { ha1 = md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())));