ClassCastException while trying to access MBeans - jmx

I am establishing a JMX connection like:
String currentHost = getRequest().getRequestURL().toString().replaceAll(getRequest().getRequestURI(), "");
String hostname = currentHost.substring(currentHost.lastIndexOf("/") + 1, currentHost.lastIndexOf(":"));
int port = Integer.parseInt(currentHost.substring(currentHost.lastIndexOf(":") + 1));
ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
String username = <system user name>;
String password = <system user password>;
String url = "service:jmx:rmi:///jndi/iiop://" + hostname + ":" + port + "/weblogic.management.mbeanservers.domainruntime";
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
JMXServiceURL jmxServiceURL = new JMXServiceURL(url);
JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL, h);
MBeanServerConnection connection = connector.getMBeanServerConnection();
Then I am trying to retrieve domain configuration by the following code:
ObjectName domain = (ObjectName) connection.getAttribute(service, "DomainConfiguration");
DomainRuntimeServiceMBean domainRuntimeService = MBeanServerInvocationHandler.newProxyInstance(connection, service, DomainRuntimeServiceMBean.class, false);
DomainMBean domainConfiguration = domainRuntimeService.getDomainConfiguration();
And doing this I am getting the exception:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool.testSettings(ConnectivityTestTool.java:577)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool$ManualStepsCheckerSheet.printWindowContent(ConnectivityTestTool.java:1729)
at com.netcracker.jsp.Sheet.printWindow(Sheet.java:380)
at com.netcracker.jsp.CommonPage.printWindowContent(CommonPage.java:2075)
at com.netcracker.jsp.UniPage.printWindowContent(UniPage.java:719)
at com.netcracker.jsp.ModernPage.printWindow(ModernPage.java:737)
at com.netcracker.jsp.CommonPage.printContent(CommonPage.java:1502)
at com.netcracker.jsp.UniPage.printContent(UniPage.java:285)
at com.netcracker.jsp.Sheet.printContent(Sheet.java:367)
at com.netcracker.jsp.Sheet._service(Sheet.java:304)
at com.netcracker.jsp.Sheet.service(Sheet.java:268)
at com.netcracker.jsp.CommonPage.service(CommonPage.java:930)
at com.netcracker.jsp.CommonPage$SecureRunner.run(CommonPage.java:325)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.security.Security.runAs(Security.java:61)
at com.netcracker.configuration.weblogic.weblogic81.Config81.doAs(Config81.java:43)
at com.netcracker.security.UserSession.doTask(UserSession.java:311)
at com.netcracker.jsp.CommonUserPage.secureRun(CommonUserPage.java:393)
at com.netcracker.jsp.CommonUserPage.secureService(CommonUserPage.java:344)
at com.netcracker.jsp.CommonPage.debugSecureService(CommonPage.java:1297)
at jsp_servlet._solutions._dhl.__connectivitytesttool._jspService(__connectivitytesttool.java:322)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.mediation.dataflow.impl.util.trigger.http.FilterImpl.doFilter(FilterImpl.java:215)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.framework.domain.filters.ThreadDomainFilter.doFilterInternal(ThreadDomainFilter.java:225)
at com.netcracker.framework.domain.filters.ThreadDomainFilter.doFilter(ThreadDomainFilter.java:99)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.presentation.process.SessionTouchFilter.doFilter(SessionTouchFilter.java:74)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.audit.NCSessionsFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.clientaddress.ClientAddressFilter.doFilter(ClientAddressFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.security.HttpSecurityFilter.doFilterInternal(HttpSecurityFilter.java:71)
at com.netcracker.platform.core.filters.security.HttpSecurityFilter.doFilter(HttpSecurityFilter.java:54)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.jsp.httpcache.JSPHeadersFilter.doFilter(JSPHeadersFilter.java:105)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3748)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1491)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.ClassCastException: javax.management.ObjectName cannot be cast to weblogic.management.configuration.DomainMBean
at com.sun.proxy.$Proxy128.getDomainConfiguration(Unknown Source)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool.getSSLParams(ConnectivityTestTool.java:428)
Line 428 mentioned in the bottom part of stack trace is actually
DomainMBean domainConfiguration = domainRuntimeService.getDomainConfiguration();
from code snippet above.
I tried to access several other MBeans by MBeanServerInvocationHandler.newProxyInstance() call and have always got similar exceptions.
Could anyone please advice what is wrong in my code? I suspect that something may be wrong with server setup but I know even less about that...

Related

Spring Authorization Server 0.3.1 problem registering several RegisteredClientRepository

Hi,
I need register several clients but when I try to do this it this exception is thrown, I have made sure that each client has a different identifier:
*Caused by: java.lang.IllegalArgumentException: Registered client must be unique. Found duplicate client secret for identifier: appclientes
at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.lambda$assertUniqueIdentifiers$0(InMemoryRegisteredClientRepository.java:107)
at java.base/java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4772)
at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.assertUniqueIdentifiers(InMemoryRegisteredClientRepository.java:95)
at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.(InMemoryRegisteredClientRepository.java:64)
at com.pryconsa.backend.config.AuthorizationServerConfig.registeredClientRepository(AuthorizationServerConfig.java:100)
at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1.CGLIB$registeredClientRepository$2()
at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1$$FastClassBySpringCGLIB$$b448ca22.invoke()
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1.registeredClientRepository()
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 58 common frames omitted
*
My code is the following:
#Bean
public RegisteredClientRepository registeredClientRepository() {
TokenSettings tokenClient1Settings = TokenSettings.builder()
.accessTokenTimeToLive(Duration.ofSeconds(client1AccessTokenValiditySeconds))
.build();
RegisteredClient registeredClient1 = RegisteredClient.withId(client1Id)
.clientId(client1Id)
.clientSecret("{noop}" + client1Secret)
.authorizationGrantType(AuthorizationGrantType.PASSWORD)
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.tokenSettings(tokenBackofficeSettings)
.scope("read")
.scope("write")
.build();
TokenSettings tokenClient2Settings = TokenSettings.builder()
.accessTokenTimeToLive(Duration.ofSeconds(client2AccessTokenValiditySeconds))
.build();
RegisteredClient registeredClient2 = RegisteredClient.withId(client2Id)
.clientId(client2Id)
.clientSecret("{noop}" + client2Secret)
.authorizationGrantType(AuthorizationGrantType.PASSWORD)
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.tokenSettings(tokenClient2Settings)
.scope("read")
.scope("write")
.build();
return new InMemoryRegisteredClientRepository(List.of(registeredClient1, registeredClient2));
}

SAML Response processing fails on parsing

I am trying to get Spring SAML to work with Idp-initiated scenario. I am getting exception when processing the SAML response message within the sample application. However when I parse the same response with simple Java code, everything goes well and I can get it parsed successfully. Any clue if there is some configuration of the parser that can be configured, I see some kind of SamlBinding in the SAMLProcessorImpl class. That seems to hold the decoder.
The first line of SAML message is:
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="s29e0437f7f268017d5f6a5766797621c301feb737" Version="2.0" IssueInstant="2016-06-21T20:01:18Z" Destination="http://www.xxxxxxxxxxxxxxxxxxxxxxxxx.com:9080/site/saml/SSO"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">http://fmdev.ist.intralink.bns:80</saml:Issuer><samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
and the error is complaining that the character ">" in "2.0:assertion">http" should be an attribute, ">" or "/>" which is the case!!!
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 303; Element type "saml:Issuer" must be followed by either attribute specifications, ">" or "/>".
Full exception trace below:
org.springframework.security.authentication.AuthenticationServiceException: Error decoding incoming SAML message
at org.springframework.security.saml.SAMLProcessingFilter.attemptAuthentication(SAMLProcessingFilter.java:94)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:195)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.saml.metadata.MetadataGeneratorFilter.doFilter(MetadataGeneratorFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.opensaml.ws.message.decoder.MessageDecodingException: Encountered error parsing message into its DOM representation
at org.opensaml.ws.message.decoder.BaseMessageDecoder.unmarshallMessage(BaseMessageDecoder.java:209)
at org.opensaml.saml2.binding.decoding.HTTPPostDecoder.doDecode(HTTPPostDecoder.java:91)
at org.opensaml.ws.message.decoder.BaseMessageDecoder.decode(BaseMessageDecoder.java:79)
at org.opensaml.saml2.binding.decoding.BaseSAML2MessageDecoder.decode(BaseSAML2MessageDecoder.java:70)
at org.springframework.security.saml.processor.SAMLProcessorImpl.retrieveMessage(SAMLProcessorImpl.java:105)
at org.springframework.security.saml.processor.SAMLProcessorImpl.retrieveMessage(SAMLProcessorImpl.java:172)
at org.springframework.security.saml.SAMLProcessingFilter.attemptAuthentication(SAMLProcessingFilter.java:77)
... 30 more
Caused by: org.opensaml.xml.parse.XMLParserException: Invalid XML
at org.opensaml.xml.parse.StaticBasicParserPool.parse(StaticBasicParserPool.java:237)
at org.opensaml.ws.message.decoder.BaseMessageDecoder.unmarshallMessage(BaseMessageDecoder.java:186)
... 36 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 303; Element type "saml:Issuer" must be followed by either attribute specifications, ">" or "/>".
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at org.opensaml.xml.parse.StaticBasicParserPool$DocumentBuilderProxy.parse(StaticBasicParserPool.java:673)
at org.opensaml.xml.parse.StaticBasicParserPool.parse(StaticBasicParserPool.java:234)
I investigated more into this. I noticed there is a difference in characters passed to the DOM parser between the working Java app and the Spring SAML one. Looking more into it, I found out that the message retrieved in the HTTPPostDecoder:getBase64DecodedMessage() is truncated. The encoded message I was using for testing had "+" signs and that needed to be encoded in the HTTP request. Should be replaced with "%2B". Doing this resolved the issue.
I am facing same issue while parsing/decoding SAML response. To resolve this issue I use encodeURIComponent()to convert/encode our SAML Response.
Details:
Tech Stack : **NodeJS**
Lib using for SAML code decode **saml2-js**
Code:
const postAssertGetSamlResponse = async(attr) => {
return new Promise((resolve, reject) => {
attr.SP.post_assert(attr.IDP,attr.options,function(err,decodedSamlResponse) {
if (err != null) {
console.log(err);
}
let data = {
decodedSAMLResponse: decodedSamlResponse,
redirectURL: attr.redirectClientURL
}
return resolve(data);
});
});
}
let regex = new RegExp("(([^&#]*)|&|#|$)");
let results = regex.exec(req.SAMLResponse);
results[2] = decodeURIComponent(results[2]);
results[2] = encodeURIComponent(results[2]);
let samlResponse = decodeURIComponent(results[2].replace(/\+/g, " "));
attrs = {
redirectClientURL: "https://test.com"
}
attrs.options = {
request_body: {
SAMLResponse: samlResponse
}
};
let data = await postAssertGetSamlResponse(attr);
console.log("SAML response ::", data);

BootStrap.groovy causing grails to fail

migrating old 2.2.2 app to 3.1.2, can i know why this app is crashing because of bootstrap.groovy
any help will be appreciated thank you
using: grails 3.1.2, mysql workbench 6
This is the Bootstrap.groovy to which causes the whole application to stop running
import grailsapp.Location;
import grailsapp.State;
import grailsapp.User;
import grailsapp.Type;
class BootStrap {
def init = { servletContext ->
new State(state: "Issuable", updates: [:]).save(failOnError:true)
new State(state: "Holding", updates: [:]).save(failOnError:true)
new State(state: "In for repair", updates: [:]).save(failOnError:true)
new Location(location: "L163", specific: "Rack 3A", updates: [:]).save(failOnError:true)
new Location(location: "L163", specific: "Rack 3B", updates: [:]).save(failOnError:true)
new Location(location: "L163", specific: "Rack 3C", updates: [:]).save(failOnError:true)
new User(username:"blah", password: User.hashPassword("password"), firstName:"blah", lastName:"blah", isAdmin:true, updates:[:]).save(failOnError:true)
new Type(type:"Dell E6500").save(failOnError:true)
new Type(type:"Dell E6510").save(failOnError:true)
new Type(type:"Dell E6520").save(failOnError:true)
}
def destroy = {
}
}
These are the errors in which it causes
ERROR org.springframework.boot.SpringApplication - Application startup failed
grails.validation.ValidationException: Validation Error(s) occurred during save():
- Field error in object 'grailsapp.State' on field 'updates': rejected value [{}]; codes [grailsapp.State.updates.typeMi
smatch.error,grailsapp.State.updates.typeMismatch,state.updates.typeMismatch.error,state.updates.typeMismatch,typeMismat
ch.grailsapp.State.updates,typeMismatch.updates,typeMismatch.java.util.Set,typeMismatch]; arguments [updates]; default m
essage [Could not find matching constructor for: java.util.Set()]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8
.0_65]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_65]
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075) ~
[springloaded-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) ~[groovy-2.4.6.jar:2.4.6]
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77) ~[groovy-2.4.
6.jar:2.4.6]
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1714) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1531) ~[groovy-2.4.6.jar:2.4.6]
at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:954) ~[groovy-2.4.6.jar:2.4.
6]
at org.codehaus.groovy.runtime.DefaultGroovyMethods.newInstance(DefaultGroovyMethods.java:15640) ~[groovy-2.4.6.
jar:2.4.6]
at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:131) ~
[grails-datastore-gorm-hibernate-core-5.0.2.RELEASE.jar:na]
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:140) ~[grails-datastore-gorm-5.0.2.R
ELEASE.jar:na]
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-2.4.6.jar:2.4.6
]
at grailsapp.State.save(State.groovy) ~[main/:na]
at grailsapp.State.save(State.groovy) ~[main/:na]
at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) [groovy-2.4.6.jar:2.4.6
]
at BootStrap$_closure1.doCall(BootStrap.groovy:10) ~[main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) ~[springloa
ded-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) ~[groovy-2.4.6.jar:2.4.6]
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) ~[groovy-2.4.6
.jar:2.4.6]
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.Closure.call(Closure.java:426) ~[groovy-2.4.6.jar:2.4.6]
at groovy.lang.Closure.call(Closure.java:420) ~[groovy-2.4.6.jar:2.4.6]
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:437) ~[grails-bootstrap-3.1.2.jar:3
.1.2]
at grails.util.Environment.executeForEnvironment(Environment.java:430) ~[grails-bootstrap-3.1.2.jar:3.1.2]
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:406) ~[grails-bootstrap-3.1.2.jar:3.1.2
]
at org.grails.web.servlet.boostrap.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:62) ~[g
rails-web-3.1.2.jar:3.1.2]
at org.grails.web.servlet.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:65) ~[grails-
web-3.1.2.jar:3.1.2]
at org.grails.plugins.web.servlet.context.BootStrapClassRunner.onStartup(BootStrapClassRunner.groovy:53) ~[grail
s-plugin-controllers-3.1.2.jar:3.1.2]
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:24
0) ~[grails-core-3.1.2.jar:3.1.2]
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy) ~
[grails-core-3.1.2.jar:3.1.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMult
icaster.java:163) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMult
icaster.java:136) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:3
81) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:3
35) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:
855) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationC
ontext.java:140) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~
[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext
.java:118) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.2.RELEASE.ja
r:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-
1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.2.RELEASE.jar:1.
3.2.RELEASE]
at grails.boot.GrailsApp.run(GrailsApp.groovy:55) [grails-core-3.1.2.jar:3.1.2]
at grails.boot.GrailsApp.run(GrailsApp.groovy:365) [grails-core-3.1.2.jar:3.1.2]
at grails.boot.GrailsApp.run(GrailsApp.groovy:354) [grails-core-3.1.2.jar:3.1.2]
at grails.boot.GrailsApp$run.call(Unknown Source) [grails-core-3.1.2.jar:3.1.2]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.6.jar:2.4.6
]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-2.4.6.jar:2.4.6
]
at grailsapp.Application.main(Application.groovy:8) [main/:na]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full trace)
state.groovy
package grailsapp
class State {
String state
static hasMany = [updates: Update]
static constraints = {
state blank:false
}
String toString() {
state
}
static ArrayList<State> getStates() {
State.findAllByStateNotEqual("Issued")
}
}
After seeing your State Class, I have checked that 'updates' field is a hasMany relationship. It says that the relation is from 0 to many objects. I mean, It is not obligatory to specify the updates, so if you write your state class without updates, it must be valid:
new State(state: "Issuable")
new State(state: "Holding")
new State(state: "In for repair")
Your problem now is that if you try:
new State(state: "Issuable", updates: [:]).save(failOnError:true) or
new State(state: "Issuable", updates: []).save(failOnError:true)
you'll get an error because updates musn't be a map or a list. It must be an object of 'Update' class.
It looks like the updates field on State is a Set but you're initializing it with a Map. Try:
new State(state: "Issuable", updates: []).save(failOnError:true)
new State(state: "Holding", updates: []).save(failOnError:true)
new State(state: "In for repair", updates: []).save(failOnError:true)

Sending email via JWebServices for Exchange and JAVA

import com.independentsoft.exchange.Body;
import com.independentsoft.exchange.ItemInfoResponse;
import com.independentsoft.exchange.Mailbox;
import com.independentsoft.exchange.Message;
import com.independentsoft.exchange.Service;
import com.independentsoft.exchange.ServiceException;
public class Example {
public static void main(String[] args)
{
try
{
Service service = new Service("https://myserver/ews/Exchange.asmx", "user", "password");
Message message = new Message();
message.setSubject("Test");
message.setBody(new Body("Body text"));
message.getToRecipients().add(new Mailbox("John#mydomain.com"));
message.getCcRecipients().add(new Mailbox("Mark#mydomain.com"));
ItemInfoResponse response = service.send(message);
}
catch (ServiceException e)
{
System.out.println(e.getMessage());
System.out.println(e.getXmlMessage());
e.printStackTrace();
}
}
}
Hello! I tried to send an email, but did not work.
I'ved used a valid user and password, at message.getToRecipients I used my yahoo email address.
At output on eclipse this is my result. Where is my mistake ?
JWebServices for Exchange 2.0 evaluation version, www.independentsoft.com.
myserver
null
myserver
at com.independentsoft.exchange.Service.createItemImplementation(Unknown Source)
at com.independentsoft.exchange.Service.send(Unknown Source)
at com.independentsoft.exchange.Service.send(Unknown Source)
at com.independentsoft.exchange.Service.send(Unknown Source)
at com.independentsoft.exchange.Service.send(Unknown Source)
at Example.main(Example.java:26)
Caused by: java.net.UnknownHostException: myserver
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
at java.net.InetAddress.getAllByName(InetAddress.java:1162)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:44)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:101)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at com.independentsoft.exchange.Service.a(Unknown Source)
... 6 more
Replace "myserver" with real name of your Exchange server.
try to AutoDiscover your service url first:
Sample here

calling ant task in my plugin and redirect the output to the console

In my eclipse plugin, I am trying to execute an Ant task and to redirect the output to the eclipse console
Here is my code:
AntRunner runner = new AntRunner();
runner.addBuildLogger("myplugin.AntLogger");
String projectPath = getProject().getLocation().toString();
String buildFileLocation = projectPath + File.separator + "build.xml";
runner.setBuildFileLocation(buildFileLocation);
runner.setExecutionTargets(new String[] { "build-for-device" });
The AntLogger code is:
public class AntLogger extends org.apache.tools.ant.DefaultLogger {
private IOConsole console = new IOConsole("Ant", null);
private IOConsoleOutputStream outputStream = console.newOutputStream();
public AntLogger() {
ConsolePlugin.getDefault().getConsoleManager()
.addConsoles(new IConsole[] { console });
}
#Override
protected void printMessage(String message, PrintStream stream, int priority) {
super.printMessage(message, stream, priority);
try {
outputStream.write(message + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
and I added the ant.jar to the plugin.xml
<extension
point="org.eclipse.ant.core.extraClasspathEntries">
<extraClasspathEntry
library="ant.jar">
</extraClasspathEntry>
</extension>
No matter what I do I keep getting class not found exception:
java.lang.NoClassDefFoundError: org/apache/tools/ant/DefaultLogger
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:626)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:608)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:562)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:486)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:459)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
at org.eclipse.ant.core.AntCorePreferences$WrappedClassLoader.findClass(AntCorePreferences.java:116)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.ant.internal.core.AntClassLoader.loadClassPlugins(AntClassLoader.java:69)
at org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:47)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.createLogger(InternalAntRunner.java:747)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.addBuildListeners(InternalAntRunner.java:202)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:572)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:498)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:378)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:475)
After banging my head over this I finally found the solution:
The AntLogger class cannot be part of the plugin project.
I moved the AntLogger to a different java project named it EclipseAntLogger, then I added the project jar to the plugin extension point like this:
<extension
point="org.eclipse.ant.core.extraClasspathEntries">
<extraClasspathEntry
library="lib/EclipseAntLogger.jar">
</extraClasspathEntry>
</extension>
Does it help to add ant.jar and other necessary jars to the AntRunner instance?
public void setCustomClasspath(URL[] customClasspath)
#wildstabinthedark

Resources