How to XSLT using SaxonEE - xslt

I am using SaxonEE integration in the Java application to do XML transformation. I am getting the following error.
Exception in thread "JavaFX Application Thread" javax.xml.transform.TransformerFactoryConfigurationError: Provider com.saxonica.config.EnterpriseTransformerFactory could not be instantiated: java.lang.SecurityException: class "net.sf.saxon.Configuration$ApiProvider"'s signer information does not match signer information of other classes in the same package
Please note that the same code is working well with the SaxonHE version. Please advise on how to solve the issue. Thanks in advance.
System.setProperty("javax.xml.transform.TransformerFactory", "com.saxonica.config.EnterpriseTransformerFactory");
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslt = new StreamSource(new StringReader(XSLTString));
Transformer transformer = factory.newTransformer(xslt);
StringWriter buffer = new StringWriter();
transformer.transform(new DOMSource(MainApp.XMLDocument), new StreamResult(buffer));
Exception in thread "JavaFX Application Thread" javax.xml.transform.TransformerFactoryConfigurationError: Provider com.saxonica.config.EnterpriseTransformerFactory could not be instantiated: java.lang.SecurityException: class "net.sf.saxon.Configuration$ApiProvider"'s signer information does not match signer information of other classes in the same package

Related

Amazon SES - Connection

I'm trying to create a template on SES sandbox version. I use the following code but I'm getting the following error. Please help me fix this.
BasicAWSCredentials basicCreds = new BasicAWSCredentials("AXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXi");
AmazonSimpleEmailService client = null;
try{
client = AmazonSimpleEmailServiceClientBuilder.standard().withRegion(Regions.US_WEST_2).withCredentials(new AWSStaticCredentialsProvider(basicCreds)).build();
} catch (Exception ex){
logger.info(ex);
}
CreateTemplateRequest ctr = new CreateTemplateRequest();
Template template = new Template();
template.setTemplateName("Sample");
template.setSubjectPart("Sample Mail");
template.setTextPart("Test Mail from Template");
ctr.setTemplate(template);
client.createTemplate(ctr);
and the exception that I get is,
Exception in thread "main" java.lang.NoSuchFieldError: SIGNING_REGION
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.executeCreateTemplate(AmazonSimpleEmailServiceClient.java:950)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.createTemplate(AmazonSimpleEmailServiceClient.java:932)
We are using ant build. If there is a jar problem please let me know which version of the jar I should be using.
Thanks in advance.

servlet connect to solr using solrj

I want my servlet to establish a connection with solr so as to perform query. using eclipse I have created a simple JSP file for the user to input their query, then it will call the doGet() method from the servlet. From the servlet i try to use solrj to connect with solr
my solrj code is as below.
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
SolrQuery query = new SolrQuery();
query.setQuery("sony digital camera");
query.addFilterQuery("cat:electronics","store:amazon.com");
query.setFields("id","price","merchant","cat","store");
query.setStart(0);
query.set("defType", "edismax");
QueryResponse response = solr.query(query);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
Its basically just simple code available online, there is no syntax error which means that the program detects the library files. However on run time the program returns classNotFoundException error.
This prompt me thinking whether i can implement solrj on servlet. Anyone can advise me where i can exactly use the solrj code? I think that the code is right but just that i implement solrj wrongly.
Thanks in advance!
The exception is saying that your runtime classpath is wrong.
Assuming you're running this class in a servlet container, most probably what you're missing is not a Java EE jar but instead has something to do with SolrJ.
Solrj has few dependencies: you can find them in the Solr distribution or if you have confidence with Apache Maven, you can use it for individuating those jars.
In any case, once you identified those libraries, you have to put them under WEB-INF/lib of your webapp
For a list of dependencies you can read here: http://mvnrepository.com/artifact/org.apache.solr/solr-solrj/4.10.3

JAX-WS web service with Source return type on Websphere

I am migrating an old JAX-WS 2.1 web service from JBoss 4 to Websphere 7. Most of the #WebMethod components all look like this:
#WebMethod
public Source someMethod(){
Source source = null;
try{
source = ServiceActions.someMethodWorker();
}
catch( Throwable throwable ){
source = ServiceActions.handleThrowable("Error occured in method someMethod", throwable );
}
return source;
}
ServiceActions.someMethodWorker() usually goes off and fetches that data populates a JAXB structure, marshalls into XML and returns a StreamSource of the XML like this:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JAXBContext jc = JAXBContext.newInstance();
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(someJaxBObjectHierarchy, byteArrayOutputStream);
return new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
This web service runs just fine on JBoss 4 (with the Jax-WS and JaxB libraries) and GlassFish 3.1, but Websphere 7 keeps giving me the following error any time I use a client against the web service:
javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class javax.xml.transform.stream.StreamSource nor any of its super class is known to this context.]
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
At first look this seems to be the JAXB type binding problem; however, I've added #XmlSeeAlso(StreamSource.class) everywhere, and I still get the error.
Would someone know why this is failing on WebSphere 7?
Thanks!
Edit/Solution: The solution is to use byte[] return type instead of Source
GlassFish and JBoss were doing something extra compared to the JAX-WS specification which led me to believe that Source return type was OK.
Instead of my methods returning new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) they now just return byteArrayOutputStream.toByteArray()
javax.xml.transform.Source is not a valid return type for a normal JAX-WS service endpoint interface (SEI). If you want to do that (and be compliant with JAX-WS) you need to use a service that is implemented as a javax.xml.ws.Provider (see the corresponding docs). If JBoss or GlassFish support Source as a parameter or return type in a normal SEI, then that's a proprietary extension.

Getting started with embedded Jetty

I just got started with embedded jetty. I'm stuck at some error messages. It's simple and straightforward few lines code, which I found online and wanted to test out.
import org.jaxen.Context;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.ServletHolder;
public class Main {
public static void main(String[] args) throws Exception {
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter("com.sun.jersey.config.property.packages", "jerseyplusjetty");
Server server = new Server(80);
ServletContextHandler sch = new ServletContextHandler(server, "/");
sch.addServlet(sh, "/*");
server.start();
server.join();
}
}
I have all jetty jars in java build path. But I kept getting errors: The constructor ServletHolder(Class) is undefined, The constructor Server(int) is undefined, ServletContextHandler cannot be resolved to a type.
If I remove the parameter inside ServletHolder and Server, it stops complaining. e.g. if I have: ServletHolder sh = new ServletHolder(); Server server = new Server();
But that's not right. I read Jetty docs and ServletHolder class can take parameters. Am I missing something here?
Just FYI on embedded Jetty in general... I have created a github project that I humbly submit may cover most of the embedded jetty issues that keep cropping up.
I've got examples for AbstractHandlers, Servlets, Jersey Servlets, static files, webapps and what not. Still working on RoR and Sinatra, but will get there.
See https://github.com/ZenGirl/EmbeddedJettyRepository for details.
Anyone want to contribute, just ask.
The version of ServletHolder I have takes a String or a servlet in the constructor. So instead of doing
new ServletHolder(ServletContainer.class) you should do new ServletHolder(ServletContainer.class.getCanonicalName()) or new ServletHolder(new ServletContainer()).
ServletContainer is a strange name for a servlet, make sure it is actually a servlet.
Also, be aware that there are number of different versions of Jetty (you're using an old one because in the new one all the classes are in org.eclipse.jetty package), and it's easy to pick up example code that refers to a different version to the one you've got. I would get jetty 7.2.2 from maven and use the example code here.

Complex Object in JAX-WS is created empty

I'm testing JAX-WS to access the Oracle IRM web serviecs. I can get it to work just fine with AXIS so this isn't an Oracle problem.
What's happening is that I'm getting the following error when making the call:
Expected xsd:anyType - unknown type provided
If I look at the SOAP packet is sent I see that the owner tag is blank under JAX-WS:
<ns1:browseAccounts>
<owner/>
<accountType>All</accountType>
</ns1:browseAccounts>
The same piece under AXIS is this:
<owner xsi:type="ns1:LicenseServer"
xmlns=""
xmlns:ns1="http://www.sealedmedia.com/ls/server/schema">
<serverKey>#############</serverKey>
</owner>
Obviously the owner tag is not getting properly created, this is what I'm using to create that:
AccountServicesPort AA = ORI.getAccountServices();
LicenseServer LicSer = new LicenseServer();
LicSer.setServerKey("#######################");
List<Account> Acts = AA.browseAccounts(LicSer,AccountAccountType.ALL);
Is there some other process that I need to go through to create the object properly?
EDIT
I thought maybe running the LicenseServer creation through ObjectFactory would help. Unfortunately, it doesn't.
Despite the Oracle IRM documentation stating that BrowseAccounts accepts either a LicenseServer object or a Context object for the owner parameter it actually accepts an LicenseServer_ref.
EDIT
Further, I was running JAX-WS under JDK 1.6.0 which is a lower version than JDK 1.6.0_14. The new version supports XMLSeeAlso annotation which allowed JAX-WS to use the proper class for serialization.