I am trying to get the projectid of my project from JIRA using gradle script.I wrote few methods which basically try to get the JSON output and fetch the project id of that particular project but now i am not able to get the projectId from that. Below is the methods which i am using to get the JSON result. it's working fine but not giving me the exact JSON output.My project Name is TESTPROJECT and id is 12345.I am looking when you have fresh project and need to get the projectid of that project using JIRA request method.I pasted the below JSON output which doesn't have {} "" so not exactly JSON output.Can someone tell me how could I get the project id with below way or am I doing something wrong?
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
classpath 'org.apache.httpcomponents:httpmime:4.2.1'
classpath 'commons-io:commons-io:2.4'
}
}
ext {
jiraURL = "https://test.test.com/"
jiraProject = 'TESTPROJECT'
jiraUser = "test"
jiraPassword = "*****"
}
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
def String authHeader() {
String userAndPassword = "${jiraUser}:${jiraPassword}"
String authHeader = 'Basic ' + userAndPassword.getBytes().encodeBase64().toString()
return authHeader
}
/*
* Get the Jira project details
*/
def Map getJiraprojectDetails(String projectName) {
Map json = jiraProjectRequest(
"project/${projectName}",
groovyx.net.http.Method.GET,
null,
'Get JIRA version failure - getJiraprojectDetails()'
)
existingProjectId = json.key.id[0]
if (existingProjectId == null || existingProjectId == 0)
throw new GradleException("Project was not found in JIRA")
return existingProjectId
}
def Map jiraProjectRequest(String path, groovyx.net.http.Method method, Map jsonBody, String failMessage) {
Map jsonResult = null
def jira = new HTTPBuilder("${jiraURL}/rest/api/2/${path}", ContentType.JSON)
jira.request(method) { req ->
headers.'Authorization' = authHeader()
requestContentType = ContentType.JSON
if (body != null)
body = jsonBody
response.success = { resp, json ->
println "$json"
jsonResult = json
println "$jsonResult"
}
response.failure = { resp ->
String message = "${failMessage}: ${resp.status} - ${resp.statusLine.reasonPhrase}"
throw new GradleException(message)
}
}
return jsonResult
}
def void makeNewversion() {
def projectName = "${jiraProject}"
println "$projectName"
projectid = getJiraprojectDetails(projectName)
}
task createJiraVersion() {
doLast {
if (project.hasProperty('createVersion')) {
makeNewversion()
}
}
}
JSON Output
[jira] Response data: -----
[jira] [expand:description,lead,url,projectKeys, self:https://test.test1.com/rest/api/2/project/48352, id:48352, key:TESTPROJECT, description:, lead:[self:https://test.test1.com/rest/api/2/user?username=C56765, key:C56765, name:C56765, avatarUrls:[48x48:https://test.test1.com/secure/useravatar?ownerId=C56765&avatarId=42213, 24x24:https://test.test1.com/secure/useravatar?size=small&ownerId=C56765&avatarId=42213, 16x16:https://test.test1.com/secure/useravatar?size=xsmall&ownerId=h156765&avatarId=42213, 32x32:https://test.test1.com/secure/useravatar?size=medium&ownerId=C56765&avatarId=42213], displayName:karry test, active:true], components:[], issueTypes:[[self:https://test.test1.com/rest/api/2/issuetype/1, id:1, description:A problem which impairs or prevents the functions or performance of the product or its related artifacts. It can be related to software, hardware or both., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31313&avatarType=issuetype, name:Defect, subtask:false, avatarId:31313], [self:https://test.test1.com/rest/api/2/issuetype/66, id:66, description:Created by JIRA Software - do not edit or delete. Issue type for a big user story that needs to be broken down., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31317&avatarType=issuetype, name:Epic, subtask:false, avatarId:31317], [self:https://test.test1.com/rest/api/2/issuetype/67, id:67, description:Created by JIRA Software - do not edit or delete. Issue type for a user story., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31325&avatarType=issuetype, name:Story, subtask:false, avatarId:31325], [self:https://test.test1.com/rest/api/2/issuetype/10600, id:10600, description:, iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31324&avatarType=issuetype, name:Initiative, subtask:false, avatarId:31324], [self:https://test.test1.com/rest/api/2/issuetype/2, id:2, description:A new feature of the product., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31321&avatarType=issuetype, name:New Feature, subtask:false, avatarId:31321], [self:https://test.test1.com/rest/api/2/issuetype/4, id:4, description:An enhancement to an existing feature., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31320&avatarType=issuetype, name:Improvement, subtask:false, avatarId:31320], [self:https://test.test1.com/rest/api/2/issuetype/25, id:25, description:A formal request to change an existing, baselined project artifact. , iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31330&avatarType=issuetype, name:Change Request, subtask:false, avatarId:31330], [self:https://test.test1.com/rest/api/2/issuetype/3, id:3, description:A task that needs to be done., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31328&avatarType=issuetype, name:Task, subtask:false, avatarId:31328], [self:https://test.test1.com/rest/api/2/issuetype/26, id:26, description:A risk is an uncertain future event or condition, with a probability of occurrence, and a potential for loss., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31318&avatarType=issuetype, name:Risk, subtask:false, avatarId:31318], [self:https://test.test1.com/rest/api/2/issuetype/87, id:87, description:An impediment is something that makes it difficult to do or complete something in a project and thus requires action. It may be a project risks that has occurred and typically represents something upon which a decision and actions are needed. The decision may not necessarily change the scope, schedule or cost of the project but the lack of a decision would affect the schedule., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31318&avatarType=issuetype, name:Impediment, subtask:false, avatarId:31318], [self:https://test.test1.com/rest/api/2/issuetype/8, id:8, description:An item discussed in a meeting that requires further action or work., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31328&avatarType=issuetype, name:Action Item, subtask:false, avatarId:31328], [self:https://test.test1.com/rest/api/2/issuetype/83, id:83, description:, iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31314&avatarType=issuetype, name:Root Cause Analysis, subtask:false, avatarId:31314], [self:https://test.test1.com/rest/api/2/issuetype/58, id:58, description:Any issue, solution or improvement learned in a project that should be shared with other people and/or projects., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31324&avatarType=issuetype, name:Lesson Learned, subtask:false, avatarId:31324], [self:https://test.test1.com/rest/api/2/issuetype/39, id:39, description:A summary of a meeting including participants, decisions, and resulting actions., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=39910&avatarType=issuetype, name:Meeting Minutes, subtask:false, avatarId:39910], [self:https://test.test1.com/rest/api/2/issuetype/55, id:55, description:An item for managing a review consisting of one or more review findings., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31323&avatarType=issuetype, name:Review, subtask:false, avatarId:31323], [self:https://test.test1.com/rest/api/2/issuetype/43, id:43, description:Used to track and manage Process Compliance and Configuration Audits on a project., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=42820&avatarType=issuetype, name:Audit, subtask:false, avatarId:42820], [self:https://test.test1.com/rest/api/2/issuetype/63, id:63, description:Used for requesting the approval of a particular work product and collecting approval from multiple individuals., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31316&avatarType=issuetype, name:Approval Request, subtask:false, avatarId:31316], [self:https://test.test1.com/rest/api/2/issuetype/5, id:5, description:A task that needs to be done., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31328&avatarType=issuetype, name:Sub-Task, subtask:true, avatarId:31328], [self:https://test.test1.com/rest/api/2/issuetype/35, id:35, description:An item discussed in a meeting that requires further action or work., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31328&avatarType=issuetype, name:Action Item (Sub-Issue), subtask:true, avatarId:31328], [self:https://test.test1.com/rest/api/2/issuetype/56, id:56, description:A defect, question, suggestion or other issue resulting from the review of a document or other artifact. , iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31323&avatarType=issuetype, name:Review Finding, subtask:true, avatarId:31323], [self:https://test.test1.com/rest/api/2/issuetype/62, id:62, description:, iconUrl:https://test.test1.com/images/icons/issuetypes/documentation.png, name:Mitigation Plan, subtask:true], [self:https://test.test1.com/rest/api/2/issuetype/61, id:61, description:An issue (non-compliance, recommendation) found during an audit., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31323&avatarType=issuetype, name:Audit Finding, subtask:true, avatarId:31323], [self:https://test.test1.com/rest/api/2/issuetype/64, id:64, description:A sub-issue type used for capturing the approval (or disapproval) of an individual for a particular work product., iconUrl:https://test.test1.com/secure/viewavatar?size=xsmall&avatarId=31316&avatarType=issuetype, name:Approval, subtask:true, avatarId:31316]], assigneeType:PROJECT_LEAD, versions:[[self:https://test.test1.com/rest/api/2/version/98423, id:98423, name:TCD 1.2.3, archived:false, released:false, projectId:48352]], name:Test PAAS, roles:[CCB:https://test.test1.com/rest/api/2/project/48352/role/10020, L1 Support:https://test.test1.com/rest/api/2/project/48352/role/10050, Developers:https://test.test1.com/rest/api/2/project/48352/role/10001, Approvers:https://test.test1.com/rest/api/2/project/48352/role/10052, Administrators:https://test.test1.com/rest/api/2/project/48352/role/10002, Watcher:https://test.test1.com/rest/api/2/project/48352/role/10030, Bulkcloners:https://test.test1.com/rest/api/2/project/48352/role/10070, Testers:https://test.test1.com/rest/api/2/project/48352/role/10010, Users:https://test.test1.com/rest/api/2/project/48352/role/10000, L2 Support:https://test.test1.com/rest/api/2/project/48352/role/10051], avatarUrls:[48x48:https://test.test1.com/secure/projectavatar?avatarId=39413, 24x24:https://test.test1.com/secure/projectavatar?size=small&avatarId=39413, 16x16:https://test.test1.com/secure/projectavatar?size=xsmall&avatarId=39413, 32x32:https://test.test1.com/secure/projectavatar?size=medium&avatarId=39413], projectCategory:[self:https://test.test1.com/rest/api/2/projectCategory/18032, id:18032, name:Solutions, description:TO-12179], projectTypeKey:software]
Below is the code to get the project id
/*
* Get the Jira project ID for a project like 'ABC'
*/
def int getJiraProjectid(String jiraProject) {
int existingProjectId = 0
def json = [jiraprojectRequest()]
json.each {
existingProjectId = it."id".toInteger()
//println "$existingVersionId"
}
if (existingProjectId == 0)
throw new GradleException("Existing project ${jiraProject} was not found in JIRA")
return existingProjectId
}
def Map jiraprojectRequest() {
Map jsonResultList = null
def jira = new HTTPBuilder("${jiraURL}/rest/api/2/project/${jiraProject}", ContentType.JSON)
jira.request(groovyx.net.http.Method.GET) { req ->
headers.'Authorization' = authHeader()
response.success = { resp, json ->
project.getLogger().info('[jira] Response data: -----')
project.getLogger().info("[jira] $json")
project.getLogger().info('\n--------------------')
jsonResultList = json
}
response.failure = { resp ->
throw new GradleException("Get JIRA versions failure - jiraGetVersions(): ${resp.status} - ${resp.statusLine.reasonPhrase}")
}
}
return jsonResultList
}
ADDED 7/23.
Many views: Not even a "that's dumb" question in response. Can anyone at least tell me why such an embarrassingly trivial question seems to have no answer anywhere.
Q:
--- Have Wildfly 8 running on local machine localhost:9990.
--- Have a Java program that need's Wildfly's IntialContext.
--- Every reference says use: "Context ctx = new InitialContext(env);"
--- Yet a week of searching turns up no set of properties that returns one.
And no example of a java program that gets one.
Does no one ever do this? Really need help
Original Msg Below
I know many people have asked how to get an Initial context from Wildfly 8. But I have yet to find a simple answer with a simple example.
Therefore, I hope someone can tell my why this doesn’t work.
I start Wildfly with standalone-full.xml
The three sections below have
A - Code summary of my test Class whose only purpose is to secure an Initial Context. (I only removed a lot of printing code that produced the next section.]
B - The Eclipse console output for a failure.
C - Cut and paste code. Just in case anyone can help me get this to work. I’d like to leave behind something the next new WF user can cut and past and run. The only difference from 1 above is that this version has all the static methods I used to format the output. NOTE: I know the comments I inserted about the less than sign sound dumb. BUT ... they are true.
A Code Summary
import java.util.Properties;
import javax.naming.CommunicationException;
import javax.naming.Context;
import javax.naming.InitialContext;
public class JmsTestGetJNDIContext {
//members
final private Properties env = new Properties() {
private static final long serialVersionUID = 1L;
{
/* These are Properties used by a standalone JavaClient to secure a WIldFly InitialContext()*/
put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
put(Context.PROVIDER_URL,"http-remoting://localhost:9990");
put(Context.SECURITY_PRINCIPAL,"userGLB");
put(Context.SECURITY_CREDENTIALS,"Open");
put("jboss.naming.client.ejb.context", true);
/*The above URL, ID and PW successfully open Wildfly's Admin Console*/
}
};
//constructor
private JmsTestGetJNDIContext (){
/*print "beg"*/
/*print "env"*/
try {
/*print "Requesting InitialContext"*/
Context ctx = new InitialContext(this.env);
/*print "JNDI Context: " + ctx)*/
/*print "end");
} catch (CommunicationException e) {
/* print "You forgot to start WildFly dummy!"*/
} catch (Exception e) {
/* print"caught: " + e.getClass().getName()*/
/*print e.getMessage()*/
/* "end")*/
}
static public void main (String[] args) {
/*print "beg"*/
JmsTestGetJNDIContext client = new JmsTestGetJNDIContext ();
/*print "end"*/
}
}
B - Console Output
JmsTestGetJNDIContext.main () beg
JmsTestGetJNDIContext.<init> () beg
JmsTestGetJNDIContext.<init> () These are Properties used to obtain IntialContext
Key: java.naming.provider.url
Value: http-remoting://localhost:9990
Key: java.naming.factory.initial
Value: org.jboss.naming.remote.client.InitialContextFactory
Key: jboss.naming.client.ejb.context
Value: true
Key: java.naming.security.principal
Value: userGLB
Key: java.naming.security.credentials
Value: Open
JmsTestGetJNDIContext.<init> () Requesting InitialContext
JmsTestGetJNDIContext.<init> () caught: javax.naming.NamingException
JmsTestGetJNDIContext.<init> () Failed to create remoting connection
JmsTestGetJNDIContext.<init> () end
JmsTestGetJNDIContext.main () end
Cut and Paste Code
package org.america3.gotest.xtra;
import java.util.Properties;
import javax.naming.CommunicationException;
import javax.naming.Context;
import javax.naming.InitialContext;
public class JmsTestGetJNDIContext {
//members
final private Properties env = new Properties() {
/**
* Properties used by a standalone JavaClient to secure
* a WIldFly InitialContext()*/
private static final long serialVersionUID = 1L;
{
put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
put(Context.PROVIDER_URL, "http-remoting://localhost:9990");
put(Context.SECURITY_PRINCIPAL, "userGLB");
put(Context.SECURITY_CREDENTIALS, "Open");
// The above URL, ID and PW successfully open Wildfly's Admin Console
put("jboss.naming.client.ejb.context", true);
}
};
//constructor
private JmsTestGetJNDIContext (){/*ignore*/String iAm = JmsTestGetJNDIContext.getIAm(" ", Thread.currentThread().getStackTrace());
P (iAm, "beg");
pProps(iAm, env);
try {
P (sp + iAm, "Requesting InitialContext");
Context ctx = new InitialContext(this.env);
P (sp + iAm, "JNDI Context: " + ctx);
P (sp + iAm, "end");
} catch (CommunicationException e) {
P (sp + iAm, "You forgot to start WildFly dummy!");
} catch (Exception e) {
P (sp + iAm, "caught: " + e.getClass().getName());
P (sp + iAm, e.getMessage());
P (iAm, "end");
}
}
static public void main (String[] args) {/*ignore*/String iAm = JmsTestGetJNDIContext.getIAm("",Thread.currentThread().getStackTrace());
P (iAm, "beg");
JmsTestGetJNDIContext client = new JmsTestGetJNDIContext ();
P (iAm , "end");
}
/*The remaining static methods are just to facilitate printing.
* They are normally in a Untility package I add to my projects.
* I put them here so this code would run for anyone.*/
static private void pProps (String leader, Properties p) {
StringBuffer sb = new StringBuffer ();
String s = JmsTestGetJNDIContext.padRight(leader, 45, ' ');
s = " " + s + "These are Properties used to obtain IntialContext"+"\n";
sb.append(s);
String skip = "";
for (Object key: p.keySet()) {
sb.append(skip + " " + JmsTestGetJNDIContext.padRight("\""
+ (String)key + "\"", 40, ' ')
+ " \"" + p.get(key) + "\"");
skip = "\n";
}
System.out.println(sb);
}
static private void P (String s, String s2) {
System.out.println(s + s2);
}
static public String getClassMethodName (StackTraceElement[] elements) {
String className = null;
for (int i = 0; i * elements.length; i++]i ) {
/* You need to type in a less than sign for the '*'
* because when I do, the editor will not show any code
* that comes after it.
* I have no idea why, but I've spent over an hour trying,
* and every time I type a less than sign all the following
* code dissappears!*/
className = elements[i].getClassName ();
if (className.startsWith ("org.america3")) {
int end = className.lastIndexOf ('.');
return className.substring (end + 1) + "." + elements[i].getMethodName ();
} else {
continue;
}
}
return "no project method found in elements beginning with org.america3" ;
}
static private String getIAm (String indent, StackTraceElement[] elements) {
StringBuffer sb = new StringBuffer ();
sb.append(JmsTestGetJNDIContext.getClassMethodName(elements));
sb.append(" ()");
return indent + JmsTestGetJNDIContext.padRight (sb.toString(), 45, ' ') ;
}
static public String padRight(String s, int width, char c){
if (s == null) return "Null String";
if(s.length() ** width){
/* You need to type in a greater than or equal sign for
* the '**'see above.*/
return s;
} else {
StringBuffer sb = new StringBuffer();
sb.append (s);
for(int i = 0; i *** (width - s.length()); i++){
/*You need to type in a less than sign the '***'. Again see above*/
sb.append(c);
}
return sb.toString();
}
}
static public String sp = " ";
}
A while ago I also struggled with remote EJBs in my CLI application. I excavated a small example project that I wrote then. It gets an InitialContext and calls a remote EJB named AddBrackets:
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import de.dnb.test.ejb.AddBrackets;
public final class Application {
public static void main(String[] args) throws NamingException {
final Properties jndiProperties = initJndiProperties();
final AddBrackets addBrackets = getEjb(jndiProperties);
System.out.println(addBrackets.processText("Hello World"));
}
private static Properties initJndiProperties() {
final Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put("jboss.naming.client.ejb.context", true);
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080/");
//jndiProperties.put(Context.SECURITY_PRINCIPAL, "test");
//jndiProperties.put(Context.SECURITY_CREDENTIALS, "test");
return jndiProperties;
}
private static AddBrackets getEjb(Properties jndiProps)
throws NamingException {
final Context jndiContext = new InitialContext(jndiProps);
final String interfaceName = AddBrackets.class.getName();
return (AddBrackets) jndiContext.lookup(
"ejbtest-app-1.0-SNAPSHOT/ejbtest-ejb-1.0-SNAPSHOT/AddBracketsBean!"
+ interfaceName);
}
}
I built this program as a Maven project which had a dependency on
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>8.2.1.Final</version>
<type>pom</type>
</dependency>
This dependency brings in Wildfly's remote client EJB implementation and adds the following jars to the class path (links are to Maven Central):
jboss-logging-3.1.4.GA.jar
jboss-marshalling-1.4.9.Final.jar
jboss-marshalling-river-1.4.9.Final.jar
jboss-remoting-4.0.7.Final.jar
jboss-sasl-1.0.4.Final.jar
jboss-ejb-api_3.2_spec-1.0.0.Final.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
xnio-api-3.3.0.Final.jar
xnio-nio-3.3.0.Final.jar
jboss-ejb-client-2.0.1.Final.jar
jboss-remote-naming-2.0.1.Final.jar
wildfly-build-config-8.2.1.Final.jar
I did no special configuration on Wildfly to run this example. I simply downloaded a vanilla Wildfly 8.2.1, unzipped it, set up an admin user with the add-user.sh script and deployed my EJB in an EAR. As you can see above access is granted without a username and a password.
You can find the complete project including the AddBrackets EJB on my bitbucket account.
When I tried to get my head around remote EJBs with Wildfly, I found the article JBoss EAP / Wildfly – Three ways to invoke remote EJBs really helpful. It clearly describes the three different methods to access remote EJBs on Wildfly.
According to your own answer the following jars are on your classpath:
jboss-remote-naming-1.0.7.final.jar
jboss-logging.jar
xnio-api-3.0.7.ga.jar
jboss-remoting-3.jar
jboss-ejb-client-1.0.19.final.jar
You write that the application throws the following exception:
java.lang.NoSuchMethodError:
org.jboss.remoting3.Remoting.createEndpoint(Ljava/lang/String;Lorg/xnio/OptionMap;)Lorg/jboss/remoting3/Endpoint;]
This exception is thrown when org.jboss.naming.remote.client.EndpointCache which is part of the jboss-remote-naming jar tries to call Remoting.createEndpoint() which is contained in the jboss-remoting jar.
As you explain in your answer the reason for this is that the Remoting class declares a 3-parameter version of the createEndpoint() method while the EndpointCache class tries to call a 2-parameter version which does not exist.
I checked the commit histories and declared dependencies of the jboss-remote-naming and the jboss-remoting projects to find out what is going wrong there. This is what I found out:
The 2-parameter version of createEndpoint() was only added in version 3.2 of jboss-remoting. The pom.xml for jboss-remote-naming-1.0.7.final says it depends on jboss-remoting 3.2.7.GA.
As there is no version number on your jboss-remoting-3.jar, I guess it is an older version. You should be able to check this by looking for a pom.xml in META-INF folder of your jboss-remoting-3.jar. This should contain the version number.
To solve your problem, I suggest to replace your jboss-remoting-3.jar with jboss-remoting-3.2.7ga.jar or to use the set of jars I listed in my other answer.
I’ve decided the problem isn’t coding or the JNDI InititialContext Properties.
I mean the fatal error is a NoSuchMethodError. Therefore, as I confirmed in the WildFly server logs, my main method never even tries to connect.
Here’s what I think explains the real problem.
And I think it explains why there are so many calls for help with this error:
java.lang.NoSuchMethodError:
org.jboss.remoting3.Remoting.createEndpoint(Ljava/lang/String;Lorg/xnio/OptionMap;)Lorg/jboss/remoting3/Endpoint;]
Also why none of those calls for help ever get a conclusive answer. Just people suggesting different jars.
And since all those answers fixed on jars, this is how I tested the Build Path I was using:
First I removed all jars from the Build Path. Then I ran my one line main program till all ClassNotFoundException were gone.
First Error
java.lang.ClassNotFoundException:
org.jboss.naming.remote.client.InitialContextFactory]
Added jboss-remote-naming-1.0.7.final.jar to class path
Next Error
java.lang.NoClassDefFoundError:
org/jboss/logging/Logger
Added jboss-logging.jar
Next Error
java.lang.NoClassDefFoundError:
org/xnio/Options
Added xnio-api-3.0.7.ga.jar
Next Error
java.lang.NoClassDefFoundError:
org/jboss/remoting3/spi/ConnectionProviderFactory
Added jboss-remoting-3.jar
Next Error
java.lang.NoClassDefFoundError:
org/jboss/ejb/client/EJBClientContextIdentifier
Added jboss-ejb-client-1.0.19.final.jar
FATAL ERROR (note: All NoClassDefFoundError have been cleared)
java.lang.NoSuchMethodError:
org.jboss.remoting3.Remoting.createEndpoint(Ljava/lang/String;Lorg/xnio/OptionMap;)Lorg/jboss/remoting3/Endpoint;]
Then I used Eclipse’s Project Explorer to verify:
That jboss-remoting3.jar has the org.jboss.remoting3.Remoting Class. It does. That’s why there is no NoClassDefFoundError left above.
And verified it had this method:
public Endpoint createEndpoint (String, Executor, OptionMap) note: 3 parameters.
BUT the above Error indicates something is calling:
public Endpoint createEndpoint (String, OptionMap) note: 2 parameters.
That’s why the program throws a NoSuchMethodError. It is looking for a 2 paramater version of org.jboss.remoting3.Remoting.createEndpoint(). And the Remoting Class I have only has a 3 parameter version.`
I know this sounds impossible but the only thing I can think is there is an inconsistency in the Java API???
Clearly something is calling org.jboss.remoting3.Remoting.createEndpoint with 2 parameters.
But my org.jboss.remoting3.Remoting Class only has a 3 parameter version of the createEndpoint() Method.
So I’m going to clean this all up and repost a question asking how to explain the existence of a Class calling for a 2 paramter org.jboss.remoting3.Remoting.createEndpoint Method when I have a jar whose org.jboss.remoting3.Remoting only offers a 3-parameter.
Here is your obligatory "that's a dumb question." Does the wildfly remote quickstart github repo answer the question for you? Their code, from RemoteEJB.java
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
return (RemoteCalculator) context.lookup("ejb:/ejb-remote-server-side/CalculatorBean!" + RemoteCalculator.class.getName());
I am taking the foursquare sample java code and the same sample values from git and running in my local machine, but getting the following exception.
Here is my code:
String ll = args.length > 0 ? args[0] : "44.3,37.2";
try {
FourSquareSampleMain fourSquareSample = new FourSquareSampleMain();
fourSquareSample.searchVenues(ll);
} catch (FoursquareApiException e) {
// TODO: Error handling
e.printStackTrace();
}
}
public void searchVenues(String ll) throws FoursquareApiException {
// First we need a initialize FoursquareApi.
FoursquareApi foursquareApi = new FoursquareApi("CLIENT_ID",
"CLIENT_SECRET", null);
// After client has been initialized we can make queries.
Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null,
null, null, null, null, null);
if (result.getMeta().getCode() == 200) {
CompactVenue[] venueList = result.getResult().getVenues();
System.out.println("Compact Venue List size : " + venueList.length);
// if query was ok we can finally we do something with the data
for (CompactVenue venue : venueList) {
// TODO: Do something we the data
System.out.println("Venue Name : " + venue.getName());
}
System.out.println("End of IF Loop: ");
} else {
// TODO: Proper error handling
System.out.println("Error occured: ");
System.out.println(" code: " + result.getMeta().getCode());
System.out.println(" type: " + result.getMeta().getErrorType());
System.out.println(" detail: " + result.getMeta().getErrorDetail());
}
}
The size of the venueList is always "0", but when I debugged it , it throws the below exception:
"org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array."
But strange when I changed the latitude and longitude value,
String ll = "-33.883056 , 151.216667";// latlong surry hills sydney
I get the below exception:
fi.foyt.foursquare.api.FoursquareApiException: org.json.JSONException: JSONObject["icon"] not a string.
at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:143)
at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:194)
at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:141)
at fi.foyt.foursquare.api.JSONFieldParser.parseEntities(JSONFieldParser.java:57)
at fi.foyt.foursquare.api.FoursquareApi.venuesSearch(FoursquareApi.java:1017)
at FourSquareSampleMain.searchVenues(FourSquareSampleMain.java:57)
at FourSquareSampleMain.main(FourSquareSampleMain.java:43)
Caused by: org.json.JSONException: JSONObject["icon"] not a string.
at org.json.JSONObject.getString(JSONObject.java:658)
at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:202)
at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:141)
What am I missing here? please suggest.
I found a workaround for that. It's a patch, but it works. Details:
Info was taken from this post where same issue was identified and fixed
Take a look that diff that resolve the issue: https://github.com/wallabyfinancial/foursquare-api-java/compare/master...ganchix:master
Copy those 3 raw classes (Category, GeoCodeFeature and Icon) as they are and add them into your porject under the package fi.foyt.foursquare.api.entities and that's it
Note 1: when you replace classes (same package and class name) in yur project, the clasloader will use yours instead of the classes provided by the jar dependency, so, there is a quick fix.
I did that and it worked like a charm
Note 2: As soon as the sdk is updated, you should remove this patch and upgrade the sdk dependency
Hope it helps
i'm trying to get all the users that belong to a project through the SDK for Java version 11.0.0 but i'm stuck.
With that code i retrieve the collections and the projects:
TeamFoundationServerEntity teamFoundationServer=configurationServer.getTeamFoundationServerEntity(true);
if (teamFoundationServer != null)
{
ProjectCollectionEntity[] projectCollections = teamFoundationServer.getProjectCollections();
for (ProjectCollectionEntity pce : projectCollections) {
System.out.println("Collection: "+pce.getDisplayName()+" "+pce.getDescription());
TeamProjectEntity[] tpe=pce.getTeamProjects();
for (TeamProjectEntity teamProjectEntity : tpe) {
System.out.println(" teamProjectEntity: "+teamProjectEntity.getDisplayName()+" * "+teamProjectEntity.getProjectURI());
}
}
}
Also with the following code taken from the example in the downloaded zip and has the groups information:
GUID[] resourceTypes = new GUID[]{
CatalogResourceTypes.PROJECT_COLLECTION
};
CatalogResource[] resources =
configurationServer.getCatalogService().queryResourcesByType(resourceTypes, CatalogQueryOptions.NONE);
if (resources != null)
{
for (CatalogResource resource : resources)
{
String instanceId = resource.getProperties().get("InstanceId");
TFSTeamProjectCollection tpc = configurationServer.getTeamProjectCollection(new GUID(instanceId));
System.out.println("TFSTeamProjectCollection");
System.out.println("\tName: " + tpc.getName().toString());
System.out.println("\tURI: " + tpc.getBaseURI());
ProjectCollection pc=tpc.getWorkItemClient().getProjects();
for (Project project : pc) {
System.out.println("---"+project.getName()+" * "+project.getID());
String[] grps=tpc.getWorkItemClient().getGroupDataProvider(project.getName()).getGroups();
}
}
}
I have found the class IdentityManagementService
IdentityManagementService ims=new IdentityManagementService(configurationServer);
but i don't know how to use the listApplicationGroups and readIdentities methods that maybe are useful to find a solution.
Has anyone some idea to get the users in every project group?
A few more trial after #Cece - MSFT answer and looking at the blog and the book Microsoft Team Foundation Server 2015 Cookbook. Using this code
TeamFoundationIdentity[] appGroups=ims.listApplicationGroups(project.getURI(), ReadIdentityOptions.EXTENDED_PROPERTIES);
for (TeamFoundationIdentity group : appGroups)
{
System.out.println(group.getDisplayName());
TeamFoundationIdentity[] groupMembers= ims.readIdentities(new IdentityDescriptor[]{group.getDescriptor()}, MembershipQuery.EXPANDED, ReadIdentityOptions.EXTENDED_PROPERTIES);
for (TeamFoundationIdentity member : groupMembers)
{
for(IdentityDescriptor memberID : member.getMembers())
{
TeamFoundationIdentity memberInfo=ims.readIdentity(IdentitySearchFactor.IDENTIFIER, memberID.getIdentifier(), MembershipQuery.EXPANDED, ReadIdentityOptions.EXTENDED_PROPERTIES);
System.out.println(memberInfo.getDisplayName());
}
}
}
the variable appGroups is always empty. Maybe the method project.getURI() is not suitable? If I put null
TeamFoundationIdentity[] tfi=ims.listApplicationGroups(null, ReadIdentityOptions.INCLUDE_READ_FROM_SOURCE);
for (TeamFoundationIdentity teamFoundationIdentity : tfi) {
System.out.println(teamFoundationIdentity.getDisplayName());
System.out.println(teamFoundationIdentity.getDescriptor().getIdentityType());
IdentityDescriptor[] mbs=teamFoundationIdentity.getMembers();
for (IdentityDescriptor mb : mbs) {
TeamFoundationIdentity mbi=ims.readIdentity(mb, MembershipQuery.EXPANDED, ReadIdentityOptions.EXTENDED_PROPERTIES);
System.out.println(mbi.getProperties());
}
}
the output is
[DefaultCollection]\Project Collection Administrators
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Build Administrators
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Build Service Accounts
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Proxy Service Accounts
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Service Accounts
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Test Service Accounts
Microsoft.TeamFoundation.Identity
[DefaultCollection]\Project Collection Valid Users
Microsoft.TeamFoundation.Identity
Why I can't get the Contributors, Readers and the other groups with project.getURI() in listApplicationGroups method? I can only get them with
String[] grps=tpc.getWorkItemClient().getGroupDataProvider(project.getName()).getGroups();
Check this blog. In this blog, author used IGroupSecurityService service to get the list of application groups and get the details of which group the user is a member.
But now, IGroupSecurityService is obsolete. You need to use the IIdentityManagementService or ISecurityService instead.
The code snippet should look like:
var sec = tfs.GetService<IIdentityManagementService>();
Identity[] appGroups = sec.ListApplicationGroups(Scope Uri);
foreach (Identity group in appGroups)
{
Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);
foreach (Identity member in groupMembers)
{
var groupM = new GroupMembership {GroupName = member.DisplayName, GroupSid = member.Sid};
if (member.Members != null)
{
foreach (string memberSid in member.Members)
{
Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.Expanded);
var userName = memberInfo.Domain + "\\" + memberInfo.AccountName;
Detailed steps, you can check the blog.
For anyone who is interested in this two link there is the answer:
get groups of project and get members of a group
Busy trying to Call RPG function from Java and got this example from JamesA. But now I am having trouble, here is my code:
AS400 system = new AS400("MachineName");
ProgramCall program = new ProgramCall(system);
try
{
// Initialise the name of the program to run.
String programName = "/QSYS.LIB/LIBNAME.LIB/FUNNAME.PGM";
// Set up the 3 parameters.
ProgramParameter[] parameterList = new ProgramParameter[2];
// First parameter is to input a name.
AS400Text OperationsItemId = new AS400Text(20);
parameterList[0] = new ProgramParameter(OperationsItemId.toBytes("TestID"));
AS400Text CaseMarkingValue = new AS400Text(20);
parameterList[1] = new ProgramParameter(CaseMarkingValue.toBytes("TestData"));
// Set the program name and parameter list.
program.setProgram(programName, parameterList);
// Run the program.
if (program.run() != true)
{
// Report failure.
System.out.println("Program failed!");
// Show the messages.
AS400Message[] messagelist = program.getMessageList();
for (int i = 0; i < messagelist.length; ++i)
{
// Show each message.
System.out.println(messagelist[i]);
}
}
// Else no error, get output data.
else
{
AS400Text text = new AS400Text(50);
System.out.println(text.toObject(parameterList[1].getOutputData()));
System.out.println(text.toObject(parameterList[2].getOutputData()));
}
}
catch (Exception e)
{
//System.out.println("Program " + program.getProgram() + " issued an exception!");
e.printStackTrace();
}
// Done with the system.
system.disconnectAllServices();
The application Hangs at this lineif (program.run() != true), and I wait for about 10 minutes and then I terminate the application.
Any idea what I am doing wrong?
Edit
Here is the message on the job log:
Client request - run program QSYS/QWCRTVCA.
Client request - run program LIBNAME/FUNNAME.
File P6CASEL2 in library *LIBL not found or inline data file missing.
Error message CPF4101 appeared during OPEN.
Cannot resolve to object YOBPSSR. Type and Subtype X'0201' Authority
FUNNAME insert a row into table P6CASEPF through a view called P6CASEL2. P6CASEL2 is in a different library lets say LIBNAME2. Is there away to maybe set the JobDescription?
Are you sure FUNNAME.PGM is terminating and not hung with a MSGW? Check QSYSOPR for any messages.
Class ProgramCall:
NOTE: When the program runs within the host server job, the library list will be the initial library list specified in the job description in the user profile.
So I saw that my problem is that my library list is not setup, and for some reason, the user we are using, does not have a Job Description. So to over come this I added the following code before calling the program.run()
CommandCall command = new CommandCall(system);
command.run("ADDLIBLE LIB(LIBNAME)");
command.run("ADDLIBLE LIB(LIBNAME2)");
This simply add this LIBNAME, and LIBNAME2 to the user's library list.
Oh yes, the problem is Library list not set ... take a look at this discussion on Midrange.com, there are different work-around ...
http://archive.midrange.com/java400-l/200909/msg00032.html
...
Depe