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 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 camel by apache.
the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeader.
protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext, boolean expect) {
OutofBandHeader hdrToTest = null;
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 1 object received " + oobHdr.size(), oobHdr.size() == 1);
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 = (OutofBandHeader) job.getValue();
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
assertNotNull("out-of-band header should not be null", hdrToTest);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.getName(), "testOobReturnHeaderName".equals(hdrToTest.getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.getValue(), "testOobReturnHeaderValue".equals(hdrToTest.getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.getHdrAttribute()));
}
use of org.apache.cxf.headers.Header in project camel by apache.
the class CxfMessageHeadersRelayTest method doTestInOutOfBandHeaderCamelTemplate.
protected void doTestInOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<Object> params = new ArrayList<Object>();
Me me = new Me();
me.setFirstName("john");
me.setLastName("Doh");
params.add(me);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inOutOfBandHeader");
List<Header> headers = buildOutOfBandHeaderList(false);
Map<String, Object> requestContext = new HashMap<String, Object>();
requestContext.put(Header.HEADER_LIST, headers);
senderExchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
Exchange exchange = template.send(producerUri, senderExchange);
org.apache.camel.Message out = exchange.getOut();
MessageContentsList result = (MessageContentsList) out.getBody();
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me) result.get(0)).getFirstName().equals("pass"));
}
Aggregations