I'm trying to register to a CORBA CosNotification Service. In the documentation of the service I'm trying to connect to, it says I have to a CosNotifyComm::SequencePushConsumer object, and attach it to the notification service. I've included my code, and the error I'm getting back.
AlarmClient.java
import NotificationIRPSystem.*;
import org.omg.CosNotification.*;
import org.omg.CosNotifyComm.*;
import org.omg.CosNotifyChannelAdmin.*;
import org.omg.CosNotifyFilter.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
public class AlarmClient
{
static _NotificationIRPOperations notiOp;
public static void main (String args [])
{
try{
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references ("NameService");
System.out.println("IOR===> " + objRef);
NamingContextExt nc = NamingContextExtHelper.narrow(objRef);
String name = "com/ericsson/nms/cif/service/NMSNAConsumer";
String portal = "com/ericsson/nms/cif/service/NMSNAPortal";
org.omg.CORBA.Object notiObj = nc.resolve_str(name);
System.out.println(nc.resolve_str(portal));
System.out.println("noti---->" + notiObj);
_NotificationIRPOperations tt = _NotificationIRPOperationsHelper.narrow(notiObj);
IRPManager irpMan = new IRPManager();
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
org.omg.CORBA.Object objNotiServer = poa.servant_to_reference(irpMan);
String manager_reference = orb.object_to_string(objNotiServer);
System.out.println("MANAGER REF: " + manager_reference);
System.out.println("OBJ NOTI SERVER: " + objNotiServer);
int time_tick = 15;
String filter = "";
String[] asd = {};
NotificationIRPConstDefs.EventTypesSetHolder e_list = new NotificationIRPConstDefs.EventTypesSetHolder();
NotificationIRPConstDefs.ExtendedEventTypesSetHolder ex_list = new NotificationIRPConstDefs.ExtendedEventTypesSet\
Holder();
String cats[] = tt.get_notification_categories(e_list, ex_list);
String res = tt.attach_push(manager_reference, time_tick, asd , filter);
// System.out.println("SUCCESS--->" + res);
// String[] ids = tt.get_subscription_ids(manager_reference);
System.out.println("ALARMIRPOPERATIONS_----> " + tt);
} catch (Exception e){
System.out.println ("ERROR: " + e);
e.printStackTrace (System.out);
}
}
}
IRPManager.java
import NotificationIRPSystem.*;
import org.omg.CosNotification.*;
import org.omg.CosNotifyComm.*;
import org.omg.CosNotifyChannelAdmin.*;
import org.omg.CosNotifyFilter.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
public class IRPManager
extends SequencePushConsumerPOA
{
public void disconnect_sequence_push_consumer()
{
System.out.println("Disconnected!");
}
public void push_structured_events(org.omg.CosNotification.StructuredEvent[] notifications) throws org.omg.CosEvent\
Comm.Disconnected
{
System.out.println("Received Event");
}
public void offer_change(org.omg.CosNotification.EventType[] added, org.omg.CosNotification.EventType[] removed) th\
rows org.omg.CosNotifyComm.InvalidEventType
{
System.out.println("Offer Change!");
}
}
OUTPUT
14-Aug-2013 3:54:02 PM org.jacorb.orb.ORBSingleton <init>
INFO: created ORBSingleton
IOR===> IOR:000000000000001D49444C3A6F6D672E6F72672F434F5242412F4F626A6563743A312E3000000000000000010000000000000040000102000000000F3137322E33302E3132302E3135380000C06600000000000B4E616D655365727669636500000000010000000000000008000000004A414300
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 172.30.120.158:49254 (7bea5671)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 172.30.120.158:49254 from local port 57080
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection close
INFO: Client-side TCP transport to 172.30.120.158:49254 closed.
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 10.20.0.4:49254 (58a17083)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 10.20.0.4:49254 from local port 52574
IOR:000000000000001849444C3A506F7274616C2F53657276696365733A312E300000000001000000000000007C000102000000000A31302E32302E302E3800C27B0000002000504D43000000040000000C2F466163746F7279504F4100000000040000000000000003564953030000000500070801FF000000000000000000000800000000564953000000000100000018000000000001000100000001050100010001010900000000
noti---->IOR:000000000000004449444C3A336770707361352E6F72672F4E6F74696669636174696F6E49525053797374656D2F4E6F74696669636174696F6E4952504F7065726174696F6E733A312E3000000000010000000000000088000102000000000A31302E32302E302E3800C27B0000002C00504D43000000040000000C2F466163746F7279504F4100000000104E4D534E41436F6E73756D6572322E3300000003564953030000000500070801FF000000000000000000000800000000564953000000000100000018000000000001000100000001050100010001010900000000
14-Aug-2013 3:54:03 PM org.jacorb.poa.AOM add
INFO: oid: 00 40 46 20 4B 4D 29 05 2A 07 10 06 30 46 38 14 14 1B 48 4C .#F KM).*...0F8...HL1B .object is activated
14-Aug-2013 3:54:03 PM org.jacorb.poa.POA getImplName
INFO: Using server ID (8624227886) for transient POA
MANAGER REF: IOR:000000000000003349444C3A6F6D672E6F72672F436F734E6F74696679436F6D6D2F53657175656E636550757368436F6E73756D65723A312E300000000000010000000000000050000102000000000E3137322E31362E32342E31353200B91900000020383632343232373838362F004046204B4D29052A07100630463814141B484C1B000000010000000000000008000000004A414300
OBJ NOTI SERVER: IOR:000000000000003349444C3A6F6D672E6F72672F436F734E6F74696679436F6D6D2F53657175656E636550757368436F6E73756D65723A312E300000000000010000000000000050000102000000000E3137322E31362E32342E31353200B91900000020383632343232373838362F004046204B4D29052A07100630463814141B484C1B000000010000000000000008000000004A414300
14-Aug-2013 3:54:03 PM org.jacorb.orb.giop.ClientConnectionManager getConnection
INFO: ClientConnectionManager: created new ClientGIOPConnection to 10.20.0.8:49787 (68e6ff0d)
14-Aug-2013 3:54:03 PM org.jacorb.orb.iiop.ClientIIOPConnection connect
INFO: Connected to 10.20.0.8:49787 from local port 35910
**************************************************************************org.jacorb.orb.giop.RequestOutputStream#1be1a408
14-Aug-2013 3:54:04 PM org.jacorb.orb.iiop.ClientIIOPConnection close
INFO: Client-side TCP transport to 10.20.0.8:49787 closed.
org.omg.CORBA.MARSHAL: Server-side Exception: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at org.jacorb.orb.SystemExceptionHelper.read(SystemExceptionHelper.java:222)
at org.jacorb.orb.ReplyReceiver.getReply(ReplyReceiver.java:456)
at org.jacorb.orb.Delegate._invoke_internal(Delegate.java:1418)
at org.jacorb.orb.Delegate.invoke_internal(Delegate.java:1187)
at org.jacorb.orb.Delegate.invoke(Delegate.java:1175)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:80)
at NotificationIRPSystem.__NotificationIRPOperationsStub.attach_push(__NotificationIRPOperationsStub.java:288)
at AlarmClient.main(AlarmClient.java:43)
I'm not really sure what's happening. I think maybe that the object I'm trying to marshal is different from what the server expects? I hope someone can help, let me know if you need more information or if I missed something.
UPDATE
This is the _NotificationIRPOperationsStub code which contains attach_push
public java.lang.String attach_push(java.lang.String manager_reference, int time_tick, java.lang.String[] notification_category_set, java.lang.String filter) throws NotificationIRPSystem.AlreadySubscribed,NotificationIRPSystem.Attach,NotificationIRPSystem.AtLeast\
OneNotificationCategoryNotSupported,NotificationIRPSystem.ParameterNotSupported,NotificationIRPSystem.InvalidParameter
{
while(true)
{
if(! this._is_local())
{
org.omg.CORBA.portable.InputStream _is = null;
org.omg.CORBA.portable.OutputStream _os = null;
try
{
_os = _request( "attach_push", true);
java.lang.String tmpResult10 = manager_reference;
_os.write_string( tmpResult10 );
_os.write_ulong(time_tick);
NotificationIRPConstDefs.NotificationCategorySetHelper.write(_os,notification_category_set);
java.lang.String tmpResult11 = filter;
_os.write_string( tmpResult11 );
System.out.println("**************************************************************************" + _os.toString());
_is = _invoke(_os);
java.lang.String _result = _is.read_string();
return _result;
}
catch( org.omg.CORBA.MARSHAL m){
m.printStackTrace();
return m.getStackTrace().getClassName();
}
catch( org.omg.CORBA.portable.RemarshalException _rx )
{
continue;
}
catch( org.omg.CORBA.portable.ApplicationException _ax )
{
String _id = _ax.getId();
try
{
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/AlreadySubscribed:1.0"))
{
throw NotificationIRPSystem.AlreadySubscribedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/Attach:1.0"))
{
throw NotificationIRPSystem.AttachHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/AtLeastOneNotificationCategoryNotSupported:1.0"))
{
throw NotificationIRPSystem.AtLeastOneNotificationCategoryNotSupportedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/ParameterNotSupported:1.0"))
{
throw NotificationIRPSystem.ParameterNotSupportedHelper.read(_ax.getInputStream());
}
else
if( _id.equals("IDL:3gppsa5.org/NotificationIRPSystem/InvalidParameter:1.0"))
{
throw NotificationIRPSystem.InvalidParameterHelper.read(_ax.getInputStream());
}
else{
throw new RuntimeException("Unexpected exception " + _id );
}
}
finally
{
try
{
_ax.getInputStream().close();
}
catch (java.io.IOException e)
{
throw new RuntimeException("Unexpected exception " + e.toString() );
}
}
}
finally
{
if (_os != null)
{
try
{
_os.close();
}
catch (java.io.IOException e)
{
throw new RuntimeException("Unexpected exception " + e.toString() );
}
}
this._releaseReply(_is);
}
}
else
{
org.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( "attach_push", _opsClass );
if( _so == null )
continue;
_NotificationIRPOperationsOperations _localServant = (_NotificationIRPOperationsOperations)_so.servant;
java.lang.String _result;
try
{
_result = _localServant.attach_push(manager_reference,time_tick,notification_category_set,filter);
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).normalCompletion();
return _result;
}
catch (NotificationIRPSystem.AlreadySubscribed ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.Attach ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.AtLeastOneNotificationCategoryNotSupported ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.ParameterNotSupported ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (NotificationIRPSystem.InvalidParameter ex)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);
throw ex;
}
catch (RuntimeException re)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(re);
throw re;
}
catch (java.lang.Error err)
{
if ( _so instanceof org.omg.CORBA.portable.ServantObjectExt)
((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(err);
throw err;
}
finally
{
_servant_postinvoke(_so);
}
}
}
}
Thanks.
UPDATE # 2
Thanks to Brian for posting that version of the document. I took the IDL from there, and with a minor adjustment I was able to call attach_push with my objNotiServer. My next question is about how I can set my AlarmClient up to receive these notifications. My assumption is that I can call orb.run() and then when notifications come in, I will receive them in my IRPManager object, is that right?
CORBA::MARSHAL exceptions usually occur because of one of these reasons:
IDL mismatches between client and server (causing unexpected payload differences)
Crappy ORB products that don't know how to unmarshal complex but valid payloads correctly
Reason #2 is really unlikely nowadays, as ORBs have matured enough that this rarely happens. As long as you're using ORB products on both the client and server side that were built in this century then you're probably ok. That leaves reason #1.
The IDL for the method you're calling is (I believe) from this document, and looks like this:
interface NotificationIRPOperations {
NotificationIRPConstDefs::SubscriptionId attach_push (
in Object manager_reference,
in long time_tick,
in NotificationCategorySet notification_category_set,
in string filter
)
raises (Attach, ParameterNotSupported, InvalidParameter, AlreadySubscribed,
AtLeastOneNotificationCategoryNotSupported);
Note the first parameter, it's of type Object. However in your code, you're passing a string. However the IDL type Object maps to org.omg.CORBA.Object in Java, not to a String. I would have expected to see you pass objNotiServer instead for this parameter.
So either your IDL is mismatched with what your server is expecting (likely), or your IDL compiler isn't following the basic IDL-to-Java mapping rules (unlikely).
Either way, something smells bad there. I don't believe that the ORB will implicitly call ORB.string_to_object() for you, so that would lead to a regular string being sent on the network when the server is actually expecting a stringified Object reference. The difference is subtle but it might be the reason why the server is throwing a MARSHAL back at you.
So your first port of call should be a check on the IDL file that you're using to build your client. Make sure that you've got the exact and correct IDL for the server you're trying to call. If there's any mismatch at all then MARSHAL exceptions will happen, and happen a lot.
The server side has a problem, therefor you receive the server side exception.
Your IDL is different on Server/Client which causes this error.
You have to look at the server's logfile. If you do not have access to the server, implement your own dummy-server and find out whether or not it works.
Regarding the manager_reference, test it in your own code via: narrow and a call to _non_existent(). I.e.
org.omg.CORBA.Object managerObj = orb.string_to_object(manager_reference);
IRPManager managerImpl = IRPManagerHelper.narrow(managerObj);
managerImpl._non_existent()
If this works, your IRPManager servant works.
By the way, you have a lot of unused imports and should refactor them. Your IDE would help you.
For Update2
Yout Alarmclient has to implement StructuredPushConsumer (see Initializing Corba notification service in java successfully but cannot get any events in linux but it's done in windows) and subscribe to the notifications.
But I recomment to open a new question.
Your code looks suspicious, you never activate irpMan in the POA, but you do use servant_to_reference. Try the code below, handle it as pseudo code, I haven't tested it and I normally program C++.
IRPManager irpMan = new IRPManager();
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
ObjectId id = poa.activate_object (irpMan);
org.omg.CORBA.Object objNotiServer = poa.id_to_reference(id);
String manager_reference = orb.object_to_string(objNotiServer);
System.out.println("MANAGER REF: " + manager_reference);
System.out.println("OBJ NOTI SERVER: " + objNotiServer);
int time_tick = 15;
String filter = "";
String[] asd = {};
NotificationIRPConstDefs.EventTypesSetHolder e_list = new NotificationIRPConstDefs.EventTypesSetHolder();
NotificationIRPConstDefs.ExtendedEventTypesSetHolder ex_list = new NotificationIRPConstDefs.ExtendedEventTypesSet\
Holder();
String cats[] = tt.get_notification_categories(e_list, ex_list);
String res = tt.attach_push(objNotiServer, time_tick, asd , filter);
Related
I'm running the following test code on SolrCloud using Solrj library:
public static void main(String[] args) {
String zkHostString = "192.168.56.99:2181";
SolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHostString).build();
List<MyBean> beans = new ArrayList<>();
for(int i = 0; i < 10000 ; i++) {
// creating a bunch of MyBean to be indexed
// and temporarily storing them in a List
// no Solr operations performed here
}
System.out.println("Adding...");
try {
solr.addBeans("myCollection", beans);
} catch (IOException | SolrServerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Committing...");
try {
solr.commit("myCollection");
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This code fails due to the following exception
Exception in thread "main" java.lang.NullPointerException
at org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:1175)
at org.apache.solr.client.solrj.impl.CloudSolrClient.request(CloudSolrClient.java:1057)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:106)
at org.apache.solr.client.solrj.SolrClient.addBeans(SolrClient.java:357)
at org.apache.solr.client.solrj.SolrClient.addBeans(SolrClient.java:312)
at com.togather.solr.testing.SolrIndexingTest.main(SolrIndexingTest.java:83)
This is the full stacktrace of the exception. I just "upgraded" from a Solr standalone installation to a SolrCloud (with an external Zookeeper single instance, not the embedded one). With standalone Solr the same code (with just some minor differences, like the host URL) used to work perfectly.
The NPE sends me inside the SolrJ library, which I don't know.
Anyone can help me understand where the problem originates from and how I can overcome it? Due to my unexperience and the brevity of the error message, I can't figure out where to start inquiring from.
Looking at your code, I would suggest to specify the default collection as first thing.
CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHostString).build();
solr.setDefaultCollection("myCollection");
Regarding the NPE you're experiencing, very likely is due to a network error.
In these lines your exception is raised by for loop: for (DocCollection ext : requestedCollections)
if (wasCommError) {
// it was a communication error. it is likely that
// the node to which the request to be sent is down . So , expire the state
// so that the next attempt would fetch the fresh state
// just re-read state for all of them, if it has not been retired
// in retryExpiryTime time
for (DocCollection ext : requestedCollections) {
ExpiringCachedDocCollection cacheEntry = collectionStateCache.get(ext.getName());
if (cacheEntry == null) continue;
cacheEntry.maybeStale = true;
}
if (retryCount < MAX_STALE_RETRIES) {//if it is a communication error , we must try again
//may be, we have a stale version of the collection state
// and we could not get any information from the server
//it is probably not worth trying again and again because
// the state would not have been updated
return requestWithRetryOnStaleState(request, retryCount + 1, collection);
}
}
I'm trying to create Internal Accounts programmaticaly by using proc metadata.
The code section below creates person with External Login.
put"<Person Name=%str(%')&&PersonName&i.%str(%')>";
put"<Logins>";
put"<Login Name=%str(%')Login.&&PersonName&i.%str(%') Password=%str(%')&&word&i.%str(%')/>";
put"</Logins>";
put"</Person>";
To create ExternalLogin we can set attribute Password, and in SAS Metadata it will be encrypted automaticaly.
But to create InternalLogin type of object it is necessary to make the hash value of the password and the salt. I know that the standard sas002 encryption method, but in the case of using proc pwencode how to obtain the value of salt?
Is it possible create InternalLogin by using SAS Base?
Thanx.
So on. I found an article that can tell us how to create Stored Process for this problem. My answer is addition to the article.
The approach is base on execute java methods from sas programm.
1. Prerare setPasswd.java class
I've modified class from article. Separate code to connect to metadata server and create InternalLogin
import java.rmi.RemoteException;
import com.sas.metadata.remote.AssociationList;
import com.sas.metadata.remote.CMetadata;
import com.sas.metadata.remote.Person;
import com.sas.metadata.remote.MdException;
import com.sas.metadata.remote.MdFactory;
import com.sas.metadata.remote.MdFactoryImpl;
import com.sas.metadata.remote.MdOMIUtil;
import com.sas.metadata.remote.MdOMRConnection;
import com.sas.metadata.remote.MdObjectStore;
import com.sas.metadata.remote.MetadataObjects;
import com.sas.metadata.remote.PrimaryType;
import com.sas.metadata.remote.Tree;
import com.sas.meta.SASOMI.ISecurity_1_1;
import com.sas.iom.SASIOMDefs.VariableArray2dOfStringHolder;
public class setPasswd {
String serverName = null;
String serverPort = null;
String serverUser = null;
String serverPass = null;
MdOMRConnection connection = null;
MdFactoryImpl _factory = null;
ISecurity_1_1 iSecurity = null;
MdObjectStore objectStore = null;
Person person = null;
public int connectToMetadata(String name, String port, String user, String pass){
try {
serverName = name;
serverPort = port;
serverUser = user;
serverPass = pass;
_factory = new MdFactoryImpl(false);
connection = _factory.getConnection();
connection.makeOMRConnection(serverName, serverPort, serverUser, serverPass);
iSecurity = connection.MakeISecurityConnection();
return 0;
}catch(Exception e){
return 1;
}
}
public setPasswd(){};
public int changePasswd(String IdentityName, String IdentityPassword) {
try
{
//
// This block obtains the person metadata ID that is needed to change the password
//
// Defines the GetIdentityInfo 'ReturnUnrestrictedSource' option.
final String[][] options ={{"ReturnUnrestrictedSource",""}};
// Defines a stringholder for the info output parameter.
VariableArray2dOfStringHolder info = new VariableArray2dOfStringHolder();
// Issues the GetInfo method for the provided iSecurity connection user.
iSecurity.GetInfo("GetIdentityInfo","Person:"+IdentityName, options, info);
String[][] returnArray = info.value;
String personMetaID = new String();
for (int i=0; i< returnArray.length; i++ )
{
System.out.println(returnArray[i][0] + "=" + returnArray[i][1]);
if (returnArray[i][0].compareTo("IdentityObjectID") == 0) {
personMetaID = returnArray[i][1];
}
}
objectStore = _factory.createObjectStore();
person = (Person) _factory.createComplexMetadataObject(objectStore, IdentityName, MetadataObjects.PERSON, personMetaID);
iSecurity.SetInternalPassword(IdentityName, IdentityPassword);
person.updateMetadataAll();
System.out.println("Password has been changed.");
return 0; // success
}
catch (MdException e)
{
Throwable t = e.getCause();
if (t != null)
{
String ErrorType = e.getSASMessageSeverity();
String ErrorMsg = e.getSASMessage();
if (ErrorType == null)
{
// If there is no SAS server message, write a Java/CORBA message.
}
else
{
// If there is a message from the server:
System.out.println(ErrorType + ": " + ErrorMsg);
}
if (t instanceof org.omg.CORBA.COMM_FAILURE)
{
// If there is an invalid port number or host name:
System.out.println(e.getLocalizedMessage());
}
else if (t instanceof org.omg.CORBA.NO_PERMISSION)
{
// If there is an invalid user ID or password:
System.out.println(e.getLocalizedMessage());
}
}
else
{
// If we cannot find a nested exception, get message and print.
System.out.println(e.getLocalizedMessage());
}
// If there is an error, print the entire stack trace.
e.printStackTrace();
}
catch (RemoteException e)
{
// Unknown exception.
e.printStackTrace();
}
catch (Exception e)
{
// Unknown exception.
e.printStackTrace();
}
System.out.println("Failure: Password has NOT been changed.");
return 1; // failure
}
}
2. Resolve depends
Pay attention to imports in class. To enable execute the code below necessary set CLASSPATH enironment variable.
On linux you can add the next command in %SASConfig%/Lev1/level_env_usermods.sh:
export CLASSPATH=$CLASSPATH:%pathToJar%
On Windows you can add/change environment variable by Advanced system settings
So where should you search jar files? They are in folder:
%SASHome%/SASVersionedJarRepository/eclipse/plugins/
Which files i should include in path?
I've include all that used in OMI(Open Metadata Interface).Also I've added log4j.jar (not working without this jar. Your promts will be helpful):
sas.oma.joma.jar
sas.oma.joma.rmt.jar
sas.oma.omi.jar
sas.svc.connection.jar
sas.core.jar
sas.entities.jar
sas.security.sspi.jar
log4j.jar
setPasswd.jar (YOUR JAR FROM THE NEXT STEP!)
Choose files from nearest release. Example:
Here I'm set file from v940m3f (fix release).
Other ways is here.
3. Compile setPasswd.jar
I'm tried use internal javac.exe into SAS, but it's not worked properly. So ou need to download JDK to compile jars. I've create Bat-file:
"C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe" -source 1.7 -target 1.7 setPasswd.java
"C:\Program Files\Java\jdk1.8.0_121\bin\jar" -cf setPasswd.jar setPasswd.class
Paramethers -source and -target will helpful if your version of JDK is upper, that usses in SAS. Version of "sas"-java you can see by:
PROC javainfo all;
run;
Search the next string in log:
java.vm.specification.version = 1.7
4. Finally. SAS Base call
Now we can call Java code by this method (All methods available here):
data test;
dcl javaobj j ("setPasswd");
j.callIntMethod("connectToMetadata", "%SERVER%", "%PORT%", "%ADMIN%", "%{SAS002}HASHPASSORPASS%", rc1);
j.callIntMethod("changePasswd", "testPassLogin", "pass1", rc2);
j.delete();
run;
In log:
UserClass=Normal
AuthenticatedUserid=Unknown
IdentityName=testPass
IdentityType=Person
IdentityObjectID=A56RQPC2.AP00000I
Password has been changed.
Now time to test. Create new user with no passwords.
Execute code:
data test;
dcl javaobj j ("setPasswd");
j.callIntMethod("connectToMetadata", "&server.", "&port.", "&adm", "&pass", rc1);
j.callIntMethod("changePasswd", "TestUserForStack", "Overflow", rc2);
j.delete();
run;
Now our user has InternalLogin object.
Thanx.
I am new to AWS, Can any one please help me how to create users on virtual machine using java code. I have created windows ec2 instance and able to connect using sshClient, but unable to create users. I dont have any idea about how it can be done.
[I am new to stack overflow please forgive me if wrong formatting]
Answering my own question... It may help someone..
You can use execute command to create user on remote windows...
Example:
public boolean executeCommands(String commands, SSHRequestParam param)
throws Exception,IOException {
boolean response = false;
try {
Connection conn = getConnection(param);
Session sess = conn.openSession();
sess.execCommand(commands);
sess.waitForCondition(ChannelCondition.EXIT_SIGNAL, 0);
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(
new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null)
break;
response=true;
System.out.println(line);
}
InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader br1 = new BufferedReader(new InputStreamReader(
stderr));
while (true) {
String line = br1.readLine();
if (line == null)
break;
response=false;
System.out.println(line);
}
/* Show exit status, if available (otherwise "null") */
System.out.println("ExitCode: " + sess.getExitStatus());
/* Close this session */
System.out.println("closing session");
sess.close();
closeConnection(conn);
} catch (IOException e) {
System.out.println("Exception..while executing command.: " + commands);
e.printStackTrace();
}
System.out.println("Command executed : "+response);
return response;
}
public void createUser(String userName, String password,SSHRequestParam param)
throws Exception,IOException {
String command = "net user " +userName+" "+password+" /add" ;
if(executeCommands(command,param))
System.out.println("User created successfully");
else
System.out.println("User didn't create....");
}
In above example param variable stores the parameters to connect to the server i.e. hostname, username, password....
I am implementing small Java ME app. This app gets some data from 3rd patty resource and needs to be authenticated before. I do first call for get cookies (it was easy), and the second call with this cookies for get data. I googled a little how to do it, and found next solution - Deal with cookie with J2ME
I have changed this code to next for my purpose:
public void getData(String url,String cookie) {
HttpConnection hpc = null;
InputStream is = null;
try {
hpc = (HttpConnection) Connector.open(url);
hpc.setRequestProperty("cookie", cookie);
hpc.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
hpc.setRequestProperty("Accept-Encoding", "gzip, deflate");
hpc.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
is = hpc.openInputStream();
int length = (int) hpc.getLength();
byte[] response = new byte[length];
is.read(response);
String strResponse = new String(response);
} catch (Exception e) {
System.out.println(e.getMessage() + " " + e.toString());
} finally {
try {
if (is != null)
is.close();
if (hpc != null)
hpc.close();
} catch (Exception e) {}
}
}
I get something like to the next
??ÑÁNÃ0à;O±(²§M}A-?#
.?PYS¨Ôe¥Í#\üìde??XÊo}Vâ]hk?6ëµóA|µvÞz'Íà?wAúêmw4í0?ÐÆ?ÚMW=?òêz CÛUa:6Ö7¼T?<oF?nh6[_0?l4?äê&)?çó³?ÅÕúf¨ä(.? ªDÙ??§?ÊP+??(:?Á,Si¾ïA¥ã-jJÅÄ8ÊbBçL)gs.S.þG5ÌÀÆéX}CÁíÑ-þ?BDK`²?\¶?ó3I÷ô±e]°6¬c?q?Ó?¼?Y.¯??Y?%?ÏP1è?ìw;?È Ò??e
|ôh0?
How can I decode this?
Stupid me. I didn't take to consideration next code: hpc.setRequestProperty("Accept-Encoding", "gzip, deflate"); I get coded in ZIP response and everything that I need it decode it.
I created a web service stub using NetBeans 7.0 and when I try using it, it throws an unknown Exception. I don't even know what part of my code to show here, all I know is that bolded line generates an unknown Exception:
public Businesses[] findBusiness(String query) throws java.rmi.RemoteException {
Object inputObject[] = new Object[]{
query
};
Operation op = Operation.newInstance(_qname_operation_findBusiness, _type_findBusiness, _type_findBusinessResponse);
_prepOperation(op);
op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "");
Object resultObj;
try {
resultObj = op.invoke(inputObject);
} catch (JAXRPCException e) {
Throwable cause = e.getLinkedCause();
if (cause instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) cause;
}
throw e;
}
return businesses_ArrayfromObject((Object[]) resultObj);
}
private static Businesses[] businesses_ArrayfromObject(Object obj[]) {
if (obj == null) {
return null;
}
Businesses result[] = new Businesses[obj.length];
for (int i = 0; i < obj.length; i++) {
result[i] = new Businesses();
Object[] oo = (Object[]) obj[i];
result[i].setAddress((String) oo[0]); // **exception here**
result[i].setEmail((String) oo[1]);
result[i].setId((Integer) oo[2]);
result[i].setName((String) oo[3]);
result[i].setPhoneno((String) oo[4]);
result[i].setProducts((String) oo[5]);
}
return result;
}`
I tried to consume the same webservice using a web application and it works quite well. I don't have a single clue to what is causing this exception. Any comment would be appreciated.
Update
I tried other services that return a String data type and it works fine. So I thought maybe J2ME has issues with JPA Entity types.
So my question is how do I return the data properly so that the J2ME client can read it well?