use of org.apache.cxf.headers.Header in project OpenAM by OpenRock.
the class OpenAMSessionTokenClientInterceptor method addToken.
/**
* This method is called on the outbound client side, secure-request in JASPI terms. This method will add the
* OpenAMSessionAssertion state to the message.
* @param message the encapsulation of the soap request.
*/
@Override
protected void addToken(SoapMessage message) {
OpenAMSessionAssertion openAMSessionAssertion = (OpenAMSessionAssertion) assertTokens(message);
Header header = findSecurityHeader(message, true);
final Element element = (Element) header.getObject();
final Element openAMSessionAssertionElement = openAMSessionAssertion.getTokenElement();
element.appendChild(element.getOwnerDocument().importNode(openAMSessionAssertionElement, true));
}
use of org.apache.cxf.headers.Header 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.headers.Header 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.headers.Header in project camel by apache.
the class SoapMessageHeaderFilter method filter.
public void filter(Direction direction, List<Header> headers) {
// Treat both in and out direction the same
if (headers == null) {
return;
}
Iterator<Header> iterator = headers.iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
LOG.trace("Processing header: {}", header);
if (!(header instanceof SoapHeader)) {
LOG.trace("Skipped header: {} since it is not a SoapHeader", header);
continue;
}
SoapHeader soapHeader = SoapHeader.class.cast(header);
for (Iterator<SoapVersion> itv = SoapVersionFactory.getInstance().getVersions(); itv.hasNext(); ) {
SoapVersion version = itv.next();
if (soapHeader.getActor() != null && soapHeader.getActor().equals(version.getNextRole())) {
// dropping headers if actor/role equals to {ns}/role|actor/next
// cxf SoapHeader needs to have soap:header@relay attribute,
// then we can check for it here as well
LOG.trace("Filtered header: {}", header);
iterator.remove();
break;
}
}
}
}
use of org.apache.cxf.headers.Header in project camel by apache.
the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.
protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
if (!expect) {
if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
return;
}
fail("Should have got *no* out-of-band headers, but some were found");
}
if (oobHdr == null) {
fail("Should have got List of out-of-band headers");
}
assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
for (Header hdr1 : oobHdr) {
if (hdr1.getObject() instanceof Node) {
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
hdrToTest.add((OutofBandHeader) job.getValue());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
Aggregations