Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
21139c8
SAX parser, namespace issue
4everalone Sep 3, 2013
8498b46
fixing SAX handler startElement
4everalone Sep 6, 2013
ae77f84
parsing 'Fault' element from soap response
4everalone Sep 6, 2013
c5d4761
bug with AnyElement exception in SAX parser
4everalone Sep 6, 2013
d143a39
Custom timezone transformation
4everalone Sep 19, 2013
4d82c6f
Any element for SAX parser. It is represents an object with a String …
4everalone Nov 6, 2013
ab4cd84
Handling xml response
4everalone Jan 22, 2014
4719d40
Fixes List object annotated with AnyElement
4everalone Dec 15, 2014
83b9664
Fixes weak reference for temporary buffer which contains an answer st…
4everalone Dec 16, 2014
5069d44
Changes inner namespace to 'n', serializes empty strings
4everalone Dec 18, 2014
218cd4f
adding encrypted attribute
Sep 2, 2015
2216f10
Revert "adding encrypted attribute"
Sep 2, 2015
ffa1362
adding encrypted attribute
Sep 2, 2015
1545c9d
correcting unit testing exceptions
Sep 2, 2015
ef5f879
added the ability to transform certain fields when serializing/de-ser…
Sep 14, 2015
60b4247
Correct decryption of elements which have @Value annotation
Sep 16, 2015
fab4cf4
Fixing bugs in Base64 encode
Sep 23, 2015
eeaa832
fixed bug with the attempt to decrypt empty values
May 16, 2016
69f96c7
change version to 0.7.2-snapshot
May 16, 2016
e2b42ec
compression of SOAP requests, increased version to 0.7.3
Dec 19, 2018
49752fb
Adding several namespaces support in one wsdl, adding support of time…
Feb 5, 2020
76a0ad0
comment javadoc because it fails. restore original repository
Feb 5, 2020
4263e84
get headers as Map, not as string
Feb 14, 2020
c0df137
Increasing GZIP inputstream buffer in hope to increase performance on…
Aug 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ target
.settings
.project
.classpath
repo
b.bat
codecover/
47 changes: 40 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.leansoft</groupId>
<artifactId>nano</artifactId>
<version>0.7.1-SNAPSHOT</version>
<version>0.7.7-SNAPSHOT</version>
<packaging>jar</packaging>

<name>nano</name>
Expand Down Expand Up @@ -34,15 +34,39 @@
</roles>
</developer>
</developers>
<repositories>
<repository>
<id>central</id>
<url>http://nexus:8081/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://nexus:8081/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>github.release.repo</id>
<id>local.release.repo</id>
<name>Release Repository</name>
<url>file:///dev/bulldog-repo/repo/releases</url>
</repository>
<snapshotRepository>
<id>github.snapshot.repo</id>
<id>local.snapshot.repo</id>
<name>Snapshot Repository</name>
<url>file:///dev/bulldog-repo/repo/snapshots</url>
</snapshotRepository>
Expand All @@ -56,15 +80,22 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.12</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.3</version>
<type>jar</type>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -105,13 +136,15 @@
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

<plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
Expand All @@ -131,7 +164,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin> -->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leansoft/nano/NanoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static IWriter getXMLWriter() {
* @return an instance of IWriter implementation
*/
public static IWriter getXMLWriter(Format format) {
return new XmlPullWriter(format);
return new XmlPullWriter(format, false);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/leansoft/nano/annotation/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,26 @@
* @return true or false
*/
public boolean data() default false;

/**
* Indicates if the string content of the field should
* be encrypted
*
* @return true or false
*/
public boolean encrypted() default false;

/**
* Comma separated list of fields.
* Indicates what fields inside the structure we need to encrypt.
* Typically used when you have structure generated out of wsdl
* and can not add annotation to the needed fields inside the structure
* @return list of field names
*/
public String sub_fields_to_encrypt() default "";

/**
* namespace for the field
*/
public String namespace() default "";
}
3 changes: 3 additions & 0 deletions src/main/java/com/leansoft/nano/annotation/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
* @return true or false
*/
public boolean data() default false;

public boolean encrypted() default false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,36 @@ public class ElementSchema {

private boolean list = false;

private boolean encrypted = false;

private String[] subfiledsToEncrypt = new String[0];

private Class<?> parameterizedType;

public boolean isEncrypted() {
return encrypted;
}

public void setEncrypted(boolean encrypted) {
this.encrypted = encrypted;
}

public boolean needToEncryptSubField(String fieldName)
{
for (String t: subfiledsToEncrypt)
{
if (t.equals(fieldName))
{
return true;
}
}
return false;
}

public void setSubFieldsToEncrypt(String[] fields)
{
this.subfiledsToEncrypt = fields;
}
/**
* Check if this is a java.util.List filed, such as List<T>
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/leansoft/nano/annotation/schema/ValueSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ValueSchema {

private Field field;

private boolean encrypted;

/**
* Indicates if the string content of the field should be put
* in a CDATA container on serialization
Expand Down Expand Up @@ -51,5 +53,15 @@ public Field getField() {
public void setField(Field field) {
this.field = field;
}

public void setEncrypted(boolean encrypted)
{
this.encrypted = encrypted;
}

public boolean isEncrypted()
{
return this.encrypted;
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/leansoft/nano/custom/types/AnyObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.leansoft.nano.custom.types;

import java.io.Serializable;

public class AnyObject implements Serializable
{
private static final long serialVersionUID = -1L;

public String content;
}
15 changes: 15 additions & 0 deletions src/main/java/com/leansoft/nano/impl/MappingSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class MappingSchema {
// use LRU cache to limit memory consumption.
private static Map<Class<?>, MappingSchema> schemaCache = Collections.synchronizedMap(new LRUCache<Class<?>, MappingSchema>(CACHE_SIZE));

public static void clearCaches()
{
schemaCache.clear();
}

private MappingSchema(Class<?> type) throws MappingException {
this.type = type;

Expand Down Expand Up @@ -173,6 +178,15 @@ public int compare(Field field1, Field field2) {
elementSchema.setXmlName(xmlElement.name());
}

if (xmlElement.encrypted())
{
elementSchema.setEncrypted(true);
}

if (!xmlElement.sub_fields_to_encrypt().isEmpty())
{
elementSchema.setSubFieldsToEncrypt(xmlElement.sub_fields_to_encrypt().split(","));
}
// List validation
handleList(field, elementSchema);

Expand Down Expand Up @@ -214,6 +228,7 @@ public int compare(Field field1, Field field2) {

valueSchema = new ValueSchema();
valueSchema.setData(xmlValue.data());
valueSchema.setEncrypted(xmlValue.encrypted());
valueSchema.setField(field);

} else if (field.isAnnotationPresent(AnyElement.class)) {
Expand Down
68 changes: 63 additions & 5 deletions src/main/java/com/leansoft/nano/impl/SOAPWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
import org.xmlpull.v1.XmlSerializer;

import com.leansoft.nano.Format;
import com.leansoft.nano.annotation.Element;
import com.leansoft.nano.annotation.schema.ElementSchema;
import com.leansoft.nano.annotation.schema.RootElementSchema;
import com.leansoft.nano.exception.MappingException;
import com.leansoft.nano.exception.WriterException;
import com.leansoft.nano.util.StringUtil;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

public class SOAPWriter extends XmlPullWriter {

Expand All @@ -17,13 +25,16 @@ public class SOAPWriter extends XmlPullWriter {
static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
static final String XSD_PREFIX = "xsd";
static final String XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
static final String INNER_PREFIX = "n"; //tg fix

private boolean qualifiedFromDefault = false;;

public SOAPWriter() {
super();
}

public SOAPWriter(Format format) {
super(format);
public SOAPWriter(Format format, boolean qualifiedFromDefault) {
super(format, qualifiedFromDefault);
}


Expand Down Expand Up @@ -57,14 +68,17 @@ public void write(Object source, Writer out) throws WriterException, MappingExce
serializer.setPrefix(SOAP_PREFIX, namespace);
serializer.setPrefix(XSI_PREFIX, XSI_NAMESPACE);
serializer.setPrefix(XSD_PREFIX, XSD_NAMESPACE);


// set default namespace without prefix
String innerNamespace = this.findInnerClassNamespace(source);
if (!StringUtil.isEmpty(innerNamespace)) {
if (serializer.getPrefix(innerNamespace, false) == null) {
serializer.setPrefix("", innerNamespace);
serializer.setPrefix(qualifiedFromDefault ? "" : INNER_PREFIX, innerNamespace); //tg fix
// serializer.setPrefix("", innerNamespace); //tg fix
}
}
this.addAllInnerNamespacesToPrefix(serializer, source);

serializer.startTag(namespace, xmlName);
this.writeObject(serializer, source, namespace);
Expand All @@ -80,7 +94,7 @@ public void write(Object source, Writer out) throws WriterException, MappingExce
}
}

private String findInnerClassNamespace(Object obj) throws MappingException {
private Object getInnerObjectFromEnvelope(Object obj) throws MappingException {
Object innerObject = null;
if (obj instanceof com.leansoft.nano.soap11.Envelope) {
com.leansoft.nano.soap11.Envelope envelope = (com.leansoft.nano.soap11.Envelope)obj;
Expand All @@ -95,7 +109,12 @@ private String findInnerClassNamespace(Object obj) throws MappingException {
innerObject = body.any.get(0);
}
}

return innerObject;
}


private String findInnerClassNamespace(Object obj) throws MappingException {
Object innerObject = getInnerObjectFromEnvelope(obj);
if (innerObject != null) {
MappingSchema ms = MappingSchema.fromObject(innerObject);
RootElementSchema res = ms.getRootElementSchema();
Expand All @@ -106,4 +125,43 @@ private String findInnerClassNamespace(Object obj) throws MappingException {
return null;
}

private void gatherAllInnerNamespaces(MappingSchema ms, Set<String> foundNamespaces, Set<String> processedClasses) throws MappingException
{
processedClasses.add(ms.getType().getCanonicalName());//to prevent recursive call for the same class
for (Map.Entry<String,Object> entry : ms.getField2SchemaMapping().entrySet()) {
if (entry.getValue() instanceof ElementSchema) {
ElementSchema elemSchema = (ElementSchema)entry.getValue();
Element elemenAnnotation = elemSchema.getField().getAnnotation(Element.class);
if (!StringUtil.isEmpty(elemenAnnotation.namespace())) {
foundNamespaces.add(elemenAnnotation.namespace().intern());
}
if (elemSchema.getParameterizedType() != null &&
!processedClasses.contains(elemSchema.getParameterizedType().getCanonicalName())) {
gatherAllInnerNamespaces(MappingSchema.fromClass(elemSchema.getParameterizedType()), foundNamespaces, processedClasses);
processedClasses.add(elemSchema.getParameterizedType().getCanonicalName());
} else
if (!processedClasses.contains(elemSchema.getField().getType().getCanonicalName())) {
gatherAllInnerNamespaces(MappingSchema.fromClass(elemSchema.getField().getType()), foundNamespaces, processedClasses);
processedClasses.add(elemSchema.getField().getType().getCanonicalName());
}
}
}
}

private void addAllInnerNamespacesToPrefix(XmlSerializer serializer, Object obj) throws MappingException, IOException {
Object innerObject = getInnerObjectFromEnvelope(obj);
if (innerObject != null) {
LinkedHashSet<String> foundNamespaces = new LinkedHashSet<String>();
HashSet<String> processedClasses = new HashSet<String>();

MappingSchema ms = MappingSchema.fromObject(innerObject);
gatherAllInnerNamespaces(ms, foundNamespaces, processedClasses);
int nsNum=1;
for (String ns: foundNamespaces) {
serializer.setPrefix("n"+nsNum, ns);
nsNum++;
}
}
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/leansoft/nano/impl/UtCacheHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.leansoft.nano.impl;

public class UtCacheHelper
{
public static void clearCaches()
{
MappingSchema.clearCaches();
}

}
Loading