Spring Authorization Server 0.3.1 problem registering several RegisteredClientRepository - spring-security

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));
}

Related

Error in returning Generic Record in spring cloud stream

I am trying a transformer in spring cloud stream to consume a json and generate an avro schema record. Can you give me an idea as to what is the right way to right this?
After following all the documentation I wrote the following transformer
#Bean
public Function<String, GenericRecord> transformMaestroDirectSearchRequest() {
return value -> {
try {
GenericRecord genericRecord = TransformJsonToAvro.convertJsonToAvro(
value, transformJsonToAvro.getMaestroDirectSearchSchema());
return genericRecord;
} catch (Exception e){
e.printStackTrace();
return null;
}
};
}
But I keep getting this error when I run the integration test
nested exception is org.springframework.messaging.converter.MessageConversionException: Could not write JSON: Not an enum:
#Test
public void maestroSearchRequestTransformTest() throws IOException, URISyntaxException {
GenericMessage<byte[]> inputMessage =
new GenericMessage<>(Utils.getJsonFile("Maestro_direct_Req.json").getBytes());
this.input.send(inputMessage);
Message<byte[]> receive = this.output.receive();
System.out.println(receive.getPayload());
}
Any ideas on how I can resolve this?
I have already verified that the conversion logic for creating the GenericRecord works well, and there is nothing wrong there (i.e. a valid GenericRecord Object is generated)
Here is the full stack trace
2020-11-18 13:36:31.112 ERROR 89354 --- [ main] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessageHandlingException: error occurred during processing message in 'MethodInvokingMessageProcessor' [org.springframework.integration.handler.MethodInvokingMessageProcessor#16fc5622]; nested exception is org.springframework.messaging.converter.MessageConversionException: Could not write JSON: Not an enum: {"type":"record","default":"null"}]}],"default":"null"}]} (through reference chain: org.apache.avro.generic.GenericData$Record["schema"]->org.apache.avro.Schema$RecordSchema["enumSymbols"])
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertToInternal(MappingJackson2MessageConverter.java:289)
at org.springframework.cloud.stream.converter.ApplicationJsonMessageMarshallingConverter.convertToInternal(ApplicationJsonMessageMarshallingConverter.java:69)
at org.springframework.messaging.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:198)
at org.springframework.cloud.function.context.config.NegotiatingMessageConverterWrapper.toMessage(NegotiatingMessageConverterWrapper.java:125)
at org.springframework.cloud.function.context.config.NegotiatingMessageConverterWrapper.toMessage(NegotiatingMessageConverterWrapper.java:139)
at org.springframework.messaging.converter.CompositeMessageConverter.toMessage(CompositeMessageConverter.java:83)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.convertValueToMessage(SimpleFunctionRegistry.java:705)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.convertOutputValueIfNecessary(SimpleFunctionRegistry.java:667)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:600)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:443)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:431)
at org.springframework.cloud.stream.function.PartitionAwareFunctionWrapper.apply(PartitionAwareFunctionWrapper.java:71)
at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionWrapper.apply(FunctionConfiguration.java:609)
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.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:129)
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:112)
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55)
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:117)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:375)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:171)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:156)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeExpression(MessagingMethodInvokerHelper.java:637)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.fallbackToInvokeExpression(MessagingMethodInvokerHelper.java:630)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInvokeExceptionAndFallbackToExpressionIfAny(MessagingMethodInvokerHelper.java:614)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:585)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:477)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:355)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:108)
... 93 more
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Not an enum: {"type":"record",..... removed real json ,"default":"null"}]}],"default":"null"}]} (through reference chain: org.apache.avro.generic.GenericData$Record["schema"]->org.apache.avro.Schema$RecordSchema["enumSymbols"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:397)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:356)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:763)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3058)
at org.springframework.messaging.converter.MappingJackson2MessageConverter.convertToInternal(MappingJackson2MessageConverter.java:271)
... 125 more
Caused by: org.apache.avro.AvroRuntimeException: Not an enum: {"type":"record",... removed real json...."default":"null"}]}],"default":"null"}]}
at org.apache.avro.Schema.getEnumSymbols(Schema.java:206)
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 com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755)
... 133 more

Unable to connect to aws-iot using paho-mqtt java client code

I created thing on AWS core. Then downloaded cert, private key and rootCa certificate too. My main goal is to publish and subscribe to AWS shadow so that I can automate my home lighting system.
I tried to connect to aws iot using paho mqtt java client code, using following code.
package test.pub;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMDecryptorProvider;
import org.bouncycastle.openssl.PEMEncryptedKeyPair;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
public class App {
public static void main(String[] args) {
String serverUrl = "ssl://xxxxxxxx.iot.us-east-
1.amazonaws.com:8883";
String caFilePath = "ca1.pem";
String clientCrtFilePath = "thing.cert.pem";
String clientKeyFilePath = "thing.private.key";
MqttClient client;
try {
client = new MqttClient(serverUrl, MqttClient.generateClientId());
MqttConnectOptions options = new MqttConnectOptions();
options.setConnectionTimeout(60);
options.setKeepAliveInterval(60);
options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1);
SSLSocketFactory socketFactory = getSocketFactory(caFilePath,
clientCrtFilePath, clientKeyFilePath, "");
options.setSocketFactory(socketFactory);
System.out.println("starting connect the server...");
client.connect(options);
System.out.println("connected!");
Thread.sleep(1000);
client.subscribe(
"test",
0);
client.disconnect();
System.out.println("disconnected!");
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
private static SSLSocketFactory getSocketFactory(final String caCrtFile,
final String crtFile, final String keyFile, final String password)
throws Exception {
Security.addProvider(new BouncyCastleProvider());
// load CA certificate
X509Certificate caCert = null;
FileInputStream fis = new FileInputStream(caCrtFile);
BufferedInputStream bis = new BufferedInputStream(fis);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
while (bis.available() > 0) {
caCert = (X509Certificate) cf.generateCertificate(bis);
// System.out.println(caCert.toString());
}
// load client certificate
bis = new BufferedInputStream(new FileInputStream(crtFile));
X509Certificate cert = null;
while (bis.available() > 0) {
cert = (X509Certificate) cf.generateCertificate(bis);
// System.out.println(caCert.toString());
}
// load client private key
PEMParser pemParser = new PEMParser(new FileReader(keyFile));
Object object = pemParser.readObject();
PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder()
.build(password.toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter()
.setProvider("BC");
KeyPair key;
if (object instanceof PEMEncryptedKeyPair) {
System.out.println("Encrypted key - we will use provided password");
key = converter.getKeyPair(((PEMEncryptedKeyPair) object)
.decryptKeyPair(decProv));
} else {
System.out.println("Unencrypted key - no password needed");
key = converter.getKeyPair((PEMKeyPair) object);
}
pemParser.close();
// CA certificate is used to authenticate server
KeyStore caKs = KeyStore.getInstance(KeyStore.getDefaultType());
caKs.load(null, null);
caKs.setCertificateEntry("ca-certificate", caCert);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(caKs);
// client key and certificates are sent to server so it can authenticate
// us
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
ks.setCertificateEntry("certificate", cert);
ks.setKeyEntry("private-key", key.getPrivate(), password.toCharArray(),
new java.security.cert.Certificate[] { cert });
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
.getDefaultAlgorithm());
kmf.init(ks, password.toCharArray());
// finally, create SSL socket factory
SSLContext context = SSLContext.getInstance("TLSv1.2");
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return context.getSocketFactory();
}
}
I am getting following console log and error
Unencrypted key - no password needed
starting connect the server...
Unable to connect to server (32103) - java.net.ConnectException: Connection timed out: connect
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:82)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:590)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
... 3 more
please help me to connect to aws IOT so that i can update shadow or atleast pub/sub to topics.

ClassCastException while trying to access MBeans

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...

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