JAXB unmarshalling a xml with inclusions - jaxb

I have a xml below called “TheFile.xml”
<!DOCTYPE page [
<!ENTITY class_common SYSTEM "class_common.xml" >]>
<api xmlns:denp="http://intranet.denali.com/wiki/DocBook_profiling">
&class_common;
As you can see the line above refers to another xml file called “class_common.xml” . However, when I do
cl = class_xml.ObjectFactory.class.getClassLoader();
context = JAXBContext.newInstance("class_xml", cl);
Unmarshaller u = context.createUnmarshaller();
api = (Api) u.unmarshal(new FileInputStream(classXMLFile));
I get some error like the following. Did I miss anything? Thanks
Exception in thread "main" javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 17; External Entity: Failed to read external document 'class_common.xml', because 'file' access is not allowed due to restriction set by the accessExternalDTD property.]

Ok, here is the answer, the Java code needs to be like the following
cl = class_xml.ObjectFactory.class.getClassLoader();
context = JAXBContext.newInstance("class_xml", cl);
Unmarshaller u = context.createUnmarshaller();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeAware(true);
spf.setNamespaceAware(true);
spf.setValidating(true); // Not required for JAXB/XInclude
XMLReader xr = (XMLReader) spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(new
FileInputStream(classXMLFile)));
api = (Api) u.unmarshal(source);

Related

reading XSD from file using eclipse-mdt-xsd

I'm trying to use the MSD-XSD library for parsing XSD files, but I can't figure out how to create an XSDSchema object from an XSD file, and if there's a way to also read the xs:include files, etc.
I found a way to do it. Not sure if this is the easiest way.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new FileReader(file));
Document doc = builder.parse(is);
XSDSchema xsd = XSDSchemaImpl.createSchema(doc.getFirstChild());

SOAP UI Problems to remove custom property

I'm currently trying to 'clean up' custom properties from a SOAP UI test case, using groovy script.
From this other post, I tried to do so but I'm facing a problem : I can't access the removeProperty method.
I get my data :
data = context.testCase.testSuite.getTestCaseByName("Test multi TT");
and from it I can only use a removePropertyChangeListener method.
I tried to use data.getPropertyAt() function to get a suitable object but it does not return the correct data class.
How can I get a PropertyChangeListener parameter from my custom property that I could use to remove it programmatically ?
All the posts I've been through provide answers with removeProperty and I can't find any that mentions removePropertyChangeListener
any help appreciated
EDIT: Based on the discussion over chat with OP, OP wants to remove the existing properties and add properties from external file to test case level custom properties.
Below is the Setup Script for the soapui test case. And this does the following (after discussion with OP on the chat):
Remove existing properties
Add the properties from file to test case level custom properties.
Setup Script:
//Change external properties file path as needed
def filename = 'C:/Users/apps/Documents/test.properties'
def properties = new Properties()
def propertiesFile = new File(flename)
assert propertiesFile.exists(), "$filename does not exists"
propertiesFile.withInputStream { properties.load(it) }
//Remove properties
testCase.propertyNames.collect { testCase.removeProperty(it) }
//load the properties of external file
properties.collect { k, v -> testCase.setPropertyValue(k, v) }
Here is a solution with no external file. The aim is to remove only the new properties I created for testCase purpose, in the teardown script:
import java.util.regex.Pattern
data = context.testCase.testSuite.getTestCaseByName("myTestCase");
log.info " ********************** old props ***********************"
String[] customProps = new String[data.getPropertyCount()];
customProps = data.getPropertyNames();
Pattern myRegex = ~/maProp_/ // I name my new properties with the same pattern and an index
for (propertyName in customProps){
log.info "info = " + propertyName
myMatcher = propertyName =~ /$myRegex/
if (myMatcher.count != 0){
match = myMatcher[0] == 'maProp_'
//log.info "match ? " + match // to check only my maProp_xx properties are matching
context.getTestCase().removeProperty(propertyName)
}
}
// verification
newProps = data.getPropertyNames();
log.info " ********************** new props ***********************"
for (i in newProps){
log.info "info = " +i
}

Core Data migration issue - selector error

I've added a new attribute to one of my entities, core data has migrated it and is loading the app fine, not showing the incompatible model error, but when it comes to using the new attribute i'm getting selector errors, i would assume since theres nothing there yet, how do i get it so that if theres no data it just shows an empty string.
I've tried
var string : String = "No value"
if let d : NSDate = lastTaken
{
let hours : NSNumber = hoursBetween!
let hoursAsSeconds : NSTimeInterval = hours.doubleValue * 3600
let time : NSDate = d.dateByAddingTimeInterval(hoursAsSeconds)
let formatter : NSDateFormatter = NSDateFormatter()
formatter.dateFormat = "MMM dd, HH:mm"
formatter.timeZone = NSTimeZone.defaultTimeZone()
string = formatter.stringFromDate(time)
}
return string
but it still throws the selector error. lastTaken is the new attribute
Full error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[M lastTaken]: unrecognized
selector sent to instance 0x12dd11b30'
if i edit out the if section, then the app runs and shows the no value string
It looks like you updated the Core Data model but didn't update your custom subclass of NSManagedObject. Now you're trying to access lastTaken, but the class doesn't have a property with that name. Re-generate the subclass, or add the new property to the class by hand.

Error during run OrganizationRequest 'RetrieveAllEntities'

I got this error during execute, could anyone give suggestion? Thanks
OrganizationRequest oreq = new OrganizationRequest();
oreq.RequestName = "RetrieveAllEntities";// please google for available Request Names
oreq.Parameters = new ParameterCollection();
oreq.Parameters.Add(new KeyValuePair<string, object>("EntityFilters", EntityFilters.Entity));
oreq.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", false));
OrganizationResponse respo = orgProxy.Execute(oreq);
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/xrm/2011/Contracts/Services:ExecuteResult. The InnerException message was 'Error in line 1 position 727. Element 'schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data of the 'schemas.microsoft.com/xrm/2011/Metadata:ArrayOfEntityMetadata' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfEntityMetadata' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."
Add a reference to Microsoft.Crm.Sdk.Proxy and Microsoft.Xrm.Sdk. Visual Studio may tell you that you need to add an additional couple System.* references - add them.
Use this code:
IOrganizationService service = GetCrmService(connectionString); //This is a helper, just need to setup the service
var request = new Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesRequest()
{
EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.All,
RetrieveAsIfPublished = false
};
var response = (Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesResponse)service.Execute(request);
Get it work finally there is two KnownTypeAttribute need to be added to the proxy class
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationRequest : object, System.Runtime.Serialization.IExtensibleDataObject
....
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationResponse : object, System.Runtime.Serialization.IExtensibleDataObject
Thank you for help.

Facebook Event gives error "Param eid must be a valid event id"

I am working on publish event on facebook by Facebook C# SDK. I am able to login and generate Access Token through it. But when I am publishing event I got error :
Facebook.FacebookOAuthException: (OAuthException - #100) (#100) Param eid must be a valid event id
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)
at Facebook.FacebookClient.Post(String path, Object parameters)
at FacebookSDK.Facebook.CreateEvent(FBEvent fbEvent)
My code is
public void CreateEvent(FBEvent fbEvent)
{
var fb = new FacebookClient(this.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.eid = "524654568165461";
parameters.owner = "me";
parameters.description = fbEvent.Description;
parameters.name = fbEvent.Title;
parameters.start_time = fbEvent.StartTime.ToString("yyyy-MM-dd hh:mm:ss");
parameters.end_time = fbEvent.EndTime.ToString("yyyy-MM-dd hh:mm:ss");
parameters.privacy = fbEvent.PrivacyInfo;
parameters.access_token = this.AccessToken;
dynamic result = fb.Post("me/event", parameters);
}
How i can resolve it....
Are you creating a new event? If so, delete this line from your code:
parameters.eid = "524654568165461";
If you are trying to edit an event, this eid is wrong.
After searching a lot I found the solution for it ....
You have to consider following link
asp.net + facebook create event
In my case i am trying to get data as dynamic but changed to JsonObject, it is working for me like,
JsonObject result = facebookClient.Post("/me/events", createEventParameters) as JsonObject;
I am using facebook sdk v 6.0.20

Resources