-
-
Save cfalzone/18ca0945b54d9c1fb656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aquent.osgi; | |
import java.util.Calendar; | |
import java.util.GregorianCalendar; | |
import java.util.List; | |
import javax.xml.datatype.DatatypeFactory; | |
import javax.xml.datatype.XMLGregorianCalendar; | |
import javax.xml.soap.MessageFactory; | |
import com.aquent.AquentUtil; | |
import com.aquent.ws.JobPostingServiceClient; | |
import com.aquent.ws.PostedJobs; | |
import com.aquent.ws.PostedJobsResponse; | |
import com.dotcms.repackage.org.osgi.framework.BundleContext; | |
import com.dotmarketing.util.Logger; | |
import org.apache.axis2.saaj.MessageFactoryImpl; | |
import org.springframework.oxm.jaxb.Jaxb2Marshaller; | |
import org.springframework.ws.client.core.WebServiceTemplate; | |
import org.springframework.ws.soap.SoapVersion; | |
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory; | |
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; | |
import org.springframework.ws.transport.http.HttpComponentsMessageSender; | |
public class AquentActivator extends ExtendedBundleActivator { | |
@Override | |
public void start ( BundleContext ctx ) throws Exception { | |
// Initializing services | |
initializeServices(ctx); | |
publishBundleServices(ctx); | |
// Test job importer | |
String cwDomain = AquentUtil.getInstance().getCWDomain(); | |
String serviceUri = "https://" + cwDomain + "/AQWS/JobPostingService"; | |
try { | |
// Create a message factory for the job service | |
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory(); | |
messageFactory.setPayloadCaching(true); | |
// Create the marshaller for the job service | |
Jaxb2Marshaller jobPostingServiceMarshaller = new Jaxb2Marshaller(); | |
jobPostingServiceMarshaller.setContextPath("com.aquent.ws"); | |
// Cerate a message factory for the job service | |
MessageFactory factory = new MessageFactoryImpl(); | |
SaajSoapMessageFactory jobPostingServiceMessageFactory = new SaajSoapMessageFactory(factory); | |
jobPostingServiceMessageFactory.setSoapVersion(SoapVersion.SOAP_11); | |
// Create the template for the job service | |
WebServiceTemplate jobPostingServiceTemplate = new WebServiceTemplate(messageFactory); | |
jobPostingServiceTemplate.setMarshaller(jobPostingServiceMarshaller); | |
jobPostingServiceTemplate.setUnmarshaller(jobPostingServiceMarshaller); | |
jobPostingServiceTemplate.setMessageSender(new HttpComponentsMessageSender()); | |
jobPostingServiceTemplate.setDefaultUri(serviceUri); | |
jobPostingServiceTemplate.setMessageFactory(jobPostingServiceMessageFactory); | |
// Get a new Job Posting Service Client | |
JobPostingServiceClient jobsService = new JobPostingServiceClient(); | |
jobsService.setWebServiceTemplate(jobPostingServiceTemplate); | |
// Set up the parameters for the call | |
Calendar cal = Calendar.getInstance(); | |
cal.add(Calendar.HOUR_OF_DAY, -1); | |
GregorianCalendar gc = new GregorianCalendar(); | |
gc.setTimeInMillis(cal.getTimeInMillis()); | |
XMLGregorianCalendar calHours = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); | |
// get the results from the soap service | |
PostedJobsResponse jobsResponse = jobsService.getAllPostedJobs(serviceUri, calHours).getPostedJobs(); | |
List<PostedJobs> results = jobsResponse.getPostedJob(); | |
Logger.info(this, "Got Jobs: "+results.size()); | |
} catch (Exception e) { | |
Logger.error(this, "Exception testing web service client", e); | |
} | |
} | |
@Override | |
public void stop ( BundleContext ctx ) throws Exception { | |
// Unregister all the bundle services | |
unregisterServices( ctx ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment