Replacement of LdapURL class in java 11 - ldap

I was using LdapURL class like below using Java 8, now I have upgraded to java 11 so I need replacement of this class.
LdapURL ldapURL = new LdapURL(ldapDomain);
if (!ldapURL.useSsl()) {
profiles.add("non-secure-LDAP");
} else {
profiles.add("secure-LDAP");
}
Could someone help.

Related

jOOQ Custom Pojo & DAO Generation

Problem
I'm having some issues configuring mapping to custom Pojos during code generation.
Question
I have implemented RecordMapperProvider but wondering how I register it to be used during the code generation phase, or even if that is possible?
More Context
I love the fact that Pojos & DAOs are generated but I want to define the Pojo myself without too much configuration code. I am using ModelMapper to map from Type to Target:
#Override
public <R extends Record, E> RecordMapper<R, E> provide(RecordType<R> recordType,
Class<? extends E> type) {
if (mapping.containsKey(type)) {
return record -> modelMapper.map(mapping.get(type), type);
}
return new DefaultRecordMapper<>(recordType, type);
}
If it helps, I am configuring jOOQ using a DefaultConfiguration object (which is a bean):
#Bean
public DefaultConfiguration configuration() {
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
jooqConfiguration.setConnectionProvider(dataSourceConnectionProvider());
jooqConfiguration.setExecuteListenerProvider(new DefaultExecuteListenerProvider(
jooqToSpringExceptionTranslator()));
jooqConfiguration.setSQLDialect(
SQLDialect.valueOf(env.getRequiredProperty("jooq.sql.dialect")));
jooqConfiguration.setRecordMapperProvider(new JooqRecordMapperFactory(modelMapper()));
return jooqConfiguration;
}
And then for Code Generation I am configuring it in gradle:
jooq {
version = '3.10.5'
edition = 'OSS'
myDb(sourceSets.getByName("main")) {
jdbc {
driver = dbDriver
url = dbUrl
user = dbUsername
}
generator {
name = 'org.jooq.util.JavaGenerator'
strategy {
name = 'org.jooq.util.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.util.postgres.PostgresDatabase'
inputSchema = dbSchema
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
daos = true
}
target {
packageName = 'com.textiq.quinn.common.dao.model.generated'
}
}
}
}
I am sure there is a disconnect here between both configurations but I can't glean from the documentation how I synch these. Ideally I want jOOQ to generate Pojos (based on the mapping that ModelMapper provides in my implementation of RecordMapperProvider) and also have jOOQ provide the DAO's for these Pojos. Is this possible? The documentation states:
If you're using jOOQ's code generator, you can configure it to generate POJOs for you, but you're not required to use those generated POJOs. You can use your own. See the manual's section about POJOs with custom RecordMappers to see how to modify jOOQ's standard POJO mapping behaviour.
Source: https://www.jooq.org/doc/3.9/manual/sql-execution/fetching/pojos/
Which to me indicates the possibility of this but only leads me to implementing RecordMapperProvider and nothing after that.
I have implemented RecordMapperProvider but wondering how I register it to be used during the code generation phase, or even if that is possible?
No, it's not possible, out of the box.
I love the fact that Pojos & DAOs are generated but I want to define the Pojo myself without too much configuration code
Then, I suggest turning off the generation of POJOs and DAOs and roll your own. Either, create manual implementations of DAOs, or extend the JavaGenerator to do so.
I'm a few years late to the party, but I actually found a very simple way to do this. I'll admit that it's a little brittle, but you can refine it further to suit your needs.
Create a new module in your gradle project, for example called jooq-generator
Add jooq-codegen as a compileOnly dependency to the module
Create a new class in the module:
public class Generator extends JavaGenerator {
#Override
public boolean generatePojos() {
return false;
}
}
Create a new class in the module:
public class MyGeneratorStrategy extends DefaultGeneratorStrategy {
#Override
public String getJavaPackageName(Definition definition, Mode mode) {
if (mode != Mode.POJO) {
return super.getJavaPackageName(definition, mode);
}
return "com.example.my.model.package.prefix";
}
}
Add the module as a dependency to the jooqGenerator jooqGenerator project(":jooq-generator")
Add your new classes to the jooq config
jooq {
configurations {
main {
generationTool {
generator {
name = 'com.example.my.package.name.Generator'
strategy {
name = 'com.example.my.package.name.MyGeneratorStrategy'
}
}
}
}
}
}
The daos will now be generated using that package prefix for the POJOs instead of the generated package name.

How JAXB/Jersey unmarshall Boolean values?

I have an issue with some RESTful services that takes a transfer object in parameter (basically an XML object that will be unmarshalled to a POJO).
#XmlRootElement(name = "myPojo")
public class MyPojo {
#XmlElement(name = "myField")
private Boolean myBoolean;
public void setMyBoolean(Boolean bool) {
myBoolean = bool;
}
public Boolean getMyBoolean() {
return myBoolean;
}
}
And the service is something like that:
public class MyRestService {
#PUT
#Path("somewhere")
#Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
#Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response update(MyPojo pojo) {
System.out.println("Boolean value: " + pojo.getMyBoolean();
}
}
If I post this XML fragment:
<myPojo>
<myField>false</myField>
</myPojo>
I got:
Boolean value: false
And if I post this XML fragment:
<myPojo>
<myField>FALSE</myField>
</myPojo>
I got:
Boolean value: null
I run that code under Glassfish 4 with Jersey 1.9.1 and JAXB 2.2.7. In addition, under Glassfish 2, I got a different behavior where both uppercase and lowercase are unmarshalled as expected.
So, I am really curious to know what is happening and why the marshalling of boolean is different.
Thanks in advance
I run into the same problem today where JAXB returns null when parsing "FaLsE" or "True" on a Boolean field. Unfortunately, upgrading to 2.2.7 or above (2.2.11 as of today) didn't help me. When I dig deeper into the source code, it seems that the parsing logic happens inside DatatypeConverterImpl.java. And there is no configuration that can alter its behavior on uppercase.
Link to JAXB DatatypeConverterImpl.java
The solution that I found (and works), is to define a new BooleanAdapter and asks JAXB to use that instead. In the adapter, you can define whatever conversion logic that fits your application.
Custom BooleanAdapter.java
public class BooleanAdapter extends XmlAdapter<String, Boolean> {
#Override
public Boolean unmarshal(String v) throws Exception {
if (StringUtils.isBlank(v))
return null;
return Boolean.valueOf(v);
}
#Override
public String marshal(Boolean v) throws Exception {
if (v == null)
return null;
return v.toString();
}
}
Your model object
#XmlElement(name = "myField")
#XmlJavaTypeAdapter(BooleanAdapter.class)
public Boolean getMyBoolean() {
return myBoolean;
}
After several investigations, we figured out that the version 2.2 of JAXB we are using seems to contain a bug that serialize the boolean values not as expected. I mean that for example: FaLsE will be converted to null value.
Upgrading to the version 2.2.7 has fixed our issue.

Not able to use addElement in the flash-builder class

I am trying to experiment with graphics api in flash builder.
1) The default application is "Main.as" ( not Main.mxml)
2) The application uses Spark (Not the mx package)
What i am looking at is using the function addElement to show the shape in the following code
Here is the code :
package app
{
import flash.display.Shape;
import flash.display.Sprite;
import spark.core.SpriteVisualElement;
public class Main
{
public function Main()
{
var shape:Shape =new Shape() ;
shape.graphics.lineStyle(3,0xff);
shape.graphics.moveTo(0,0);
shape.graphics.lineTo(300,300);
var sve:SpriteVisualElement = new SpriteVisualElement() ;
sve.addChild(shape);
//***********************************
addElement( sve) ;// <<< Compiler error here
//***********************************
}
}
}
Your class must extend a class that supports visual elements.
In this case, you are attempting to extend Spark Application class:
package
{
import spark.components.Application;
public class Main extends Application
{
public function Main()
{
super();
}
}
}

eclipse CDT Plugin development : How to get the class name which has a declaration

I'm developing an eclipse plugin based on CDT API.
Suppose I've following C++ code
class EventEnum
{
public:
enum e {
E_CompleteDisconnectSuccess = 1,
E_CreateBtAdapterNoSuccess = 2,
E_CreateBtAdapterSuccess = 3,
};
};
Using following ASTVisitor visitor method I can find the enum declaration
public int visit(IASTDeclaration declaration) {
if (declaration instanceof IASTSimpleDeclaration) {
IASTDeclSpecifier specifier = ((IASTSimpleDeclaration)declaration).getDeclSpecifier();
if (specifier instanceof IASTEnumerationSpecifier) {
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier)specifier;
// Get the current enumeration name
String enumerationName = enumSpecifier.getName().toString();
System.out.println("Found enum : " + enumerationName);
}
}
return PROCESS_CONTINUE;
}
Question : How can I get the class name which contains the found enum declaration, in my case it will be EventEnum ?
Found the answer on my own, probably for someone it will be usefull, so I'm posting it here
if (enumSpecifier.getParent() instanceof CPPASTSimpleDeclaration)
{
if (enumSpecifier.getParent().getParent() instanceof CPPASTCompositeTypeSpecifier)
{
CPPASTCompositeTypeSpecifier firstLevelClass = (CPPASTCompositeTypeSpecifier)enumSpecifier.getParent().getParent();
return firstLevelClass.getName().toString();
}
}

spring 3 AOP anotated advises

Trying to figure out how to Proxy my beans with AOP advices in annotated way.
I have a simple class
#Service
public class RestSampleDao {
#MonitorTimer
public Collection<User> getUsers(){
....
return users;
}
}
i have created custom annotation for monitoring execution time
#Target({ ElementType.METHOD, ElementType.TYPE })
#Retention(RetentionPolicy.RUNTIME)
public #interface MonitorTimer {
}
and advise to do some fake monitoring
public class MonitorTimerAdvice implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable{
try {
long start = System.currentTimeMillis();
Object retVal = invocation.proceed();
long end = System.currentTimeMillis();
long differenceMs = end - start;
System.out.println("\ncall took " + differenceMs + " ms ");
return retVal;
} catch(Throwable t){
System.out.println("\nerror occured");
throw t;
}
}
}
now i can use it if i manually proxy the instance of dao like this
AnnotationMatchingPointcut pc = new AnnotationMatchingPointcut(null, MonitorTimer.class);
Advisor advisor = new DefaultPointcutAdvisor(pc, new MonitorTimerAdvice());
ProxyFactory pf = new ProxyFactory();
pf.setTarget( sampleDao );
pf.addAdvisor(advisor);
RestSampleDao proxy = (RestSampleDao) pf.getProxy();
mv.addObject( proxy.getUsers() );
but how do i set it up in Spring so that my custom annotated methods would get proxied by this interceptor automatically? i would like to inject proxied samepleDao instead of real one. Can that be done without xml configurations?
i think should be possible to just annotate methods i want to intercept and spring DI would proxy what is necessary.
or do i have to use aspectj for that? would prefere simplest solution :- )
thanks a lot for help!
You haven't to use AspectJ, but you can use AspectJ annotations with Spring (see 7.2 #AspectJ support):
#Aspect
public class AroundExample {
#Around("#annotation(...)")
public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
...
}
}