use of org.apache.cxf.jaxb.JAXBDataBinding in project tdi-studio-se by Talend.
the class NetsuiteManagement_CXF method initializeStub.
public void initializeStub() throws Exception {
URL wsdl_locationUrl = this.getClass().getResource("/wsdl/netsuite.wsdl");
QName serviceQname = new QName("urn:platform_2014_2.webservices.netsuite.com", "NetSuiteService");
NetSuiteService service = new NetSuiteService(wsdl_locationUrl, serviceQname);
NetSuitePortType port = service.getNetSuitePort();
BindingProvider provider = (BindingProvider) port;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, _url);
Preferences preferences = new Preferences();
preferences.setDisableMandatoryCustomFieldValidation(Boolean.FALSE);
preferences.setWarningAsError(Boolean.FALSE);
preferences.setIgnoreReadOnlyFields(Boolean.TRUE);
preferences.setDisableMandatoryCustomFieldValidation(Boolean.TRUE);
SearchPreferences searchPreferences = new SearchPreferences();
searchPreferences.setPageSize(this._pageSize);
searchPreferences.setBodyFieldsOnly(Boolean.valueOf(false));
RecordRef role = new RecordRef();
role.setInternalId(this._role);
Passport passport = new Passport();
passport.setEmail(this._email);
passport.setPassword(this._pwd);
passport.setRole(role);
passport.setAccount(this._account);
// Get the webservices domain for your account
GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
dataCenterRequest.setAccount(this._account);
DataCenterUrls urls = null;
GetDataCenterUrlsResponse reponse = port.getDataCenterUrls(dataCenterRequest);
if (reponse != null && reponse.getGetDataCenterUrlsResult() != null) {
urls = reponse.getGetDataCenterUrlsResult().getDataCenterUrls();
}
if (urls == null) {
throw new Exception("Can't get a correct webservice domain! Please check your configuration or try to run again.");
}
String wsDomain = urls.getWebservicesDomain();
String endpoint = wsDomain.concat(new URL(this._url).getPath());
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
if (list == null) {
list = new ArrayList<Header>();
requestContext.put(Header.HEADER_LIST, list);
}
Header searchPreferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
Header preferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
list.add(searchPreferences_header);
list.add(preferences_header);
LoginRequest request = new LoginRequest();
request.setPassport(passport);
port.login(request);
this._port = port;
Arrays.asList(new String[] { "", "", "" });
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project libresonic by Libresonic.
the class SonosService method getUsername.
private String getUsername() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
LOG.error("Message context is null or not an instance of WrappedMessageContext.");
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
if (headers != null) {
for (Header h : headers) {
Object o = h.getObject();
// Unwrap the node using JAXB
if (o instanceof Node) {
JAXBContext jaxbContext;
try {
// TODO: Check performance
jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
o = unmarshaller.unmarshal((Node) o);
} catch (JAXBException e) {
// failed to get the credentials object from the headers
LOG.error("JAXB error trying to unwrap credentials", e);
}
}
if (o instanceof Credentials) {
Credentials c = (Credentials) o;
// Note: We're using the username as session ID.
String username = c.getSessionId();
if (username == null) {
LOG.debug("No session id in credentials object, get from login");
username = c.getLogin().getUsername();
}
return username;
} else {
LOG.error("No credentials object");
}
}
} else {
LOG.error("No headers found");
}
return null;
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project camel by apache.
the class HeaderTesterImpl method addReplyOutOfBandHeader.
private void addReplyOutOfBandHeader() {
if (context != null) {
MessageContext ctx = context.getMessageContext();
if (ctx != null) {
try {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobReturnHeaderName");
ob.setValue("testOobReturnHeaderValue");
ob.setHdrAttribute("testReturnHdrAttribute");
JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
Header hdr = new Header(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
hdrList.add(hdr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project BIMserver by opensourceBIM.
the class GenericWebServiceServlet method loadBus.
public void loadBus(ServletConfig servletConfig) {
this.bus = BusFactory.newInstance().createBus();
Bus bus = getBus();
HeaderManager headerManager = bus.getExtension(HeaderManager.class);
headerManager.registerHeaderProcessor(new HeaderProcessor() {
@Override
public String getNamespace() {
return "uri:org.bimserver.shared";
}
@Override
public InterceptorProvider getInterceptorProvider() {
return null;
}
@Override
public DataBinding getDataBinding() {
try {
return new JAXBDataBinding(Token.class);
} catch (JAXBException e) {
LOGGER.error("", e);
}
return null;
}
});
BusFactory.setDefaultBus(bus);
for (Class<? extends PublicInterface> clazz : getBimServer().getServicesMap().getInterfaceClasses()) {
JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("mtom-enabled", Boolean.TRUE);
serverFactoryBean.setBindingId(bindingId);
serverFactoryBean.setProperties(properties);
serverFactoryBean.setServiceClass(clazz);
serverFactoryBean.getOutFaultInterceptors().add(new StatusCodeModifyingFaultInterceptor());
serverFactoryBean.setInvoker(new CustomInvoker(getBimServer().getServiceFactory(), clazz));
if (getBimServer().getConfig().getEnvironment() != Environment.WAR) {
// equals check allowed, just keep using the constant
serverFactoryBean.setAddress((bindingId == WSDLConstants.NS_SOAP11 ? "/soap11/" : "/soap12/") + clazz.getSimpleName());
} else {
// equals check allowed, just keep using the constant
serverFactoryBean.setAddress("/" + clazz.getSimpleName());
}
serverFactoryBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
serverFactoryBean.create();
}
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class WrapperClassGeneratorTest method testForXmlList.
@org.junit.Test
public void testForXmlList() throws Exception {
JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(AddNumbersImpl.class);
JaxWsServiceFactoryBean jaxwsFac = new JaxWsServiceFactoryBean(implInfo);
jaxwsFac.setBus(BusFactory.getDefaultBus());
Service service = jaxwsFac.create();
ServiceInfo serviceInfo = service.getServiceInfos().get(0);
InterfaceInfo interfaceInfo = serviceInfo.getInterface();
OperationInfo inf = interfaceInfo.getOperations().iterator().next();
Class<?> requestClass = inf.getInput().getMessagePart(0).getTypeClass();
Class<?> responseClass = inf.getOutput().getMessagePart(0).getTypeClass();
// Create request wrapper Object
List<String> partNames = Arrays.asList(new String[] { "arg0" });
List<String> elTypeNames = Arrays.asList(new String[] { "list" });
List<Class<?>> partClasses = Arrays.asList(new Class<?>[] { List.class });
String className = requestClass.getName();
className = className.substring(0, className.lastIndexOf(".") + 1);
WrapperHelper wh = new JAXBDataBinding().createWrapperHelper(requestClass, null, partNames, elTypeNames, partClasses);
List<Object> paraList = new ArrayList<>();
List<String> valueList = new ArrayList<>();
valueList.add("str1");
valueList.add("str2");
valueList.add("str3");
paraList.add(valueList);
Object requestObj = wh.createWrapperObject(paraList);
// Create response wrapper Object
partNames = Arrays.asList(new String[] { "return" });
elTypeNames = Arrays.asList(new String[] { "list" });
partClasses = Arrays.asList(new Class<?>[] { List.class });
className = responseClass.getName();
className = className.substring(0, className.lastIndexOf(".") + 1);
wh = new JAXBDataBinding().createWrapperHelper(responseClass, null, partNames, elTypeNames, partClasses);
List<Object> resPara = new ArrayList<>();
List<Integer> intValueList = new ArrayList<>();
intValueList.add(1);
intValueList.add(2);
intValueList.add(3);
resPara.add(intValueList);
Object responseObj = wh.createWrapperObject(resPara);
JAXBContext jaxbContext = JAXBContext.newInstance(requestClass, responseClass);
java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
Marshaller marshaller = jaxbContext.createMarshaller();
// check marshall wrapper
marshaller.marshal(requestObj, bout);
String expected = "<arg0>str1 str2 str3</arg0>";
assertTrue("The generated request wrapper class does not contain the correct annotations", bout.toString().contains(expected));
bout.reset();
marshaller.marshal(responseObj, bout);
expected = "<return>1</return><return>2</return><return>3</return>";
assertTrue("The generated response wrapper class is not correct", bout.toString().contains(expected));
}
Aggregations