-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #884 from brange/make-WebApplicationException-seri…
…alizable Make WebApplicationException serializable
- Loading branch information
Showing
2 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
jaxrs-api/src/test/java/jakarta/ws/rs/SerializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |