Determine Glassfish HTTP port number from java code without request - java

I'm using Glassfish 3.1.2.2. Is it possible to determine http port number (http-listener-1) from java (EJB) code? I don't have any connections or requests, so reading ServletRequest is not an option.

Yes, this is possible. You can use the Glassfish Admin REST API to retrieve nearly every property of the server.
For the properties of the http-listener-1 use the following url: http://localhost:4848/management/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1
A normal GET request will give you a HTML response, set the Accept header to application/json to retrieve the response in JSON.
In your EJB you just have to issue an HTTP request to the url from above with the right header. Here is an example:
String url = "http://localhost:4848/management/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty("Accept", "application/json");
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
This will give you a result similar to this:
{
"message": "",
"command": "http-listener-1",
"exit_code": "SUCCESS",
"extraProperties": {
"commands": [
{
"path": "create-ssl",
"method": "POST",
"command": "create-ssl"
}
],
"methods": [
{
"name": "GET"
},
{},
{
"messageParameters": {
"address": {
"defaultValue": "0.0.0.0",
"optional": "true",
"type": "string",
"key": "false"
},
"enabled": {
"defaultValue": "true",
"optional": "true",
"type": "boolean",
"key": "false"
},
"jkConfigurationFile": {
"defaultValue": "${com.sun.aas.instanceRoot}/config/glassfish-jk.properties",
"optional": "true",
"type": "string",
"key": "false"
},
"jkEnabled": {
"defaultValue": "false",
"optional": "true",
"type": "boolean",
"key": "false"
},
"name": {
"optional": "false",
"type": "string",
"key": "true"
},
"port": {
"optional": "false",
"type": "int",
"key": "false"
},
"protocol": {
"optional": "false",
"type": "string",
"key": "false"
},
"threadPool": {
"optional": "true",
"type": "string",
"key": "false"
},
"transport": {
"optional": "false",
"type": "string",
"key": "false"
}
},
"name": "POST"
},
{
"messageParameters": {
"target": {
"acceptableValues": "",
"defaultValue": "server",
"optional": "true",
"type": "string"
}
},
"name": "DELETE"
}
],
"entity": {
"address": "0.0.0.0",
"enabled": "true",
"jkConfigurationFile": "${com.sun.aas.instanceRoot}/config/glassfish-jk.properties",
"jkEnabled": "false",
"name": "http-listener-1",
"port": "8080",
"protocol": "http-listener-1",
"threadPool": "http-thread-pool",
"transport": "tcp"
},
"childResources": {
"find-http-protocol": "http://localhost:4848/management/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1/find-http-protocol",
"property": "http://localhost:4848/management/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1/property"
}
}
}
As you can see the result contains the port (8080 in this case).
You can either parse the value manually from the response string or use some JSON library to convert the response to an JSON object from which you can easily retrieve the property.
This procedure should work if your Glassfish Admin interface is unprotected, if you have enabled secure administration you may have to send authorization parameters with your HTTP request.
See also:
Oracle GlassFish 3.1 Administration Guide - Using REST Interfaces to Administer GlassFish Server

Related

How to parse a JSON with SCIM Schemas in java

I have the following json which get from endpoint,
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:response",
"urn:scim:schemas:extension:customattrs:2.0:User"
],
"meta": {
"resourceType": "User",
"created": "2011-08-01T18:29:49.793Z",
"lastModified": "2011-08-01T18:29:49.793Z",
"version": "W/\"f250dd84f0671c3\""
},
"userName": "bjensen",
"phoneNumbers": [
{
"value": "555-555-8377",
"type": "work"
}
],
"emails": [
{
"value": "bjensen#example.com",
"type": "work",
"primary": true
}
],
"urn:scim:schemas:extension:customattrs:2.0:User": {
"userName": "bjensen",
"address": ""
}
}
please suggest me to parse the json along with schemas "urn:scim:schemas:extension:customattrs:2.0:User" into java object

Getting all elements from JSON API response

Getting an API response as below and wanted to get the names for all the fields using restassured.
{
"expand": "projects",
"projects": [
{
"expand": "issuetypes",
"issuetypes": [
{
"subtask": false,
"expand": "fields",
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10100": {
"required": false,
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 10100
},
"name": "Epic Link",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10102": {
"required": true,
"schema": {
"type": "string",
"custom": "com.pyxis.greenhopper.jira:gh-epic-label",
"customId": 10102
},
"name": "Epic Name",
"hasDefaultValue": false,
"operations": [
"set"
]
},
}
}
]
}
]
}
I tried to get the names using respStg1.jsonPath().getList("projects.issuetypes.fields.[*].name"), but getting gpath error. Please help if there is any way to get the name of all the fields under projects.issuetypes.fields.
Try with this = [*].[*].[*].[*].name
This should work
For future you can use this link to evaluate jsonPath : http://jsonpath.com/
and for jsonPath syntax and wildcards refer this link : https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html

Pojo/Entity corresponding to json response from Azure REST API

I have written a java class which hits the Azure REST API's and gets me the json response. for example below-
{
"value": [
{
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"id": "/subscriptions/cc60365e-3193-xxxx-b0f6-xxxxxxx/resourceGroups/WebServer-ubuntu/providers/Microsoft.Storage/storageAccounts/webserverubuntudiagxxx",
"name": "webserverubuntudiag4xx",
"type": "Microsoft.Storage/storageAccounts",
"location": "eastus",
"tags": {},
"properties": {
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"trustedDirectories": [
"50228742-xxx-4cd2-xxx-3e50b7a62xx1"
],
"supportsHttpsTrafficOnly": false,
"encryption": {
"services": {
"file": {
"enabled": true,
"lastEnabledTime": "2018-03-26T15:02:26.8078850Z"
},
"blob": {
"enabled": true,
"lastEnabledTime": "2018-03-26T15:02:26.8078850Z"
}
},
"keySource": "Microsoft.Storage"
},
"provisioningState": "Succeeded",
"creationTime": "2018-03-26T15:02:26.6359768Z",
"primaryEndpoints": {
"blob": "https://webserverubuntudiagxx.blob.core.windows.net/",
"queue": "https://webserverubuntudiag4xx.queue.core.windows.net/",
"table": "https://webserverubuntudiagxx.table.core.windows.net/",
"file": "https://webserverubuntudiag4xx.file.core.windows.net/"
},
"primaryLocation": "eastus",
"statusOfPrimary": "available"
}
}
]
}
My questions is: Are there any model/pojo/bean already available to map this json to java object ?
I need to map the data from above json into the java beans/pojos to display into jsp pages, do I need to separately create custom pojos or there are any already in Azure libraries/sdk ? any suggestions?

How to execute mail Task process on camunda cockpit?

we have workflow that has service task attached to the box , Below template is applied to bmpn:serviceTask, Now when we deploy workflow to camunda using https://engine-rest/deployment/create , we are able to run the process but we see this error on incident tab,we are using bpmn-js node library for modeler and create workflows, where we define camunda:class, as you can see error below, Any idea how to resolve this camunda class issue ?
we are just trying to send email notification when process starts ?
New to camunda stuff any help will be appreciated.
template.js
{
"name": "Mail_Task_2",
"id": "com.camunda.example.MailTask_2",
"createdBy": "sh529u",
"users": [],
"groups": [],
"properties": [
{
"binding": {
"name": "camunda:class",
"type": "property"
},
"editable": false,
"value": "com.mycompany.MailTaskImpl",
"type": "String",
"label": "Implementation Type"
},
{
"label": "Sender",
"type": "String",
"binding": {
"type": "camunda:inputParameter",
"name": "sender"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "Receivers",
"type": "String",
"binding": {
"type": "camunda:inputParameter",
"name": "receivers"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "Template",
"description": "By the way, you can use freemarker templates here",
"value": "Hello ${firstName}!",
"type": "Text",
"binding": {
"type": "camunda:inputParameter",
"name": "messageBody",
"scriptFormat": "freemarker"
},
"constraints": {
"notEmpty": true
}
},
{
"label": "Result Status",
"description": "The process variable to which to assign the send result to",
"type": "String",
"value": "mailSendResult",
"binding": {
"type": "camunda:outputParameter",
"source": "${ resultStatus }"
}
},
{
"label": "Send Async?",
"type": "Boolean",
"value": true,
"binding": {
"type": "property",
"name": "camunda:asyncBefore"
}
}
],
"appliesTo": [
"bpmn:ServiceTask"
]
}
ERROR
org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class 'com.mycompany.MailTaskImpl': ENGINE-09017 Cannot load class 'com.mycompany.MailTaskImpl': com.mycompany.MailTaskImpl
at org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:78)

generating POJOs from JSON Schema for non-object types

I am trying to generate POJOs from the JSON Schema of XMBC.
I do this with jsonschema2pojo.
However, nothing gets generated. It doesn't even bring me an error.
This is a reduced sample json schema I am trying to generate from:
{
"description": "JSON-RPC API of XBMC",
"id": "http://xbmc.org/jsonrpc/ServiceDescription.json",
"methods": {
"Addons.ExecuteAddon": {
"description": "Executes the given addon with the given parameters (if possible)",
"params": [
{
"name": "addonid",
"required": true,
"type": "string"
},
{
"default": "",
"name": "params",
"type": [
{
"additionalProperties": {
"default": "",
"type": "string"
},
"type": "object"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "URL path (must start with / or ?",
"type": "string"
}
]
},
{
"default": false,
"name": "wait",
"type": "boolean"
}
],
"returns": {
"type": "string"
},
"type": "method"
}
},
"notifications": {
"Application.OnVolumeChanged": {
"description": "The volume of the application has changed.",
"params": [
{
"name": "sender",
"required": true,
"type": "string"
},
{
"name": "data",
"properties": {
"muted": {
"required": true,
"type": "boolean"
},
"volume": {
"maximum": 100,
"minimum": 0,
"required": true,
"type": "integer"
}
},
"required": true,
"type": "object"
}
],
"returns": null,
"type": "notification"
}
},
"types": {
"Addon.Content": {
"default": "unknown",
"enums": [
"unknown",
"video",
"audio",
"image",
"executable"
],
"id": "Addon.Content",
"type": "string"
}
},
"version": "6.14.3"
}
I must admin that my knowledge of JSON is very terse, maybe it is just a simple fault of mine. But can anyone help me how I can generate Java objects from such a JSON Schema?
The JSON Schema doesn't support method. JSON schema defines json data structure, it would not be used to define your methods. Most important attribute in JSON schema is properties.
It's good to generate POJO data models from a JSON schema, but not business logic. You can learn the JSON schema from those examples.

Categories