Skip to content

Commit

Permalink
Merge pull request #884 from brange/make-WebApplicationException-seri…
Browse files Browse the repository at this point in the history
…alizable

Make WebApplicationException serializable
  • Loading branch information
chkal authored Jul 11, 2020
2 parents 3d419b9 + 285b6b4 commit 9fcdde1
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class WebApplicationException extends RuntimeException {

private static final long serialVersionUID = 8273970399584007146L;
private final Response response;
private final transient Response response;

/**
* Construct a new instance with a default HTTP status code of 500 and a default message generated from the HTTP status
Expand Down
173 changes: 173 additions & 0 deletions jaxrs-api/src/test/java/jakarta/ws/rs/SerializationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package jakarta.ws.rs;

import jakarta.ws.rs.core.EntityTag;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Link;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.NewCookie;
import jakarta.ws.rs.core.Response;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.annotation.Annotation;
import java.net.URI;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.junit.Test;

public class SerializationTest {

class TestResponse extends Response {

@Override
public int getStatus() {
return 0;
}

@Override
public StatusType getStatusInfo() {
return null;
}

@Override
public Object getEntity() {
return null;
}

@Override
public <T> T readEntity(Class<T> entityType) {
return null;
}

@Override
public <T> T readEntity(GenericType<T> entityType) {
return null;
}

@Override
public <T> T readEntity(Class<T> entityType, Annotation[] annotations) {
return null;
}

@Override
public <T> T readEntity(GenericType<T> entityType, Annotation[] annotations) {
return null;
}

@Override
public boolean hasEntity() {
return false;
}

@Override
public boolean bufferEntity() {
return false;
}

@Override
public void close() {

}

@Override
public MediaType getMediaType() {
return null;
}

@Override
public Locale getLanguage() {
return null;
}

@Override
public int getLength() {
return 0;
}

@Override
public Set<String> getAllowedMethods() {
return null;
}

@Override
public Map<String, NewCookie> getCookies() {
return null;
}

@Override
public EntityTag getEntityTag() {
return null;
}

@Override
public Date getDate() {
return null;
}

@Override
public Date getLastModified() {
return null;
}

@Override
public URI getLocation() {
return null;
}

@Override
public Set<Link> getLinks() {
return null;
}

@Override
public boolean hasLink(String relation) {
return false;
}

@Override
public Link getLink(String relation) {
return null;
}

@Override
public Link.Builder getLinkBuilder(String relation) {
return null;
}

@Override
public MultivaluedMap<String, Object> getMetadata() {
return null;
}

@Override
public MultivaluedMap<String, String> getStringHeaders() {
return null;
}

@Override
public String getHeaderString(String name) {
return null;
}
}

@Test
public void testSerializaWebApplicationException() throws Exception {
final WebApplicationException exceptionWithResponse = new WebApplicationException("message", new RuntimeException("cause"), new TestResponse());
serialize(exceptionWithResponse);

}

private void serialize(WebApplicationException exception) throws IOException {
try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
) {
oos.writeObject(exception);
oos.flush();
byte[] data = bos.toByteArray();
}
}
}

0 comments on commit 9fcdde1

Please sign in to comment.