use of org.glassfish.grizzly.http.server.Request in project Payara by payara.
the class JerseyContainerCommandService method getJerseyContainer.
private JerseyContainer getJerseyContainer(ResourceConfig rc) {
AdminJerseyServiceIteratorProvider iteratorProvider = new AdminJerseyServiceIteratorProvider();
try {
ServiceFinder.setIteratorProvider(iteratorProvider);
final HttpHandler httpHandler = ContainerFactory.createContainer(HttpHandler.class, rc);
return new JerseyContainer() {
@Override
public void service(Request request, Response response) throws Exception {
httpHandler.service(request, response);
}
};
} finally {
iteratorProvider.disable();
}
}
use of org.glassfish.grizzly.http.server.Request in project edammap by edamontology.
the class Resource method checkEdam.
@Path("edam")
@POST
@Produces(MediaType.TEXT_PLAIN)
public Response checkEdam(String requestString, @Context Request request) {
try {
logger.info("POST /edam {} from {}", requestString, request.getRemoteAddr());
Response response = Response.ok(QueryLoader.fromServerEdam(requestString, Server.concepts).entrySet().stream().map(c -> c.getKey() + " : " + c.getValue().getLabel()).collect(Collectors.joining("\n"))).build();
logger.info("POSTED /edam {}", response.getEntity());
return response;
} catch (IllegalArgumentException e) {
logger.error("Exception!", e);
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (Throwable e) {
logger.error("Exception!", e);
throw e;
}
}
use of org.glassfish.grizzly.http.server.Request in project edammap by edamontology.
the class Resource method patch.
/* TODO JSON
// curl -H "Content-Type: application/json" -X POST -d '{"threads":2,"reportPaginationSize":"7","mapperArgs":{"algorithmArgs":{"compoundWords":2}}}' http://localhost:8080/api
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String json(JsonObject json) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, JsonValue> entry : json.entrySet()) {
if (entry.getValue().getValueType() == JsonValue.ValueType.STRING || entry.getValue().getValueType() == JsonValue.ValueType.NUMBER) {
sb.append(entry.getKey()).append(" --> ").append(entry.getValue().toString()).append("\n");
}
}
return sb.toString();
}
*/
private Response patch(String requestString, Request request, String resource, Class<?> clazz, boolean doc, int max) {
try {
logger.info("PATCH {} {} from {}", resource, requestString, request.getRemoteAddr());
// TODO get actual args from form
FetcherArgs fetcherArgs = new FetcherArgs();
fetcherArgs.setPrivateArgs(Server.args.getFetcherPrivateArgs());
Response response = Response.ok(Server.processor.getDatabaseEntries(QueryLoader.fromServerEntry(requestString, clazz, max), fetcherArgs, clazz, doc).stream().map(p -> p.toStringId() + " : " + p.getStatusString(fetcherArgs).toUpperCase(Locale.ROOT)).collect(Collectors.joining("\n"))).build();
logger.info("PATCHED {} {}", resource, response.getEntity());
return response;
} catch (IllegalArgumentException e) {
logger.error("Exception!", e);
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (Throwable e) {
logger.error("Exception!", e);
throw e;
}
}
use of org.glassfish.grizzly.http.server.Request in project Payara by payara.
the class GrizzlyConfigTest method backendConfig.
@Test
public void backendConfig() throws IOException, InstantiationException {
GrizzlyConfig grizzlyConfig = null;
try {
grizzlyConfig = new GrizzlyConfig("grizzly-backend-config.xml");
grizzlyConfig.setupNetwork();
for (GrizzlyListener listener : grizzlyConfig.getListeners()) {
setHttpHandler((GenericGrizzlyListener) listener, new HttpHandler() {
@Override
public void service(Request request, Response response) throws Exception {
response.getWriter().write(request.getScheme());
final String remoteUser = request.getRemoteUser();
if (remoteUser != null) {
response.getWriter().write(request.getRemoteUser());
}
}
});
}
final String content = getContent(new URL("http://localhost:38082").openConnection());
final String content2 = getContent(new URL("http://localhost:38083").openConnection());
final URLConnection c3 = new URL("http://localhost:38084").openConnection();
c3.addRequestProperty("my-scheme", "https");
final String content3 = getContent(c3);
final URLConnection c4 = new URL("http://localhost:38085").openConnection();
c4.addRequestProperty("my-remote-user", "glassfish");
final String content4 = getContent(c4);
Assert.assertEquals("http", content);
Assert.assertEquals("https", content2);
Assert.assertEquals("https", content3);
Assert.assertEquals("httpglassfish", content4);
} finally {
if (grizzlyConfig != null) {
grizzlyConfig.shutdown();
}
}
}
use of org.glassfish.grizzly.http.server.Request in project Payara by payara.
the class SessionsResource method create.
/**
* Get a new session with GlassFish Rest service
* If a request lands here when authentication has been turned on => it has been authenticated.
* @return a new session with GlassFish Rest service
*/
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response create(HashMap<String, String> data) {
if (data == null) {
data = new HashMap<String, String>();
}
final RestConfig restConfig = ResourceUtil.getRestConfig(locatorBridge.getRemoteLocator());
Response.ResponseBuilder responseBuilder = Response.status(UNAUTHORIZED);
RestActionReporter ar = new RestActionReporter();
Request grizzlyRequest = request.get();
// If the call flow reached here, the request has been authenticated by logic in RestAdapater
// probably with an admin username and password. The remoteHostName value
// in the data object is the actual remote host of the end-user who is
// using the console (or, conceivably, some other client). We need to
// authenticate here once again with that supplied remoteHostName to
// make sure we enforce remote access rules correctly.
String hostName = data.get("remoteHostName");
boolean isAuthorized = false;
boolean responseErrorStatusSet = false;
Subject subject = null;
try {
subject = ResourceUtil.authenticateViaAdminRealm(locatorBridge.getRemoteLocator(), grizzlyRequest, hostName);
isAuthorized = ResourceUtil.isAuthorized(locatorBridge.getRemoteLocator(), subject, "domain/rest-sessions/rest-session", "create");
} catch (RemoteAdminAccessException e) {
responseBuilder.status(FORBIDDEN);
responseErrorStatusSet = true;
} catch (Exception e) {
ar.setMessage("Error while authenticating " + e);
}
if (isAuthorized) {
responseBuilder.status(OK);
// Check to see if the username has been set (anonymous user case)
String username = (String) grizzlyRequest.getAttribute("restUser");
if (username != null) {
ar.getExtraProperties().put("username", username);
}
ar.getExtraProperties().put("token", sessionManager.createSession(grizzlyRequest.getRemoteAddr(), subject, chooseTimeout(restConfig)));
} else {
if (!responseErrorStatusSet) {
responseBuilder.status(UNAUTHORIZED);
}
}
return responseBuilder.entity(new ActionReportResult(ar)).build();
}
Aggregations