Skip to content

Commit

Permalink
Fix compilation and checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
reta committed Sep 19, 2023
1 parent 3ef7b6e commit cd259c4
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public EntityPartBuilderImpl(String name) {
}

@Override
public Builder mediaType(MediaType mediaType) throws IllegalArgumentException {
this.mediaType = mediaType;
public Builder mediaType(MediaType mt) throws IllegalArgumentException {
this.mediaType = mt;
return this;
}

@Override
public Builder mediaType(String mediaTypeString) throws IllegalArgumentException {
this.mediaType = MediaType.valueOf(mediaTypeString);
public Builder mediaType(String mts) throws IllegalArgumentException {
this.mediaType = MediaType.valueOf(mts);
return this;
}

Expand All @@ -76,29 +76,29 @@ public Builder headers(MultivaluedMap<String, String> newHeaders) throws Illegal
}

@Override
public Builder fileName(String fileName) throws IllegalArgumentException {
this.fileName = fileName;
public Builder fileName(String fn) throws IllegalArgumentException {
this.fileName = fn;
return this;
}

@Override
public Builder content(InputStream content) throws IllegalArgumentException {
this.content = content;
public Builder content(InputStream in) throws IllegalArgumentException {
this.content = in;
return this;
}

@Override
public <T> Builder content(T content, Class<? extends T> type) throws IllegalArgumentException {
this.content = content;
this.type = type;
public <T> Builder content(T c, Class<? extends T> t) throws IllegalArgumentException {
this.content = c;
this.type = t;
this.genericType = null;
return this;
}

@Override
public <T> Builder content(T content, GenericType<T> type) throws IllegalArgumentException {
this.content = content;
this.genericType = type;
public <T> Builder content(T c, GenericType<T> t) throws IllegalArgumentException {
this.content = c;
this.genericType = t;
this.type = null;
return this;
}
Expand All @@ -109,12 +109,12 @@ public EntityPart build() throws IllegalStateException, IOException, WebApplicat
final Message message = JAXRSUtils.getCurrentMessage();

if (genericType != null) {
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writeTo(genericType, mt, message, out);
return new EntityPartImpl(name, fileName, new ByteArrayInputStream(out.toByteArray()), headers, mt);
}
} else if (type != null) {
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writeTo(type, mt, message, out);
return new EntityPartImpl(name, fileName, new ByteArrayInputStream(out.toByteArray()), headers, mt);
}
Expand All @@ -124,25 +124,25 @@ public EntityPart build() throws IllegalStateException, IOException, WebApplicat
}

@SuppressWarnings("unchecked")
private <T> void writeTo(final GenericType<T> type, final MediaType mt, final Message message,
private <T> void writeTo(final GenericType<T> t, final MediaType mt, final Message message,
final ByteArrayOutputStream out) throws IOException {

final MessageBodyWriter<T> writer = (MessageBodyWriter<T>) ProviderFactory
.getInstance(message)
.createMessageBodyWriter(genericType.getRawType(), genericType.getType(), null, mt, message);
.createMessageBodyWriter(t.getRawType(), t.getType(), null, mt, message);

writer.writeTo((T) content, type.getRawType(), type.getType(), null, mt, cast(headers), out);
writer.writeTo((T) content, t.getRawType(), t.getType(), null, mt, cast(headers), out);
}

@SuppressWarnings("unchecked")
private <T> void writeTo(final Class<T> type, final MediaType mt, final Message message,
private <T> void writeTo(final Class<T> t, final MediaType mt, final Message message,
final ByteArrayOutputStream out) throws IOException {

final MessageBodyWriter<T> writer = (MessageBodyWriter<T>) ProviderFactory
.getInstance(message)
.createMessageBodyWriter(type, null, null, mt, message);
.createMessageBodyWriter(t, null, null, mt, message);

writer.writeTo((T) content, type, null, null, mt, cast(headers), out);
writer.writeTo((T) content, t, null, null, mt, cast(headers), out);
}

private static <T, U> MultivaluedMap<T, U> cast(MultivaluedMap<?, ?> p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class EntityPartImpl implements EntityPart {
private final MultivaluedMap<String, String> headers;
private final MediaType mediaType;

EntityPartImpl(String name, String fileName, InputStream content, MultivaluedMap<String, String> headers, MediaType mediaType) {
EntityPartImpl(String name, String fileName, InputStream content,
MultivaluedMap<String, String> headers, MediaType mediaType) {
this.name = name;
this.fileName = fileName;
this.content = content;
Expand All @@ -62,18 +63,25 @@ public InputStream getContent() {
}

@Override
public <T> T getContent(Class<T> type) throws IllegalArgumentException, IllegalStateException, IOException, WebApplicationException {
public <T> T getContent(Class<T> type)
throws IllegalArgumentException, IllegalStateException, IOException, WebApplicationException {
@SuppressWarnings({ "unchecked", "rawtypes" })
final MessageBodyReader<T> reader = (MessageBodyReader) ProviderFactory.getInstance(null).createMessageBodyReader(type, null, null, mediaType, null);
final MessageBodyReader<T> reader = (MessageBodyReader) ProviderFactory
.getInstance(null)
.createMessageBodyReader(type, null, null, mediaType, null);

return reader.readFrom(type, null, null, mediaType, headers, content);
}

@SuppressWarnings("unchecked")
@Override
public <T> T getContent(GenericType<T> type) throws IllegalArgumentException, IllegalStateException, IOException, WebApplicationException {
public <T> T getContent(GenericType<T> type)
throws IllegalArgumentException, IllegalStateException, IOException, WebApplicationException {
@SuppressWarnings("rawtypes")
final MessageBodyReader<T> reader = (MessageBodyReader) ProviderFactory.getInstance(null).createMessageBodyReader(type.getRawType(), type.getType(), null, mediaType, null);
final MessageBodyReader<T> reader = (MessageBodyReader) ProviderFactory
.getInstance(null)
.createMessageBodyReader(type.getRawType(), type.getType(), null, mediaType, null);

return reader.readFrom((Class<T>) type.getRawType(), type.getType(), null, mediaType, headers, content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import jakarta.ws.rs.core.UriBuilder;
import jakarta.ws.rs.core.Variant.VariantListBuilder;
import jakarta.ws.rs.ext.RuntimeDelegate;

import org.apache.cxf.configuration.jsse.TLSServerParameters;
import org.apache.cxf.configuration.security.ClientAuthentication;
import org.apache.cxf.endpoint.Server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ public static Collection<Object[]> data() throws ParseException {
new Object[] {"Sun, 03 Nov 2002 08:49:37 EST", Duration.ofSeconds(89646577)},
new Object[] {"Sat, 01 Jan 2000 01:00:00 GMT", Duration.ofSeconds(3600)},
new Object[] {"Sunday, 03-Nov-02 08:49:37 GMT", Duration.ofSeconds(89628577)},
new Object[] {"Sun Nov 3 08:49:37 2002", Duration.ofSeconds(89628577 - TimeZone.getDefault().getOffset(new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US).parse("Sun Nov 3 08:49:37 2002").getTime()) / 1000)},
new Object[] {"Sun Nov 03 08:49:37 2002", Duration.ofSeconds(89628577 - TimeZone.getDefault().getOffset(new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US).parse("Sun Nov 03 08:49:37 2002").getTime()) / 1000)},
new Object[] {"Sun Nov 3 08:49:37 2002", Duration.ofSeconds(89628577 - TimeZone.getDefault()
.getOffset(
new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US)
.parse("Sun Nov 3 08:49:37 2002").getTime()) / 1000)},
new Object[] {"Sun Nov 03 08:49:37 2002", Duration.ofSeconds(89628577 - TimeZone.getDefault()
.getOffset(
new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US)
.parse("Sun Nov 03 08:49:37 2002").getTime()) / 1000)},
new Object[] {"Sun, 06 Nov 1994 08:49:37 EST", Duration.ZERO}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import jakarta.servlet.DispatcherType;
import jakarta.servlet.ReadListener;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletConnection;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletInputStream;
Expand Down Expand Up @@ -547,19 +546,13 @@ public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0) throws IOExceptio
}

@Override
public String getRequestId() {
LOG.log(Level.FINE, "getRequestId");
return null;
public String getRealPath(String path) {
return path;
}

@Override
public String getProtocolRequestId() {
LOG.log(Level.FINE, "getProtocolRequestId");
return null;
}

@Override
public ServletConnection getServletConnection() {
throw new UnsupportedOperationException();
public boolean isRequestedSessionIdFromUrl() {
LOG.log(Level.FINE, "isRequestedSessionIdFromUrl");
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -360,4 +362,22 @@ public void setContentLengthLong(long arg0) {
throw new UnsupportedOperationException();

}

@Override
public String encodeUrl(String url) {
return URLEncoder.encode(url, StandardCharsets.UTF_8);
}

@Override
public String encodeRedirectUrl(String url) {
return URLEncoder.encode(url, StandardCharsets.UTF_8);
}

@Override
public void setStatus(int sc, String sm) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "setStatus({0})", sc);
}
responseHeaders.put(WebSocketUtils.SC_KEY, Integer.toString(sc));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import jakarta.servlet.DispatcherType;
import jakarta.servlet.ReadListener;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletConnection;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletInputStream;
Expand Down Expand Up @@ -572,17 +571,13 @@ public <T extends HttpUpgradeHandler> T upgrade(Class<T> arg0) throws IOExceptio
}

@Override
public String getRequestId() {
throw new UnsupportedOperationException();
public String getRealPath(String path) {
return path;
}

@Override
public String getProtocolRequestId() {
throw new UnsupportedOperationException();
}

@Override
public ServletConnection getServletConnection() {
throw new UnsupportedOperationException();
public boolean isRequestedSessionIdFromUrl() {
LOG.log(Level.FINE, "isRequestedSessionIdFromUrl");
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -364,4 +366,22 @@ public void setContentLengthLong(long arg0) {
throw new UnsupportedOperationException();

}

@Override
public String encodeUrl(String url) {
return URLEncoder.encode(url, StandardCharsets.UTF_8);
}

@Override
public String encodeRedirectUrl(String url) {
return URLEncoder.encode(url, StandardCharsets.UTF_8);
}

@Override
public void setStatus(int sc, String sm) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "setStatus({0})", sc);
}
responseHeaders.put(WebSocketUtils.SC_KEY, Integer.toString(sc));
}
}

0 comments on commit cd259c4

Please sign in to comment.