List of usage examples for org.apache.http.entity SerializableEntity SerializableEntity
public SerializableEntity(Serializable serializable, boolean z) throws IOException
From source file:org.httplog4j.client.HTTPLog4jAppender.java
public void append(LoggingEvent event) { if (event == null) return;/* www. j av a 2 s.c o m*/ if (httpClient == null) return; //don't log events generated by calling this appender, leads to infinite call loop if (event.getLoggerName().startsWith("org.apache.http")) return; System.out.println(event.getLoggerName()); event.getNDC(); event.getThreadName(); event.getMDCCopy(); event.getRenderedMessage(); event.getThrowableStrRep(); HttpPost httpPost = new HttpPost(remoteURI); try { httpPost.setEntity(new SerializableEntity(event, true)); HttpResponse response = httpClient.execute(httpPost); } catch (Exception exception) { LogLog.warn("could not publish to logging server", exception); } }
From source file:com.lonepulse.robozombie.util.Entities.java
/** * <p>Discovers which implementation of {@link HttpEntity} is suitable for wrapping the given object. * This discovery proceeds in the following order by checking the runtime-type of the object:</p> * * <ol>/*from w w w.jav a 2 s . c o m*/ * <li>org.apache.http.{@link HttpEntity} --> returned as-is.</li> * <li>{@code byte[]}, {@link Byte}[] --> {@link ByteArrayEntity}</li> * <li>java.io.{@link File} --> {@link FileEntity}</li> * <li>java.io.{@link InputStream} --> {@link BufferedHttpEntity}</li> * <li>{@link CharSequence} --> {@link StringEntity}</li> * <li>java.io.{@link Serializable} --> {@link SerializableEntity} (with an internal buffer)</li> * </ol> * * @param genericEntity * a generic reference to an object whose concrete {@link HttpEntity} is to be resolved * <br><br> * @return the resolved concrete {@link HttpEntity} implementation * <br><br> * @throws NullPointerException * if the supplied generic type was {@code null} * <br><br> * @throws EntityResolutionFailedException * if the given generic instance failed to be translated to an {@link HttpEntity} * <br><br> * @since 1.3.0 */ public static final HttpEntity resolve(Object genericEntity) { assertNotNull(genericEntity); try { if (genericEntity instanceof HttpEntity) { return (HttpEntity) genericEntity; } else if (byte[].class.isAssignableFrom(genericEntity.getClass())) { return new ByteArrayEntity((byte[]) genericEntity); } else if (Byte[].class.isAssignableFrom(genericEntity.getClass())) { Byte[] wrapperBytes = (Byte[]) genericEntity; byte[] primitiveBytes = new byte[wrapperBytes.length]; for (int i = 0; i < wrapperBytes.length; i++) { primitiveBytes[i] = wrapperBytes[i].byteValue(); } return new ByteArrayEntity(primitiveBytes); } else if (genericEntity instanceof File) { return new FileEntity((File) genericEntity, null); } else if (genericEntity instanceof InputStream) { BasicHttpEntity basicHttpEntity = new BasicHttpEntity(); basicHttpEntity.setContent((InputStream) genericEntity); return new BufferedHttpEntity(basicHttpEntity); } else if (genericEntity instanceof CharSequence) { return new StringEntity(((CharSequence) genericEntity).toString()); } else if (genericEntity instanceof Serializable) { return new SerializableEntity((Serializable) genericEntity, true); } else { throw new EntityResolutionFailedException(genericEntity); } } catch (Exception e) { throw (e instanceof EntityResolutionFailedException) ? (EntityResolutionFailedException) e : new EntityResolutionFailedException(genericEntity, e); } }
From source file:com.lonepulse.zombielink.processor.SerializerEndpointTest.java
/** * <p>Test for detachment of the inherited serializer.</p> * * @since 1.3.0//ww w .ja v a2 s. c om */ @Test public final void testDetachSerializer() throws ParseException, IOException { String subpath = "/detach"; User user = new User(1, "Roy", "Mustang", 30, false); stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200))); serializerEndpoint.detachSerializer(user); verify(putRequestedFor(urlEqualTo(subpath)) .withRequestBody(equalTo(EntityUtils.toString(new SerializableEntity(user, true))))); }
From source file:com.sayar.requests.RequestArguments.java
/** * Setter for the request entity. The serializable will be placed in the * request./*from w w w. j a v a 2 s.c o m*/ * * @param ser * @param bufferize * @throws IOException */ public void setRequestEntity(final Serializable ser, final boolean bufferize) throws IOException { this.requestEntity = new SerializableEntity(ser, bufferize); }
From source file:com.lonepulse.zombielink.processor.RequestParamEndpointTest.java
/** * <p>Test for a {@link Request} with a {@link Serializable} entity.</p> * //from www. j a v a 2 s .c om * @since 1.3.0 */ @Test public final void testSerializableEntity() throws ParseException, IOException { String subpath = "/serializableentity"; User entity = new User(1L, "Eren", "Yeager", 15, false); SerializableEntity se = new SerializableEntity(entity, true); stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200))); requestEndpoint.serializableEntity(entity); verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(EntityUtils.toString(se)))); }