How to count the invocation of Webservices deployed on Glassfish 3.1?
Actually I can get what I want at console commands? as following
asadmin get -m "server.applications.hello-jaxws2*" server.applications.hello-jaxws2.2.server.Hello.requestcount-count = 14
But I want to know if there is a way of getting the invocation count of web services programatically?
As an example using Glassfish 3.1.2. and a Web service named "NewWebService" here is a code extract that retrieves the number of requests for that Web service.
public static void showRequestCount(MBeanServerConnection mbs) throws Exception {
ObjectName on = new ObjectName("amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService");
final Set<ObjectInstance> mBeans = mbs.queryMBeans(on, null);
for (ObjectInstance mbean : mBeans) {
System.out.println("mbean: " + mbean);
final MBeanInfo info = mbs.getMBeanInfo(on);
final MBeanAttributeInfo[] attributes = info.getAttributes();
for (int i = 0; i < attributes.length; i++) {
MBeanAttributeInfo mBeanAttributeInfo = attributes[i];
if (mBeanAttributeInfo.getName().equals("requestcount")) {
final Object attribute = mbs.getAttribute(on, mBeanAttributeInfo.getName());
CompositeDataSupport cds = (CompositeDataSupport) attribute;
final Object requestCount = cds.get("count");
System.out.println("Object name: " + on.getKeyProperty("name"));
System.out.println("Request count: " + requestCount);
}
}
}
}
The result is:
mbean: servlet-instance-mon[amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService]
Object name: WebApplication1/server/NewWebService
Request count: 18
Please note that the ObjectName of the MBean and/or its attributes may vary depending on your Glassfish version.
Related
I have google app engine project taht i finish upgrade from java 8 to java 11.
I also upgraded TaskQueque to cloudTask and every working but how i can run cloudTask on localHost?
this is my old code
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions taskOptions = TaskOptions.Builder.withUrl("/" + backgroundTaskParams.getUrl());
taskOptions.retryOptions(RetryOptions.Builder.withTaskRetryLimit(backgroundTaskParams.getRetryLimit()));
taskOptions.countdownMillis(backgroundTaskParams.getStartDelay());
Map<String, String> params = backgroundTaskParams.getParams();
if(params != null){
for (String key : params.keySet()) {
taskOptions.param(key, params.get(key));
}
}
TaskHandle taskHandle = queue.add(taskOptions);
is not working on java 11 standard gcp
so I upgrade to this code
try (CloudTasksClient client = CloudTasksClient.create()) {
RetryConfig retyConfig = RetryConfig.builder()
.setMaxRetries(backgroundTaskParams.getRetryLimit())
.build();
String queueName = QueueName.of(EMF.getProjectId(), "us-central1", "default").toString();
String payload = Utilities.buildUrlParams(backgroundTaskParams.getParams());
long startTime = (ApplicationServicesManager.getInstance().getTimeManager().getCurrentTime() + backgroundTaskParams.getStartDelay()) / 1000;
Task.Builder taskBuilder = Task.newBuilder();
taskBuilder.setAppEngineHttpRequest(
AppEngineHttpRequest.newBuilder()
.setRelativeUri("/" + backgroundTaskParams.getUrl())
.setHttpMethod(HttpMethod.POST)
.setBody(ByteString.copyFrom(payload, Charset.defaultCharset()))
.build());
taskBuilder.setScheduleTime(
Timestamp.newBuilder()
.setSeconds(startTime));
taskBuilder.setDispatchCount(1);
Task task = taskBuilder.build();
Task taskResponse = client.createTask(queueName, task);
}
//
catch (Exception e) {
NotificationsManager.sendLogException(e);
}
the new code working fine in production server but when I run in localhost
the code create task in production server so i cannot debugging and is not good :)
so how I can to start task in localHost
thank you
I have developed a web service using C# dot net coding which will connect to SharePoint online - and that web service I have hosted in one of the SharePoint on-premise IIS front end server - but I see some strange behavior. If we call that web service first time in a day using nintex workflow we get the below error:
**The GetListAttachmentsAndCopyToSPOnline workflow has ended unexpectedly for (no title).
For more information, please read this article: http://go.microsoft.com/fwlink/?LinkID=323543&clcid=0x409
Click here to view the workflow status.**
But once we restart the particular web service from IIS - everything start working perfectly. I mean in order to work with that web service every day at least once we need to restart the web service from the IIS....Not getting any clue why is this behavior? Any help would be much appreciated.
Sample web service code:
using (ClientContext ctx = new ClientContext(siteURL))
{
bool isSONumberFound = false;
string userName = "MyUserName";
string passWord = "MyPassword";
if (salesOrderNumber.Length <= 7)
{
salesOrderNumber = "000" + salesOrderNumber;
}
using (SecureString securedPassWord = new SecureString())
{
foreach (char c in passWord.ToCharArray()) securedPassWord.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials(userName, securedPassWord);
Web web = ctx.Web;
try
{
ctx.Load(web);
ctx.ExecuteQuery();
List list = web.Lists.GetByTitle(documentLibrayName);
var camelQuery = new CamlQuery() { ViewXml = "<View><Query><Where><Eq><FieldRef Name='OrderID' /><Value Type='Text'>" + salesOrderNumber + "</Value></Where></Query></View>" };
var queryResults = list.GetItems(camelQuery);
ctx.Load(queryResults);
ctx.ExecuteQuery();
int countSalesOrder = queryResults.Count;
if (countSalesOrder >= 1)
{
isSONumberFound = true;
using (StreamWriter w = System.IO.File.AppendText(logFileName))
{
string logMessageSONotFound = "Sales Order Number: " + salesOrderNumber + "is found in the target document library: " + documentLibrayName + "of" + siteURL + ", so please enter the valid SO number";
Log(logMessageSONotFound, w);
w.Flush();
w.Close();
w.Close();
}
}
else
{
isSONumberFound = false;
using (StreamWriter w = System.IO.File.AppendText(logFileName))
{
string logMessageSONotFound = "Sales Order Number: " + salesOrderNumber + "is not found in the target document library: " + documentLibrayName + "of"+ siteURL+", so please enter the valid SO number";
Log(logMessageSONotFound, w);
w.Flush();
w.Close();
w.Close();
}
}
}
catch (Exception ex)
{
using (StreamWriter w = System.IO.File.AppendText(logFileName))
{
Log(ex.Message.ToString(), w);
}
}
}
return isSONumberFound;
}
}
}
}
I was trying to implement an Axis2 service that receives user requests and publishes them as events to a CEP using carbon databridge thrift (via 'org.wso2.carbon.databridge.agent.thrift.DataPublisher')
I followed the code sample provided in wso2cep-3.1.0/samples/producers/activity-monitor
please see the following code snippet
public class GatewayServiceSkeleton{
private static Logger logger = Logger.getLogger(GatewayServiceSkeleton.class);
public RequestResponse request(Request request)throws AgentException,
MalformedStreamDefinitionException,StreamDefinitionException,
DifferentStreamDefinitionAlreadyDefinedException,
MalformedURLException,AuthenticationException,DataBridgeException,
NoStreamDefinitionExistException,TransportException, SocketException,
org.wso2.carbon.databridge.commons.exception.AuthenticationException
{
final String GATEWAY_SERVICE_STREAM = "gateway.cep";
final String VERSION = "1.0.0";
final String PROTOCOL = "tcp://";
final String CEPHOST = "cep.gubnoi.com";
final String CEPPORT = "7611";
final String CEPUSERNAME = "admin";
final String CEPPASSWORD = "admin";
Object[] metadata = { request.getDeviceID(), request.getViewID()};
Object[] correlationdata = { request.getSessionID()};
Object[] payloaddata = {request.getBucket()};
KeyStoreUtil.setTrustStoreParams();
KeyStoreUtil.setKeyStoreParams();
DataPublisher dataPublisher = new DataPublisher(PROTOCOL + CEPHOST + ":" + CEPPORT, CEPUSERNAME, CEPPASSWORD);
//create event
Event event = new Event (GATEWAY_SERVICE_STREAM + ":" + VERSION, System.currentTimeMillis(), metadata, correlationdata, payloaddata);
//Publish event for a valid stream
dataPublisher.publish(event);
//stop
dataPublisher.stop();
RequestResponse response = new RequestResponse();
response.setSessionID(request.getSessionID());
response.setDeviceID(request.getDeviceID());
response.setViewID(request.getViewID());
response.setBucket(request.getBucket());
return response;
}
there is also a utility class that set the key store parameters as following
public class KeyStoreUtil {
static File filePath = new File("../../../repository/resources/security");
public static void setTrustStoreParams() {
String trustStore = filePath.getAbsolutePath();
System.setProperty("javax.net.ssl.trustStore", trustStore + "/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
}
public static void setKeyStoreParams() {
String keyStore = filePath.getAbsolutePath();
System.setProperty("Security.KeyStore.Location", keyStore + "/wso2carbon.jks");
System.setProperty("Security.KeyStore.Password", "wso2carbon");
}
}
I uploaded the service into a wso2as-5.2.1, and called the service using SOAPUI
the request returned an error message "cannot borrow client for TCP"
I debug, and found out the problem might lies with the class 'KeyStoreUtil',
where the 'filePath' somehow retuned a 'null',
static File filePath = new File("../../../repository/resources/security");
and caused the failure on this line
DataPublisher dataPublisher = new DataPublisher(PROTOCOL + CEPHOST + ":" + CEPPORT, CEPUSERNAME, CEPPASSWORD);
I guess it could be a better idea if I use the value of "CARBON_HOME" to figure out the location of Key Store
so my question is :
How may I be able to get the value of 'CARBON_HOME' in the Java code?
that said. If you think a bit more:
the service will be called numerous time; whileas the 'setTrustStoreParams' and the 'setKeyStoreParams' will only be needed to executed once at the server/service initiate.
So, are there any even better ways to remove 'setTrustStoreParams' and 'setKeyStoreParams' out of the service code, or implement as configurable items?
Please advise
thanks
so my question is :
How may I be able to get the value of 'CARBON_HOME' in the Java code?
You should use the property carbon.home like following which will retrieve the WSO2 product's home directory.
System.getProperty("carbon.home");
I'm trying to use GZip or any other method of compression for consuming a SOAP web service on windows phone 7.1 , but I don't seem to find a way.
I found a library called SharpGIS.GZipWebClient, but the examples don't seem to work with the type of classes generated by Visual Studio 2010 when I add the service reference. I don't seem to find the WebClient class to be able to override GetWebRequest and GetWebResponse like they do on this blog
EDIT: This is the code I'm using to call the service:
private void btnService_Click(object sender, RoutedEventArgs e)
{
lblResponse.Text = "... Waiting for service response";
ConvertSoapClient client = new ConvertSoapClient();
client.TestCompressionCompleted += new EventHandler<TestCompressionCompletedEventArgs>(TestCompressionCompleted);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++)
sb.Append("qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm");
client.TestCompressionAsync(sb.ToString());
}
private void TestCompressionCompleted(object sender, TestCompressionCompletedEventArgs args)
{
lblResponse.Text = "Web service responded! Length = " + args.Result.Length;
}
Using the SQL Server Reporting Services Web Service, how can I determine the permissions of a particular domain user for a particular report? The user in question is not the user that is accessing the Web Service.
I am accessing the Web Service using a domain service account (lets say MYDOMAIN\SSRSAdmin) that has full permissions in SSRS. I would like to programmatically find the permissions of a domain user (lets say MYDOMAIN\JimBob) for a particular report.
The GetPermissions() method on the Web Service will return a list of permissions that the current user has (MYDOMAIN\SSRSAdmin), but that is not what I'm looking for. How can I get this same list of permissions for MYDOMAIN\JimBob? I will not have the user's domain password, so using their credentials to call the GetPermissions() method is not an option. I am however accessing this from an account that has full permissions, so I would think that theoretically the information should be available to it.
SSRS gets the NT groups from the users' NT login token. This is why when you are added to a new group, you are expected to log out and back in. The same applies to most Windows checks (SQL Server, shares, NTFS etc).
If you know the NT group(s)...
You can query the ReportServer database directly. I've lifted this almost directly out of one of our reports which we use to check folder security (C.Type = 1). Filter on U.UserName.
SELECT
R.RoleName,
U.UserName,
C.Path
FROM
ReportServer.dbo.Catalog C WITH (NOLOCK) --Parent
JOIN
ReportServer.dbo.Policies P WITH (NOLOCK) ON C.PolicyID = P.PolicyID
JOIN
ReportServer.dbo.PolicyUserRole PUR WITH (NOLOCK) ON P.PolicyID = PUR.PolicyID
JOIN
ReportServer.dbo.Users U WITH (NOLOCK) ON PUR.UserID = U.UserID
JOIN
ReportServer.dbo.Roles R WITH (NOLOCK) ON PUR.RoleID = R.RoleID
WHERE
C.Type = 1
look into "GetPolicies Method" you can see at the following link.
http://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.getpolicies.aspx
Hopefully this will get you started. I use it when copying Folder structure, and Reports from an old server to a new server when I want to 'migrate' my SSRS items from the Source to the Destination Server. It is a a Method to Get the Security Policies for an item on one server, and then set the Security Policies for an identical item on another server, after I have copied the item from the Source Server to the Destination Server. You have to set your own Source and Destination Server Names.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Services.Protocols; //<=== required for SoapException
namespace SSRS_WebServices_Utility
{
internal static class TEST
{
internal static void GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination(string itemPath)
{
string sSourceServer = "SOURCE-ServerName";
Source_ReportService2010.ReportingService2010 sourceRS = new Source_ReportService2010.ReportingService2010();
sourceRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
sourceRS.Url = #"http://" + sSourceServer + "/reportserver/reportservice2010.asmx";
string sDestinationServer = "DESTINATION-ServerName";
Destination_ReportService2010.ReportingService2010 DestinationRS = new Destination_ReportService2010.ReportingService2010();
DestinationRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
DestinationRS.Url = #"http://" + sDestinationServer + "/reportserver/reportservice2010.asmx";
Boolean val = true;
Source_ReportService2010.Policy[] curPolicy = null;
Destination_ReportService2010.Policy[] newPolicy = null;
try
{
curPolicy = new Source_ReportService2010.Policy[1];
curPolicy = sourceRS.GetPolicies(itemPath, out val); //e.g. of itemPath: "/B2W/001_OLD_PuertoRicoReport"
//DestinationRS.SetPolicies(itemPath, newPolicy);
int iCounter = 0;
//int iMax = curPolicy.Length;
newPolicy = new Destination_ReportService2010.Policy[curPolicy.Length];
foreach (Source_ReportService2010.Policy p in curPolicy)
{
//create the Policy
Destination_ReportService2010.Policy pNew = new Destination_ReportService2010.Policy();
pNew.GroupUserName = p.GroupUserName;
pNew.GroupUserName = p.GroupUserName;
Destination_ReportService2010.Role rNew = new Destination_ReportService2010.Role();
rNew.Description = p.Roles[0].Description;
rNew.Name = p.Roles[0].Name;
//create the Role, which is part of the Policy
pNew.Roles = new Destination_ReportService2010.Role[1];
pNew.Roles[0]=rNew;
newPolicy[iCounter] = pNew;
iCounter += 1;
}
DestinationRS.SetPolicies(itemPath, newPolicy);
Debug.Print("whatever");
}
catch (SoapException ex)
{
Debug.Print("SoapException: " + ex.Message);
}
catch (Exception Ex)
{
Debug.Print("NON-SoapException: " + Ex.Message);
}
finally
{
if (sourceRS != null)
sourceRS.Dispose();
if (DestinationRS != null)
DestinationRS.Dispose();
}
}
}
}
To invoke it use the following:
TEST.GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination("/FolderName/ReportName");
Where you have to put your own SSRS Folder Name and Report Name, i.e. the Path to the item.
In fact I use a method that loops through all the items in the Destination folder that then calls the method like this:
internal static void CopyTheSecurityPolicyFromSourceToDestinationForAllItems_2010()
{
string sDestinationServer = "DESTINATION-ServerName";
Destination_ReportService2010.ReportingService2010 DestinationRS = new Destination_ReportService2010.ReportingService2010();
DestinationRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
DestinationRS.Url = #"http://" + sDestinationServer + "/reportserver/reportservice2010.asmx";
// Return a list of catalog items in the report server database
Destination_ReportService2010.CatalogItem[] items = DestinationRS.ListChildren("/", true);
// For each FOLDER, debug Print some properties
foreach (Destination_ReportService2010.CatalogItem ci in items)
{
{
Debug.Print("START----------------------------------------------------");
Debug.Print("Object Name: " + ci.Name);
Debug.Print("Object Type: " + ci.TypeName);
Debug.Print("Object Path: " + ci.Path);
Debug.Print("Object Description: " + ci.Description);
Debug.Print("Object ID: " + ci.ID);
Debug.Print("END----------------------------------------------------");
try
{
GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination(ci.Path);
}
catch (SoapException e)
{
Debug.Print("SoapException START----------------------------------------------------");
Debug.Print(e.Detail.InnerXml);
Debug.Print("SoapException END----------------------------------------------------");
}
catch (Exception ex)
{
Debug.Print("ERROR START----------------------------------------------------");
Debug.Print(ex.GetType().FullName);
Debug.Print(ex.Message);
Debug.Print("ERROR END----------------------------------------------------");
}
}
}
}