use of org.glassfish.hk2.api.Context in project Payara by payara.
the class Iso2Servlet method doGet.
/**
* Just prints out the value of the ServiceLocator getName
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
ServletContext context = getServletContext();
ServiceLocator locator = (ServiceLocator) context.getAttribute(HABITAT_ATTRIBUTE);
String reply1 = SERVLET_CONTEXT_LOCATOR + ((locator == null) ? "null" : locator.getName());
String jndiAppLocatorName = getJndiAppLocatorName();
String reply2 = JNDI_APP_LOCATOR + ((jndiAppLocatorName == null) ? "null" : jndiAppLocatorName);
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Iso2 WebApp</title>");
writer.println("</head>");
writer.println("<body>");
writer.println(reply1);
writer.println(reply2);
writer.println("</body>");
writer.println("</html>");
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class GetProtocol method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// Check that a configuration can be found
if (targetUtil.getConfig(target) == null) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
return;
}
Config config = targetUtil.getConfig(target);
// Check that a matching listener can be found
List<Protocol> protocols = config.getNetworkConfig().getProtocols().getProtocol();
Optional<Protocol> optionalProtocol = protocols.stream().filter(protocol -> protocol.getName().equals(protocolName)).findFirst();
if (!optionalProtocol.isPresent()) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_PROTOCOL), protocolName, target));
return;
}
Protocol protocol = optionalProtocol.get();
// Write message body
report.appendMessage(String.format("Name: %s\n", protocol.getName()));
// Write HTTP config options
report.appendMessage("\nHTTP:\n");
report.appendMessage(String.format("Server Name: %s\n", protocol.getHttp().getServerName()));
report.appendMessage(String.format("Max Connections: %s seconds\n", protocol.getHttp().getMaxConnections()));
report.appendMessage(String.format("Default Virtual Server: %s\n", protocol.getHttp().getDefaultVirtualServer()));
report.appendMessage(String.format("Server Header: %s\n", protocol.getHttp().getServerHeader()));
report.appendMessage(String.format("X-Powered-By: %s\n", protocol.getHttp().getXpoweredBy()));
if (verbose) {
report.appendMessage(String.format("Request Timeout: %s seconds\n", protocol.getHttp().getRequestTimeoutSeconds()));
report.appendMessage(String.format("Timeout: %s seconds\n", protocol.getHttp().getTimeoutSeconds()));
report.appendMessage(String.format("DNS Lookup Enabled: %s\n", protocol.getHttp().getDnsLookupEnabled()));
report.appendMessage(String.format("X Frame Options: %s\n", protocol.getHttp().getXframeOptions()));
}
// Write HTTP/2 config options
report.appendMessage("\nHTTP/2:\n");
report.appendMessage(String.format("Enabled: %s\n", protocol.getHttp().isHttp2Enabled()));
if (protocol.getHttp().isHttp2Enabled()) {
report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().isHttp2PushEnabled()));
report.appendMessage(String.format("Cipher Check: %s\n", !protocol.getHttp().isHttp2DisableCipherCheck()));
if (verbose) {
report.appendMessage(String.format("Max Concurrent Streams: %s\n", protocol.getHttp().getHttp2MaxConcurrentStreams()));
report.appendMessage(String.format("Initial Window Size: %s bytes\n", protocol.getHttp().getHttp2InitialWindowSizeInBytes()));
report.appendMessage(String.format("Max Frame Payload Size: %s bytes\n", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes()));
report.appendMessage(String.format("Max Header List Size: %s bytes\n", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes()));
report.appendMessage(String.format("Streams High Water Mark: %s\n", protocol.getHttp().getHttp2StreamsHighWaterMark()));
report.appendMessage(String.format("Clean Percentage: %s\n", protocol.getHttp().getHttp2CleanPercentage()));
report.appendMessage(String.format("Clean Frequency Check: %s\n", protocol.getHttp().getHttp2CleanFrequencyCheck()));
}
}
// Write the variables as properties
Properties properties = new Properties();
properties.put("name", protocol.getName());
properties.put("serverName", protocol.getHttp().getServerName() == null ? "null" : protocol.getHttp().getServerName());
properties.put("maxConnections", protocol.getHttp().getMaxConnections());
properties.put("defaultVirtualServer", protocol.getHttp().getDefaultVirtualServer());
properties.put("serverHeader", protocol.getHttp().getServerHeader());
properties.put("xPoweredBy", protocol.getHttp().getXpoweredBy());
properties.put("requestTimeoutSeconds", protocol.getHttp().getRequestTimeoutSeconds());
properties.put("timeoutSeconds", protocol.getHttp().getTimeoutSeconds());
properties.put("dnsLookupEnabled", protocol.getHttp().getDnsLookupEnabled());
properties.put("xFrameOptions", protocol.getHttp().getXframeOptions());
properties.put("http2Enabled", protocol.getHttp().isHttp2Enabled());
properties.put("http2MaxConcurrentStreams", protocol.getHttp().getHttp2MaxConcurrentStreams());
properties.put("http2InitialWindowSizeInBytes", protocol.getHttp().getHttp2InitialWindowSizeInBytes());
properties.put("http2MaxFramePayloadSizeInBytes", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes());
properties.put("http2MaxHeaderListSizeInBytes", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes());
properties.put("http2StreamsHighWaterMark", protocol.getHttp().getHttp2StreamsHighWaterMark());
properties.put("http2CleanPercentage", protocol.getHttp().getHttp2CleanPercentage());
properties.put("http2CleanFrequencyCheck", protocol.getHttp().getHttp2CleanFrequencyCheck());
properties.put("http2DisableCipherCheck", protocol.getHttp().isHttp2DisableCipherCheck());
properties.put("http2PushEnabled", protocol.getHttp().isHttp2PushEnabled());
report.setExtraProperties(properties);
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class WeldUtils method getTypes.
private static Types getTypes(DeploymentContext context) {
String metadataKey = Types.class.getName();
Types types = (Types) context.getTransientAppMetadata().get(metadataKey);
while (types == null) {
context = ((ExtendedDeploymentContext) context).getParentContext();
if (context != null) {
types = (Types) context.getTransientAppMetadata().get(metadataKey);
} else {
break;
}
}
return types;
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class WeldUtils method hasCDIEnablingAnnotations.
/**
* Determine whether there are any beans annotated with annotations that should enable CDI
* processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
* @param paths The paths to check for annotated beans
*
* @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
*/
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
List<String> result = new ArrayList<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at) && type.wasDefinedIn(paths)) {
if (!result.contains(at.getName())) {
result.add(at.getName());
}
}
}
}
}
}
return !(result.isEmpty());
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class WeldUtils method getCDIAnnotatedClassNames.
/**
* Get the names of any classes that are annotated with bean-defining annotations, which should
* enable CDI processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
*
* @return A collection of class names; The collection could be empty if none are found.
*/
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
Set<String> result = new HashSet<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at)) {
if (!result.contains(at.getName())) {
result.add(type.getName());
}
}
}
}
}
}
return result;
}
Aggregations