obfuscating with allatori obfuscates too much - java

I have the following config.xml file
<config>
<input>
<jar in="FVCellsPlugin-3.3.1-jcg.jar" out="obf-FVCellsPlugin-3.3.1-jcg.jar"/>
</input>
<keep-names>
<class template="class io.github.freakyville.fvcells.main.Main"/>
<class template="class regex:(?!io\.github\.freakyville).*\..*">
<field template="*"/>
<field template="static *"/>
<field template="public static *"/>
<method template="private+ *(**)"/>
<method template="private+ static *(**)"/>
</class>
<class template="private+ class regex:io\.github\.freakyville\.utilsupdated\..*"/>
</keep-names>
<property name="log-file" value="log.xml"/>
<property name="line-numbers" value="keep"/>
</config>
So I tried a few things without it working, all my code that i want obfuscated is in the package(or sub packages) io.github.freakyville(except io.github.freakyville.utilsupdated).
when the plugin is enabled I get an error java.lang.NoSuchMethodError: com.mongodb.client.model.geojson.c.iiiiiI(Ljava/lang/String;)Ljava/lang/String; which shows that it is obfuscating the class inside com.mongodb.client.model.geojson, When looking inside the jar I can see that it has obfuscated the geojson.c class https://gyazo.com/45c17157d5d7a213f14a9ecc2c12b4f6 which to me doesn't make sence as my regex (?!io\.github\.freakyville).*\..* should match that package/class path and then keep the package/class right?

Ah I figured it out, I missed the tag in the documentation(which ignores the classes matched in the obfuscating process). Adding my class templates to that and now it works

Related

Generate source files from XML

I have the XML file which starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<interface name="AccountAPING" owner="BDP" version="1.0.0" date="now()" namespace="com.betfair.account.api"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<description>Account API-NG</description>
...
afterward there are various blocks, such as:
<operation name="getDeveloperAppKeys" since="1.0.0">
<description>
Get all application keys owned by the given developer/vendor
</description>
<parameters>
<request/>
<simpleResponse type="list(DeveloperApp)">
<description>
A list of application keys owned by the given developer/vendor
</description>
</simpleResponse>
<exceptions>
<exception type="AccountAPINGException">
<description>Generic exception that is thrown if this operation fails for any reason.</description>
</exception>
</exceptions>
</parameters>
</operation>
........
<simpleType name="Status" type="string">
<validValues>
<value name="SUCCESS">
<description>Sucess status</description>
</value>
</validValues>
</simpleType>
........
<dataType name="TimeRange">
<description>TimeRange</description>
<parameter name="from" type="dateTime" mandatory="false">
<description>from, format: ISO 8601)</description>
</parameter>
<parameter name="to" type="dateTime" mandatory="false">
<description>to, format: ISO 8601</description>
</parameter>
</dataType>
How can I generate Java code from this using maven? I tried using "maven-jaxb2-plugin", but it can't parse this structure.
Please note
This is an XML file not not an xsd
I'm using Netbeans
First of all, you need the schema (xsd) that describes your xml sample. Without that schema you can not use Jaxb. You don't have a schema for the sample you shown xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is not the schema for your xml.
You can use free on-line tools to generate schemas from xml, but you can't rely on this tools without review the automated schema.
To generate Java code from a schema file use XJC, see here. Open a command prompt to the folder where you put your xsd file, and then generate java code you'll just need to type:
$ xjc nameOfSchemaFile.xsd
xjc is included with Java SDK.

Findbugs not excluding methods in our java application

I have added the following in the findbugs exclude.xml file
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Method name="getConnectionConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>
The code that needs to be ignored
public ConnectionConfig getConnectionConfig() {
return m_connectionConfig;
}
because Findbugs reports that
m_connectionConfig suffers from (inconsistent synchronization) BUG - IS2_INCONSISTENT_SYNC
But for some reason my findbugs are not getting ignored.
and when I do following -
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>
The findbugs is getting ignored for the entire class but as soon as I introduce
<Method name="getConnectionConfig">
tag in between, findbugs stops getting ignored for that method.
Can someone help me figure out why?
The IS2_INCONSISTENT_SYNC warning is issued on a data member (field), according to its usages by various methods, constructors, static blocks, etc. and not on the method itself, so you can't ignore it with a <Method> element.
Instead, you could use a <Field> element:
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Field name="m_connectionConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>

Ofbiz service creation

Starting to learn ofbiz, I am following the tutorial here:
https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guide#OFBizTutorial-ABeginnersDevelopmentGuide-SecureYourApplicationbyAuthentication
Now I am in the step to make the list form of persons editable. In this step I need to create a service which will be used for auto-fields-service. Below I give the code which I have done.
In the controller.xml of my componenent I have created a requestMaps as follows:
<request-map uri="updatePracticePerson">
<security https="true" auth="true"/>
<event type="service" invoke="updatePracticePerson"/>
<response name="success" type="view" value="personForm"/>
<response name="error" type="view" value="personForm"/>
</request-map>
Moving now to the PracticeScreens.xml i have the following for personForm:
<screen name="personForm">
<section>
<actions>
<set field="headerItem" value="personForm"/>
<set field="titleProperty" value="PageTitlePracticePersonForm"/>
<entity-condition entity-name="Person" list="persons"/>
</actions>
<widgets>
<decorator-screen name="CommonPracticeDecorator" location="${parameters.mainDecoratorLocation}">
<decorator-section name="body">
<label text="Person List" style="h2"/>
<include-form name="ListPersons" location="component://practice/widget/PracticeForms.xml"></include-form>
</decorator-section>
</decorator-screen>
</widgets>
</section>
The above includes the ListPersons from PracticeForms.xml, which I have as :
<form name="ListPersons" type="list" list-name="persons" list-entry-name="person" target="updatePracticePerson" paginate-target="personForm">
<auto-fields-service service-name="updatePracticePerson" default-field-type="edit" map-name="person"/>
<field name="partyId"><hidden/></field>
<field name="submitButton" title="Update" widget-style="smallSubmit"><submit button-type="button"/></field>
<field name="deletePracticePerson" title="Delete Person" widget-style="buttontext">
<hyperlink target="deletePracticePerson?partyId=${person.partyId}" description="${uiLabelMap.CommonDelete}" also-hidden="false"/>
</field>
<field name="submitButton" title="${uiLabelMap.CommonUpdate}"><submit button-type="button"/></field>
</form>
If you see above the ListPersons calls the service updatePracticePerson.
inside servicedef/services.xml i have the following:
<service name="updatePracticePerson" default-entity-name="Person" engine="simple"
location="component://practice/script/org/hotwax/practice/PracticeServices.xml" invoke="updatePracticePerson" auth="true">
<description>Create a Person</description>
<auto-attributes include="pk" mode="IN" optional="false"/>
<attribute name="salutation" mode="IN" type="String" optional="true"/>
<attribute name="firstName" mode="IN" type="String" optional="false"/>
<attribute name="middleName" mode="IN" type="String" optional="true"/>
<attribute name="lastName" mode="IN" type="String" optional="false"/>
<attribute name="suffix" mode="IN" type="String" optional="true"/>
</service>
In the root of my project in the file ofbiz-component.xml i have :
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
this to make sure that my service is loaded.
Although all of the above seem correct to me I get the following error :
org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen [component://common/widget/CommonScreens.xml#GlobalDecorator]: java.lang.RuntimeException: Error rendering included form named [ListPersons] at location [component://practice/widget/PracticeForms.xml]: java.lang.IllegalArgumentException: Error finding Service with name updatePracticePerson for auto-fields-service in a form widget (Error rendering included form named [ListPersons] at location [component://practice/widget/PracticeForms.xml]: java.lang.IllegalArgumentException: Error finding Service with name updatePracticePerson for auto-fields-service in a form widget)
Which obviously implies that everything is not ok and there is something wrong with my service. Could you please assist on this?
Thanks in advance,
gianis
Restart OFBiz and check the logs. During startup it will show you loading your component and then the services defined in your component. You should be able to see the problem in the logs
at the end i found the answer myself.
in the file on the root of my component ofbiz-component.xml i had:
<resource-loader name="personForm" type="component"/>
when I should have:
<resource-loader name="main" type="component"/>

Unmarshalling list of objects using castor gives java.lang.IllegalArgumentException: object is not an instance of declaring class

I'm using castor 1.3.3-rc1 and I've been puzzled with this problem. Have read the manuals few times and I believe I've done everything right here, but I keep getting :
java.lang.IllegalArgumentException: object is not an instance of declaring class{File: [not available]; line: 4; column: 43}
when unmarshalling my xml.
These are my java classes:
public class ReportConfiguration {
private List<ColumnMapping> columnMappings;
// getters and setters omitted
}
public class ColumnMapping {
private int index;
private String label;
private String sumTotal;
// getters and setters omitted
}
This is my xml data file which will be unmarshalled into java classes above
<reportConfiguration>
<columnMappings>
<columnMapping index="0" label="Login"/>
<columnMapping index="1" label="Group"/>
<columnMapping index="2" label="Profit" sumTotal="yes"/>
</columnMappings>
</reportConfiguration>
And this is my castor mapping file
<mapping>
<class name="my.company.ReportConfiguration">
<map-to xml="reportConfiguration"/>
<field name="columnMappings" collection="arraylist" type="my.company.ColumnMapping">
<bind-xml name="columnMappings"/>
</field>
</class>
<class name="my.company.ColumnMapping">
<map-to xml="columnMapping"/>
<field name="index" type="integer" required="true">
<bind-xml name="index" node="attribute"/>
</field>
<field name="label" type="string" required="true">
<bind-xml name="label" node="attribute"/>
</field>
<field name="sumTotal" type="string">
<bind-xml name="sumTotal" node="attribute"/>
</field>
</class>
</mapping>
I used Spring OXM, created a org.springframework.oxm.castor.CastorMarshaller instance on my application context, and injected an Unmarshaller instance as dependency. When unmarshalling I just do something like this:
ReportConfiguration config = (ReportConfiguration) unmarshaller.unmarshall(new StreamSource(inputStream));
Can anyone spot what did I do wrong / how else I can debug this problem ?
Ah actually I found the answer. I need to supply container="false" attribute on the castor mapping :
<field name="columnMappings" collection="arraylist" type="my.company.ColumnMapping" container="false">
<bind-xml name="columnMappings"/>
</field>
This is what castor manual says:
container Indicates whether the field should be treated as a
container, i.e. only it's fields should be persisted, but not the
containing class itself. In this case, the container attribute should
be set to true (supported in Castor XML only).
I think the default is true -- in which case castor hopes to find multiple instance of <columnMapping> directly under <reportConfiguration>, not contained inside a <columnMappings>
A more helpful error message could be presented.

Is it possible for Hibernate to use a class with no default c'tor as a component or composite-element?

I need to use some legacy classes in Hibernate. One of the classes doesn't have a default constructor so I get a "org.hibernate.InstantiationException: No default constructor for entity: .." error. I do not need to persist this class directly. Here is the mapping:
<class name="test.geo.support.Observation" table="observation">
<id access="property" column="obs_msg" name="EncodedObMsg" type="string"/>
<property name="ReportTime" column="report_time" type="long" />
<many-to-one name="Station" column="station_id" class="test.geo.Station"/>
</class>
<class name="test.geo.Station" table="station">
<id access="property" column="station_id" name="UniqueId" type="string" />
<component name="Point" class="test.geo.geometry.PointGeometry">
<property name="latitude" type="double" access="field" column="lat" />
<property name="longitude" type="double" access="field" column="lon" />
</component>
</class>
I need to persist the 'Observation' and 'Station', and want to reference the 'PointGeometry' class to persist the Station.Point. Is there any way to pull this off with 'PointGeometry' not having a default constructor?
You will always need a no argument constructor. If I really don't like no arg constructor to be called by my code, I make it protected.
No, you need a no argument constructor. Hibernate needs a way to create objects.
You might be able to create a subclass of this class, and give the subclass the no-arg constructor.
No. That is a JPA requirement. In Hibernate you can implement an Interceptor that populates the object using as desired. See:
https://stackoverflow.com/a/29433238/2108278
https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Interceptor.html

Categories