I am using JasperReports Server with its jrs-rest-java-client API. When I access the remote server I want to inject the datasource (in my case it is a database) that the report should use. I do not know if it is possible to do it using this API.
Yes, it is possible. This is how I do it in JasperReports Server v6.2.1 with the jrs-rest-java-client v6.2.3:
// build configuration object
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:8080/jasperserver");
configuration.setContentMimeType(MimeType.JSON);
configuration.setAcceptMimeType(MimeType.JSON);
configuration.setAuthenticationType(AuthenticationType.SPRING);
configuration.setLogHttp(true);
configuration.setLogHttpEntity(true);
// build client and authenticate
JasperserverRestClient client = new JasperserverRestClient(configuration);
Session session = client.authenticate("jasperadmin", "jasperadmin");
String reportUnitUri = "/path/to/reportUnit";
// first get the version of the reportUnit to prevent update conflicts from optimistic locking
OperationResult<ClientReportUnit> reportUnitOperationResult = session.resourcesService().resource(reportUnitUri).get(ClientReportUnit.class);
Integer reportUnitVersion = reportUnitOperationResult.getEntity().getVersion();
// build patchDescriptor with the dataSource field
PatchDescriptor patchDescriptor = new PatchDescriptor();
patchDescriptor.setVersion(reportUnitVersion);
patchDescriptor.field("dataSource", "/path/to/repository/dataSource");
// apply the patchDescriptor
session.resourcesService().resource(reportUnitUri).patchResource(ClientReportUnit.class, patchDescriptor);
Related
I am using the REST api for executing rules on Decision Server (Redhat Decision Manager 7.2) using a stateless kie session. I'm currently getting the number of triggered rules, but I also want to get the names of those rules. Is this possible?
KieServicesConfiguration conf = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD);
List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
commands.add((GenericCommand<?>)
KieServices.Factory.get().getCommands().newInsert(applicant, "applicant"));
commands.add((GenericCommand<?>)
KieServices.Factory.get().getCommands().newInsert(loan, "loan"));
commands.add((GenericCommand<?>)KieServices.Factory.get().getCommands().newFireAllRules("numberOfFiredRules"));
KieCommands kieCommands = KieServices.Factory.get().getCommands();
BatchExecutionCommand batchCommand = kieCommands.newBatchExecution(commands, "default-stateless-ksession");
ServiceResponse<ExecutionResults> executeResponse = ruleServicesClient
.executeCommandsWithResults("loan-application_1.2.0", batchCommand);
System.out.println("Number of fired rules:" executeResponse.getResult().getValue("numberOfFiredRules"));
You have to use an AgendaEventListener to keep track of rules exectioned. By implemnting org.kie.api.event.rule.AgendaEventListener interface you can capture these detials.
To know which rules are triggered I added an action column with custom code (Action BRL fragment) that writes the rule name in one of the field of my fact. You can get it from rule.name.
Example:myFact.logMyRuleName(rule.name)
I am struggling to set-up infrastructure in my solution to send and retrieve the custom header for REST WCF Service. Basically, we need this to send UserID, password, token value from client to service and if provided values are valid then operation will continue to execute otherwise throw exception.
We already have few classes inherited from interfaces like IDispatchMessageInspector, IClientMessageInspector, IEndPointBehaviour, MessageHeader, etc., This is working fine for WCF with soap request. I tried to use these classes for my new REST WCF Service, but was not working as MessageHeader derived class supports only Soap.
I also tried using WebOperationContext, but no luck :(
Please provide a solution along with sample project to solve this problem.
Thank you so much!
Seems in your case it might be easier to interogate the ASPNET pipeline
if you add the following to your WCF service to allow it to hookup into the ASPNET pipeline
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
Then you can simply now use the HttpContext object and just get the headers as you would from a normal aspnet application, e.g
System.Web.HttpContext.Current.Request.Headers["CustomHeader"]
If you want to add http header in wcf rest service , you should use HttpRequestMessageProperty, it has a Headers property , you could set http Header through its Headers property
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
HttpRequestMessageProperty property;
// if OutgoingMessageProperties already has HttpRequestMessageProperty, use the existing one , or initialize a new one and
// set OutgoingMessageProperties's HttpRequestMessageProperty.Name key's value to the initialized HttpRequestMessageProperty so that the HttpRequestMessageProperty will work
if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name)){
property = OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
}
else
{
property = new HttpRequestMessageProperty();
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = property;
}
// add headers to HttpRequestMessageProperty, it will become the http header of the reuqest
property.Headers.Add(System.Net.HttpRequestHeader.Authorization, "myAuthorization");
string re = client.HelloWorld();
}
About getting the Header , just use WebOperationContext.Current.Headers.
WebOperationContext.Current.IncomingRequest.Headers["MyCustomHttpHeader"]
Please refer to http://kenneththorman.blogspot.com/2011/02/wcf-rest-client-using-custom-http.html
We would like to fetch the payment configuration from Order in Java class (OrderBO extension). So far we have managed to fetch the service like this:
final OrderBOPaymentExtension<OrderBO> paymentExtension = getExtendedObject().getExtension(OrderBOPaymentExtension.EXTENSION_ID);
final PaymentBO paymentBO = paymentExtension.getPaymentBOs().stream().findFirst().orElse(null);
PaymentServiceBO paymentServiceBO = paymentBO.getPaymentServiceBO();
Now we need to fetch the configuration, so we can read certain configuration parameters from the payment method. What is the best way to do that?
We know it is possible to fetch the payment configuration through the PO Factory like this:
PaymentConfigurationPOFactory f = (PaymentConfigurationPOFactory)NamingMgr.getInstance().lookupFactory(PaymentConfigurationPO.class);
PaymentConfigurationPO r = f.getConfigForIDAndDomain(iD, domain);
But we would like to avoid using deprecated code.
UPDATE:
What we are trying to achieve is access these BO parameters in Java code:
I'd suggest you write a PaymentServiceBO extension. Within that extension you can write getter methods to query for certain config values. The java code for accessing service configuration object is:
PaymentConfiguration paymentConfig = paymentServiceBO.getExtension(PersistentObjectBOExtension.class).getPersistentObject();
ServiceConfigurationBO serviceConfigurationBO = repository.getServiceConfigurationBOByID(paymentConfig.getManagedServiceConfiguration().getUUID());
ConfigurationProvider configProviderExtension = serviceConfigurationBO.getExtension(ConfigurationProvider.class);
Configuration configuration = configProviderExtension.getConfiguration();
Logger.debug(this, "payment service config keys = {}", configuration.getKeys());
I believe PaymentConfiguration is deprecated. See PaymentConfigurationBO javadoc:
Deprecated since 7.6. Payment configurations are now represented via PaymentServiceBOs.
So you need to use PaymentServiceBO methods or write a business object extension that does what you want.
In elastic search java api, suppose I am building the indexed data using this client
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
.execute()
.actionGet();
This indexed data is stored in folder XYZ/elasticsearch/data.
My question is how to retrieve this indexed data in java from some other client or some other code. Is there any way in which I can give the path and the already indexed data can be imported, then I can perform queries on it?
Edit :
The code for client on other computer
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
MatchQueryBuilder qb = QueryBuilders.matchQuery("user", "kimchy");
SearchRequestBuilder srb = client.prepareSearch("twitter").setTypes("tweet");
SearchResponse big = srb.setQuery(qb).execute().actionGet();
SearchHit[] results = big.getHits().getHits();
This shows
search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed
Thanks
Arya
I'm not sure I understand the question, but if it's just querying in java here's an example :
MatchQueryBuilder qb = QueryBuilders.matchQuery("user", "kimchy);
SearchRequestBuilder srb = client.prepareSearch("twitter").setTypes("tweet");
srb.setQuery(qb);
SearchResponse response = srb.execute().actionGet();
//Here goes your code where you use response.getHits() that contains your items
The message you get by using my snippet usually indicates that your client doesn't manage to connect to your server. Check your server status (i.e. that you launched your server properly) and try using this.
Node node = NodeBuilder.nodeBuilder().client(true).node();
client = node.client();
I don't think you need to specify the clustername unless you have some custom configuration i'm not aware of. Also check your index name.
ADFS 2.0, WIF (WS-Federation), ASP.NET: There is no http modules or any IdentityFoundation configuration defined in a web.config (like most WIF SDK samples show), instead everything is done via program code manually using WSFederationAuthenticationModule, ServiceConfiguration and SignInRequestMessage classes. I do http redirect to ADFS in a code and it seems to work fine, returning claims and redirecting user back to my web site with serialized claims in http request. So the question is how to parse this request using WIF classes, properties and methods and extract claims values from there? Thanks
Just in case want to share my experience, it might help somebody in the future. Well, solution I finally came to looks like this:
var message = SignInResponseMessage.CreateFromFormPost(Request) as SignInResponseMessage;
var rstr = new WSFederationSerializer().CreateResponse(message, new WSTrustSerializationContext(SecurityTokenHandlerCollectionManager.CreateDefaultSecurityTokenHandlerCollectionManager()));
var issuers = new ConfigurationBasedIssuerNameRegistry();
issuers.AddTrustedIssuer("630AF999EA69AF4917362D30C9EEA00C22D9A343", #"http://MyADFSServer/adfs/services/trust");
var tokenHandler = new Saml11SecurityTokenHandler {CertificateValidator = X509CertificateValidator.None};
var config = new SecurityTokenHandlerConfiguration{
CertificateValidator = X509CertificateValidator.None,
IssuerNameRegistry = issuers};
config.AudienceRestriction.AllowedAudienceUris.Add(new Uri("MyUri"));
tokenHandler.Configuration = config;
using(var reader=XmlReader.Create(new StringReader(rstr.RequestedSecurityToken.SecurityTokenXml.OuterXml)))
{
token = tokenHandler.ReadToken(reader);
}
ClaimsIdentityCollection claimsIdentity = tokenHandler.ValidateToken(token);
I found few similar code that uses SecurityTokenServiceConfiguration (it contains token handlers) instead of Saml11SecurityTokenHandler to read and parse token, however it did not work for me because of certificate validation failure. Setting SecurityTokenServiceConfiguration.CertificateValidator to X509CertificateValidator.None did not help coz Security Token Handler classes uses their own handler configuration and ignores STS configuration values, at least if you specify configuration parameters through the code like I did, however it works fine in case configuration is defined in web.config.