Java Code Examples for org.apache.cxf.common.util.PropertyUtils#isTrue()
The following examples show how to use
org.apache.cxf.common.util.PropertyUtils#isTrue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipartProvider.java From cxf with Apache License 2.0 | 6 votes |
private String getRootMediaType(Annotation[] anns, MediaType mt) { String mimeType = mt.getParameters().get("type"); if (mimeType != null) { return mimeType; } Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class); if (id != null && !MediaType.WILDCARD.equals(id.type())) { mimeType = id.type(); } if (mimeType == null) { if (PropertyUtils.isTrue(mc.getContextualProperty(Message.MTOM_ENABLED))) { mimeType = "text/xml"; } else { mimeType = MediaType.APPLICATION_OCTET_STREAM; } } return mimeType; }
Example 2
Source File: OSGiBeanLocator.java From cxf with Apache License 2.0 | 6 votes |
private <T> List<T> getBeansFromOsgiService(Class<T> type) { List<T> list = new ArrayList<>(); try { ServiceReference<?>[] refs = context.getServiceReferences(type.getName(), null); if (refs != null) { for (ServiceReference<?> r : refs) { if (type == ClassLoader.class && checkCompatibleLocators && !PropertyUtils.isTrue(r.getProperty(COMPATIBLE_LOCATOR_PROP))) { continue; } list.add(type.cast(context.getService(r))); } } } catch (Exception ex) { //ignore, just don't support the OSGi services LOG.info("Tried to find the Bean with type:" + type + " from OSGi services and get error: " + ex); } return list; }
Example 3
Source File: AbstractHTTPDestination.java From cxf with Apache License 2.0 | 6 votes |
/** * Constructor * * @param b the associated Bus * @param registry the destination registry * @param ei the endpoint info of the destination * @param path the path * @param dp true for adding the default port if it is missing * @throws IOException */ public AbstractHTTPDestination(Bus b, DestinationRegistry registry, EndpointInfo ei, String path, boolean dp) throws IOException { super(b, getTargetReference(getAddressValue(ei, dp), b), ei); this.bus = b; this.registry = registry; this.path = path; try { ServletRequest.class.getMethod("isAsyncSupported"); isServlet3 = true; } catch (Throwable t) { //servlet 2.5 or earlier, no async support } decodeBasicAuthWithIso8859 = PropertyUtils.isTrue(bus.getProperty(DECODE_BASIC_AUTH_WITH_ISO8859)); initConfig(); }
Example 4
Source File: OAuthUtils.java From cxf with Apache License 2.0 | 6 votes |
public static Response handleException(MessageContext mc, Exception e, int status) { ResponseBuilder builder = Response.status(status); if (PropertyUtils.isTrue(mc.getContextualProperty(REPORT_FAILURE_DETAILS))) { boolean asHeader = PropertyUtils.isTrue( mc.getContextualProperty(REPORT_FAILURE_DETAILS_AS_HEADER)); String text = null; if (e instanceof OAuthProblemException) { OAuthProblemException problem = (OAuthProblemException)e; if (asHeader && problem.getProblem() != null) { text = problem.getProblem(); } } if (text == null) { text = e.getMessage(); } if (asHeader) { builder.header("oauth_problem", text); } else { builder.entity(e.getMessage()); } } return builder.build(); }
Example 5
Source File: MessageUtils.java From cxf with Apache License 2.0 | 5 votes |
public static boolean getContextualBoolean(Message m, String key, boolean defaultValue) { if (m != null) { Object o = m.getContextualProperty(key); if (o != null) { return PropertyUtils.isTrue(o); } } return defaultValue; }
Example 6
Source File: MultipartProvider.java From cxf with Apache License 2.0 | 5 votes |
private boolean isSupported(Class<?> type, Annotation[] anns, MediaType mt) { return mediaTypeSupported(mt) && (WELL_KNOWN_MULTIPART_CLASSES.contains(type) || Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) && type != MultivaluedMap.class || AnnotationUtils.getAnnotation(anns, Multipart.class) != null || PropertyUtils.isTrue(mc.getContextualProperty(SUPPORT_TYPE_AS_MULTIPART))); }
Example 7
Source File: FiqlParser.java From cxf with Apache License 2.0 | 5 votes |
/** * Creates FIQL parser. * * @param tclass - class of T used to create condition objects in built syntax tree. Class T must have * accessible no-arg constructor and complementary setters to these used in FIQL expressions. * @param contextProperties * @param beanProperties */ public FiqlParser(Class<T> tclass, Map<String, String> contextProperties, Map<String, String> beanProperties) { super(tclass, contextProperties, beanProperties); if (PropertyUtils.isTrue(this.contextProperties.get(SUPPORT_SINGLE_EQUALS))) { operatorsMap = new HashMap<>(operatorsMap); operatorsMap.put("=", ConditionType.EQUALS); comparatorsPattern = COMPARATORS_PATTERN_SINGLE_EQUALS; } }
Example 8
Source File: UnformattedServiceListWriter.java From cxf with Apache License 2.0 | 5 votes |
private void writeUnformattedRESTfulEndpoints(PrintWriter writer, String baseAddress, AbstractDestination[] destinations) throws IOException { for (AbstractDestination sd : destinations) { String address = getAbsoluteAddress(baseAddress, sd); address = StringEscapeUtils.escapeHtml4(address); boolean wadlAvailable = bus != null && PropertyUtils.isTrue(bus.getProperty("wadl.service.descrition.available")); boolean swaggerAvailable = bus != null && PropertyUtils.isTrue(bus.getProperty("swagger.service.descrition.available")); boolean openApiAvailable = bus != null && PropertyUtils.isTrue(bus.getProperty("openapi.service.descrition.available")); if (!wadlAvailable && !swaggerAvailable) { writer.write(address + "\n"); return; } if (wadlAvailable) { writer.write(address + "?_wadl\n"); } if (swaggerAvailable) { writer.write(address + "/swagger.json\n"); } if (openApiAvailable) { writer.write(address + "/openapi.json\n"); } } }
Example 9
Source File: MicroProfileClientConfigurableImpl.java From cxf with Apache License 2.0 | 5 votes |
boolean isDefaultExceptionMapperDisabled() { Object prop = getConfiguration().getProperty(CONFIG_KEY_DISABLE_MAPPER); if (prop != null) { return PropertyUtils.isTrue(prop); } return ConfigFacade.getOptionalValue(CONFIG_KEY_DISABLE_MAPPER, Boolean.class).orElse(false); }
Example 10
Source File: JoseUtils.java From cxf with Apache License 2.0 | 5 votes |
public static boolean checkBooleanProperty(JoseHeaders headers, Properties props, Message m, String propertyName) { if (headers == null) { return false; } if (props.containsKey(propertyName)) { return PropertyUtils.isTrue(props.get(propertyName)); } return MessageUtils.getContextualBoolean(m, propertyName, false); }
Example 11
Source File: JAXRSInInterceptor.java From cxf with Apache License 2.0 | 5 votes |
private void setExchangeProperties(Message message, Exchange exchange, OperationResourceInfo ori, MultivaluedMap<String, String> values, int numberOfResources) { final ClassResourceInfo cri = ori.getClassResourceInfo(); exchange.put(OperationResourceInfo.class, ori); exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri); message.put(RESOURCE_METHOD, ori.getMethodToInvoke()); message.put(URITemplate.TEMPLATE_PARAMETERS, values); String plainOperationName = ori.getMethodToInvoke().getName(); if (numberOfResources > 1) { plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName; } exchange.put(RESOURCE_OPERATION_NAME, plainOperationName); if (ori.isOneway() || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) { exchange.setOneWay(true); } ResourceProvider rp = cri.getResourceProvider(); if (rp instanceof SingletonResourceProvider) { //cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message)); } }
Example 12
Source File: KerberosAuthenticationFilter.java From cxf with Apache License 2.0 | 5 votes |
protected GSSContext createGSSContext() throws GSSException { boolean useKerberosOid = PropertyUtils.isTrue( messageContext.getContextualProperty(PROPERTY_USE_KERBEROS_OID)); Oid oid = new Oid(useKerberosOid ? KERBEROS_OID : SPNEGO_OID); GSSManager gssManager = GSSManager.getInstance(); String spn = getCompleteServicePrincipalName(); GSSName gssService = gssManager.createName(spn, null); return gssManager.createContext(gssService.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME); }
Example 13
Source File: SecurityUtils.java From cxf with Apache License 2.0 | 5 votes |
/** * Get the security property boolean for the given property. It also checks for the older "ws-"* property * values. If none is configured, then the defaultValue parameter is returned. */ public static boolean getSecurityPropertyBoolean(String property, Message message, boolean defaultValue) { Object value = getSecurityPropertyValue(property, message); if (value != null) { return PropertyUtils.isTrue(value); } return defaultValue; }
Example 14
Source File: BookStoreNoAnnotationsImpl.java From cxf with Apache License 2.0 | 5 votes |
public Book getBook(Long id) throws BookNotFoundFault { if (hs == null) { throw new WebApplicationException(Response.serverError().build()); } boolean springProxy = PropertyUtils.isTrue(hs.getHeaderString("SpringProxy")); if (!springProxy && ui == null) { throw new WebApplicationException(Response.serverError().build()); } return books.get(id); }
Example 15
Source File: CXFNonSpringJaxrsServlet.java From cxf with Apache License 2.0 | 4 votes |
protected boolean isIgnoreApplicationPath(ServletConfig servletConfig) { String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM); return ignoreParam == null || PropertyUtils.isTrue(ignoreParam); }
Example 16
Source File: OAuthServletFilter.java From cxf with Apache License 2.0 | 4 votes |
public void init(FilterConfig filterConfig) throws ServletException { ServletContext servletContext = filterConfig.getServletContext(); super.setDataProvider(OAuthUtils.getOAuthDataProvider(servletContext)); super.setValidator(OAuthUtils.getOAuthValidator(servletContext)); super.setUseUserSubject(PropertyUtils.isTrue(servletContext.getInitParameter(USE_USER_SUBJECT))); }
Example 17
Source File: JAXRSClientFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
protected void initClient(AbstractClient client, Endpoint ep, boolean addHeaders) { if (username != null) { AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setUserName(username); authPolicy.setPassword(password); ep.getEndpointInfo().addExtensor(authPolicy); } client.getConfiguration().setConduitSelector(getConduitSelector(ep)); client.getConfiguration().setBus(getBus()); client.getConfiguration().getOutInterceptors().addAll(getOutInterceptors()); client.getConfiguration().getOutInterceptors().addAll(ep.getOutInterceptors()); client.getConfiguration().getInInterceptors().addAll(getInInterceptors()); client.getConfiguration().getInInterceptors().addAll(ep.getInInterceptors()); client.getConfiguration().getInFaultInterceptors().addAll(getInFaultInterceptors()); applyFeatures(client); if (headers != null && addHeaders) { client.headers(headers); } ClientProviderFactory factory = ClientProviderFactory.createInstance(getBus()); setupFactory(factory, ep); final Map<String, Object> theProperties = super.getProperties(); final boolean encodeClientParameters = PropertyUtils.isTrue(theProperties, "url.encode.client.parameters"); if (encodeClientParameters) { final String encodeClientParametersList = (String)getProperties().get("url.encode.client.parameters.list"); factory.registerUserProvider(new ParamConverterProvider() { @SuppressWarnings("unchecked") @Override public <T> ParamConverter<T> getConverter(Class<T> cls, Type t, Annotation[] anns) { if (cls == String.class && AnnotationUtils.getAnnotation(anns, HeaderParam.class) == null && AnnotationUtils.getAnnotation(anns, CookieParam.class) == null) { return (ParamConverter<T>) new UrlEncodingParamConverter(encodeClientParametersList); } return null; } }); } }
Example 18
Source File: Headers.java From cxf with Apache License 2.0 | 4 votes |
private boolean logSensitiveHeaders() { // Not allowed by default return PropertyUtils.isTrue(message.getContextualProperty(ALLOW_LOGGING_SENSITIVE_HEADERS)); }
Example 19
Source File: MultipartProvider.java From cxf with Apache License 2.0 | 4 votes |
public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { checkContentLength(); List<Attachment> infos = AttachmentUtils.getAttachments( mc, attachmentDir, attachmentThreshold, attachmentMaxSize); boolean collectionExpected = Collection.class.isAssignableFrom(c); if (collectionExpected && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) { return getAttachmentCollection(t, infos, anns); } if (c.isAssignableFrom(Map.class)) { Map<String, Object> map = new LinkedHashMap<>(infos.size()); Class<?> actual = getActualType(t, 1); for (Attachment a : infos) { map.put(a.getContentType().toString(), fromAttachment(a, actual, actual, anns)); } return map; } if (MultipartBody.class.isAssignableFrom(c)) { return new MultipartBody(infos); } Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class); Attachment multipart = AttachmentUtils.getMultipart(id, mt, infos); if (multipart != null) { if (collectionExpected && !mediaTypeSupported(multipart.getContentType()) && !PropertyUtils.isTrue(mc.getContextualProperty(SINGLE_PART_IS_COLLECTION))) { List<Attachment> allMultiparts = AttachmentUtils.getMatchingAttachments(id, infos); return getAttachmentCollection(t, allMultiparts, anns); } return fromAttachment(multipart, c, t, anns); } if (id != null && !id.required()) { /* * Return default value for a missing optional part */ Object defaultValue = null; if (c.isPrimitive()) { defaultValue = PrimitiveUtils.read((Class<?>)c == boolean.class ? "false" : "0", c); } return defaultValue; } throw ExceptionUtils.toBadRequestException(null, null); }
Example 20
Source File: AuthenticationCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private static void addUsernameTokenConfigurer(ComponentProxyComponent component, Map<String, Object> options) { final CamelContext camelContext = component.getCamelContext(); final String username = getResolvedValue(camelContext, (String) options.remove(ComponentProperties.USERNAME)); if (username == null || username.isEmpty()) { throw new IllegalArgumentException("Invalid empty or null username for WS-Security Username Token"); } final String password = getResolvedValue(camelContext, (String) options.remove(ComponentProperties.PASSWORD)); final String passwordTypeString = (String) options.remove(ConfigurationConstants.PASSWORD_TYPE); final boolean addTimeStamp = PropertyUtils.isTrue(options.remove(ComponentProperties.ADD_TIMESTAMP)); // set WSSE-UT options and create client out interceptor final SoapCxfProxyComponent proxyComponent = (SoapCxfProxyComponent) component; proxyComponent.setCxfEndpointConfigurer(new ChainedCxfConfigurer.NullCxfConfigurer() { @Override public void configureClient(Client client) { // TODO reconcile with any WSDL defined WS security policy // for now, we assume there are no security policies in WSDL final StringBuilder actions = new StringBuilder(); final Map<String, Object> outProps = new HashMap<>(); outProps.put(ConfigurationConstants.USER, username); if (password != null && !password.isEmpty()) { outProps.put(ConfigurationConstants.PW_CALLBACK_REF, (CallbackHandler) callbacks -> { for (Callback callback : callbacks) { final WSPasswordCallback passwordCallback = (WSPasswordCallback) callback; if (username.equals(passwordCallback.getIdentifier())) { passwordCallback.setPassword(password); return; } } }); } final PasswordType passwordType = PasswordType.fromValue(passwordTypeString); outProps.put(ConfigurationConstants.PASSWORD_TYPE, passwordType.getValue()); // set action and other options based on type switch (passwordType) { case NONE: actions.append(ConfigurationConstants.USERNAME_TOKEN_NO_PASSWORD); outProps.remove(ConfigurationConstants.PW_CALLBACK_REF); break; case TEXT: case DIGEST: actions.append(ConfigurationConstants.USERNAME_TOKEN); break; } if (addTimeStamp) { actions.append(' '); actions.append(ConfigurationConstants.TIMESTAMP); } final boolean addNonce = PropertyUtils.isTrue(options.remove(ConfigurationConstants.ADD_USERNAMETOKEN_NONCE)); outProps.put(ConfigurationConstants.ADD_USERNAMETOKEN_NONCE, String.valueOf(addNonce)); final boolean addCreated = PropertyUtils.isTrue(options.remove(ConfigurationConstants.ADD_USERNAMETOKEN_CREATED)); outProps.put(ConfigurationConstants.ADD_USERNAMETOKEN_CREATED, String.valueOf(addCreated)); outProps.put(ConfigurationConstants.ACTION, actions.toString()); client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); } }); }