Skip to content

Commit

Permalink
Minor change:fix checkstyle error
Browse files Browse the repository at this point in the history
  • Loading branch information
jimma committed Nov 22, 2018
1 parent 19dd490 commit f3f189e
Show file tree
Hide file tree
Showing 30 changed files with 273 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/
public interface EmbeddedJaxrsServer
{
final int DEFAULT_PORT = 8080;
int DEFAULT_PORT = 8080;

void setRootResourcePath(String rootResourcePath);

void start();
Expand All @@ -24,21 +25,23 @@ public interface EmbeddedJaxrsServer
void setDeployment(ResteasyDeployment deployment);

void setSecurityDomain(SecurityDomain sc);

void setSSLContext(SSLContext sslContext);

void setProtocol(String protocol);

void setSslParameters(SSLParameters sslParameters);

void setPort(int port);

void setHost(String host);

default void setConfiguration(JAXRS.Configuration configuration) {

default void setConfiguration(JAXRS.Configuration configuration)
{
}

default int scanPort() {

default int scanPort()
{
return PortProvider.getFreePort();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jboss.resteasy.plugins.server.embedded;

import java.io.IOException;
import java.net.ServerSocket;

public class PortProvider
{
public static int portNumber = 8989;

public static synchronized int getFreePort()
{
int port = -1;
while (port == -1)
{
int pn = portNumber++;
try
{
ServerSocket sock = new ServerSocket(pn);
sock.close();
port = pn;
portNumber = pn;
}
catch (IOException ex)
{
//
}
}
return port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@MessageBundle(projectCode = "RESTEASY")
public interface Messages
{
public Messages MESSAGES = org.jboss.logging.Messages.getBundle(Messages.class);
Messages MESSAGES = org.jboss.logging.Messages.getBundle(Messages.class);

int BASE = 3000;

Expand Down Expand Up @@ -845,7 +845,7 @@ public interface Messages

@Message(id = BASE_EMBEDEDSERVER + 10, value = "Error parsing request")
String errorParsingRequest();

@Message(id = BASE_EMBEDEDSERVER + 15, value = "WTF!")
String wtf();
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public abstract <T> MessageBodyWriter<T> getClientMessageBodyWriter(Class<T> typ
public abstract boolean isReactive(Class<?> clazz);

public abstract ResourceBuilder getResourceBuilder();

public abstract EmbeddedJaxrsServer getJaxrsServer();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Builder property(String name, Object value)
properties.put(name, value);
return this;
}

private class ServerConfiguration implements javax.ws.rs.JAXRS.Configuration {
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -107,14 +106,12 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.BiFunction;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -265,7 +262,6 @@ public int compareTo(SortedKey<T> tMessageBodyKey)
protected Set<Feature> enabledFeatures;
protected Set<Class<?>> providerClasses;
protected Set<Object> providerInstances;


public ResteasyProviderFactoryImpl()
{
Expand Down Expand Up @@ -1658,6 +1654,7 @@ protected void processProviderContracts(Class provider, Integer priorityOverride
addResourceClassProcessor(provider, priority);
newContracts.put(ResourceClassProcessor.class, priority);
}

if (isA(provider, HeaderDelegate.class, contracts))
{
Type[] headerTypes = Types.getActualTypeArgumentsOfAnInterface(provider, HeaderDelegate.class);
Expand All @@ -1670,6 +1667,8 @@ protected void processProviderContracts(Class provider, Integer priorityOverride
Class<?> headerClass = Types.getRawType(headerTypes[0]);
HeaderDelegate<?> delegate = createProviderInstance((Class<? extends HeaderDelegate>) provider);
addHeaderDelegate(headerClass, delegate);
}
}
if (isA(provider, EmbeddedJaxrsServer.class, contracts))
{
try
Expand Down Expand Up @@ -2670,16 +2669,17 @@ public ResourceBuilder getResourceBuilder()
{
return resourceBuilder;
}

public EmbeddedJaxrsServer getJaxrsServer() {

public EmbeddedJaxrsServer getJaxrsServer()
{
return jaxrsServer;
}

public <T> T getContextData(Class<T> type)
{
return ResteasyContext.getContextData(type);
}
}

public CompletionStage<Instance> bootstrap(Application application, JAXRS.Configuration configuration)
{
RegisterBuiltin.register(this);
Expand All @@ -2689,7 +2689,7 @@ public CompletionStage<Instance> bootstrap(Application application, JAXRS.Config
@Override
public Instance get()
{

if (jaxrsServer == null)
{
jaxrsServer = new SunHttpJaxrsServer();
Expand All @@ -2716,7 +2716,7 @@ public Instance get()
jaxrsServer.setSSLContext(configuration.sslContext());
}
jaxrsServer.setProtocol(configuration.protocol());

jaxrsServer.setConfiguration(configuration);
ResteasyDeployment deployment = new ResteasyDeploymentImpl();
deployment.setApplication(application);
jaxrsServer.setDeployment(deployment);
Expand All @@ -2732,22 +2732,24 @@ public javax.ws.rs.JAXRS.Configuration configuration()
@Override
public CompletionStage<StopResult> stop()
{
return CompletableFuture.supplyAsync(new Supplier<StopResult>() {
return CompletableFuture.supplyAsync(new Supplier<StopResult>()
{
@Override
public StopResult get()
{
jaxrsServer.stop();
return new StopResult() {
return new StopResult()
{

@Override
public <T> T unwrap(Class<T> nativeClass)
{
return null;
}
};

};
}

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public CompletionStage<?> broadcast(OutboundSseEvent event)
* @param cascading Boolean value that controls closing of registered {@link SseEventSink}
* instances.
*/
public void close(boolean cascading) {
//TODO: implement this
public void close(boolean cascading)
{
// TODO: implement this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BasicAuthFilter extends Filter
{
protected SecurityDomain domain;

public BasicAuthFilter(SecurityDomain domain)
public BasicAuthFilter(final SecurityDomain domain)
{
this.domain = domain;
}
Expand All @@ -40,7 +40,8 @@ public void doFilter(HttpExchange exchange, Chain chain) throws IOException
String cookie = auth.substring(6);
cookie = new String(Base64.decodeBase64(cookie.getBytes()));
String[] split = cookie.split(":");
//System.out.println("Authenticating user: " + split[0] + " passwd: " + split[1]);
// System.out.println("Authenticating user: " + split[0] +
// " passwd: " + split[1]);
Principal user = null;
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
package org.jboss.resteasy.plugins.server.sun.http;

import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpServer;

import org.jboss.resteasy.core.ResteasyDeploymentImpl;
import org.jboss.resteasy.plugins.server.embedded.SecurityDomain;
import org.jboss.resteasy.spi.ResteasyConfiguration;
import org.jboss.resteasy.spi.ResteasyDeployment;

import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpServer;

/**
* Helper class to create a ResteasyDeployment and bind it to an HttpContext of an HttpServer. Setting the SecurityDomain
* will turn on Basic Authentication. Right now, only BasicAuthentication is supported.
* Helper class to create a ResteasyDeployment and bind it to an HttpContext of
* an HttpServer. Setting the SecurityDomain will turn on Basic Authentication.
* Right now, only BasicAuthentication is supported.
*
* HttpContext.getAttributes() data is available within Providers and Resources by injecting a ResteasyConfiguration interface
* HttpContext.getAttributes() data is available within Providers and Resources
* by injecting a ResteasyConfiguration interface
*
* <pre>
HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 10);
contextBuilder = new HttpContextBuilder();
contextBuilder.getDeployment().getActualResourceClasses().add(SimpleResource.class);
HttpContext context = contextBuilder.bind(httpServer);
context.getAttributes().put("some.config.info", "42");
httpServer.start();
contextBuilder.cleanup();
httpServer.stop(0);
* HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 10);
* contextBuilder = new HttpContextBuilder();
* contextBuilder.getDeployment().getActualResourceClasses().add(SimpleResource.class);
* HttpContext context = contextBuilder.bind(httpServer);
* context.getAttributes().put(&quot;some.config.info&quot;, &quot;42&quot;);
* httpServer.start();
* contextBuilder.cleanup();
* httpServer.stop(0);
* </pre>
* Create your HttpServer the way you want then use the org.jboss.resteasy.plugins.server.sun.http.HttpContextBuilder to initialize Resteasy
* and bind it to an HttpContext. The HttpContext attributes are available by injecting in a org.jboss.resteasy.spi.ResteasyConfiguration
* Create your HttpServer the way you want then use the
* org.jboss.resteasy.plugins.server.sun.http.HttpContextBuilder to initialize
* Resteasy and bind it to an HttpContext. The HttpContext attributes are
* available by injecting in a org.jboss.resteasy.spi.ResteasyConfiguration
* interface using @Context within your provider and resource classes.
*
*
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>* @version $Revision: 1 $
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>* @version
* $Revision: 1 $
*/
public class HttpContextBuilder
{
protected ResteasyDeployment deployment = new ResteasyDeploymentImpl();

protected String path = "/";

protected ResteasyHttpHandler handler;

protected SecurityDomain securityDomain;

protected HttpContext boundContext;

public ResteasyDeployment getDeployment()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.jboss.resteasy.plugins.server.sun.http;

import com.sun.net.httpserver.HttpContext;
import java.util.Set;

import org.jboss.resteasy.spi.ResteasyConfiguration;

import java.util.Set;
import com.sun.net.httpserver.HttpContext;

/**
* ResteasyConfiguration adapter for HttpContext attributes
Expand All @@ -15,7 +16,7 @@ public class HttpContextResteasyConfiguration implements ResteasyConfiguration
{
protected HttpContext context;

public HttpContextResteasyConfiguration(HttpContext context)
public HttpContextResteasyConfiguration(final HttpContext context)
{
this.context = context;
}
Expand All @@ -24,7 +25,8 @@ public HttpContextResteasyConfiguration(HttpContext context)
public String getParameter(String name)
{
Object val = context.getAttributes().get(name);
if (val == null) return null;
if (val == null)
return null;
return val.toString();
}

Expand Down
Loading

0 comments on commit f3f189e

Please sign in to comment.