List of usage examples for java.lang ClassNotFoundException getMessage
public String getMessage()
From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; HttpParams params = getParams();/*ww w .j ava 2 s .c om*/ ClientConnectionManagerFactory factory = null; String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try { Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new SingleClientConnManager(registry); } return connManager; }
From source file:org.mwc.debrief.editable.test.EditableTests.java
private Editable getEditable(IType type) { Editable editable = null;/*from ww w. j a va 2 s. c o m*/ switch (type.getFullyQualifiedName()) { case "Debrief.Wrappers.SensorWrapper": SensorWrapper sensor = new SensorWrapper("tester"); final java.util.Calendar cal = new java.util.GregorianCalendar(2001, 10, 4, 4, 4, 0); // and create the list of sensor contact data items cal.set(2001, 10, 4, 4, 4, 0); sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null, null, null, 1, sensor.getName())); cal.set(2001, 10, 4, 4, 4, 23); sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null, null, null, 1, sensor.getName())); editable = sensor; break; case "MWC.GUI.Shapes.ChartFolio": editable = new ChartFolio(false, Color.white); break; case "org.mwc.cmap.naturalearth.wrapper.NELayer": editable = new NELayer(Activator.getDefault().getDefaultStyleSet()); break; case "MWC.GUI.VPF.CoverageLayer$ReferenceCoverageLayer": final LibrarySelectionTable LST = null; final DebriefFeatureWarehouse myWarehouse = new DebriefFeatureWarehouse(); final FeaturePainter fp = new FeaturePainter("libref", "Coastline"); fp.setVisible(true); editable = new CoverageLayer.ReferenceCoverageLayer(LST, myWarehouse, "libref", "libref", "Coastline", fp); break; case "MWC.GUI.Chart.Painters.ETOPOPainter": editable = new ETOPOPainter("etopo", null); break; case "MWC.GUI.ETOPO.ETOPO_2_Minute": editable = new ETOPO_2_Minute("etopo"); break; case "MWC.GUI.ExternallyManagedDataLayer": editable = new ExternallyManagedDataLayer("test", "test", "test"); break; case "MWC.GUI.Shapes.CircleShape": editable = new CircleShape(new WorldLocation(2d, 2d, 2d), 2d); break; case "Debrief.Wrappers.Track.SplittableLayer": editable = new SplittableLayer(true); break; case "org.mwc.debrief.satc_interface.data.SATC_Solution": final ISolversManager solvMgr = SATC_Activator.getDefault().getService(ISolversManager.class, true); final ISolver newSolution = solvMgr.createSolver("test"); editable = new SATC_Solution(newSolution); break; case "MWC.GUI.Shapes.PolygonShape": editable = new PolygonShape(null); break; case "ASSET.GUI.Painters.NoiseSourcePainter": editable = new ASSET.GUI.Painters.NoiseSourcePainter.PainterTest().getEditable(); break; case "ASSET.GUI.Painters.ScenarioNoiseLevelPainter": editable = new ASSET.GUI.Painters.ScenarioNoiseLevelPainter.NoiseLevelTest().getEditable(); break; case "ASSET.GUI.Workbench.Plotters.ScenarioParticipantWrapper": editable = new ScenarioParticipantWrapper(new SSN(12), null); break; case "Debrief.Wrappers.PolygonWrapper": // get centre of area WorldLocation centre = new WorldLocation(12, 12, 12); // create the shape, based on the centre final Vector<PolygonNode> path2 = new Vector<PolygonNode>(); final PolygonShape newShape = new PolygonShape(path2); // and now wrap the shape final PolygonWrapper theWrapper = new PolygonWrapper("New Polygon", newShape, PlainShape.DEFAULT_COLOR, null); // store the new point newShape.add(new PolygonNode("1", centre, (PolygonShape) theWrapper.getShape())); editable = theWrapper; break; case "Debrief.Wrappers.Track.AbsoluteTMASegment": WorldSpeed speed = new WorldSpeed(5, WorldSpeed.Kts); double course = 33; WorldLocation origin = new WorldLocation(12, 12, 12); HiResDate startTime = new HiResDate(11 * 60 * 1000); HiResDate endTime = new HiResDate(17 * 60 * 1000); editable = new AbsoluteTMASegment(course, speed, origin, startTime, endTime); break; case "Debrief.Wrappers.Track.RelativeTMASegment": speed = new WorldSpeed(5, WorldSpeed.Kts); course = 33; final WorldVector offset = new WorldVector(12, 12, 0); editable = new RelativeTMASegment(course, speed, offset, null); break; case "Debrief.Wrappers.Track.PlanningSegment": speed = new WorldSpeed(5, WorldSpeed.Kts); course = 33; final WorldDistance worldDistance = new WorldDistance(5, WorldDistance.MINUTES); editable = new PlanningSegment("test", course, speed, worldDistance, Color.WHITE); break; case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper": BearingMeasurementContribution bmc = new BearingMeasurementContribution(); bmc.setName("Measured bearing"); bmc.setAutoDetect(false); editable = new BMC_Wrapper(bmc); break; case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper": FrequencyMeasurementContribution fmc = new FrequencyMeasurementContribution(); fmc.setName("Measured frequence"); editable = new FMC_Wrapper(fmc); break; case "Debrief.Wrappers.SensorContactWrapper": origin = new WorldLocation(0, 0, 0); editable = new SensorContactWrapper("blank track", new HiResDate(new java.util.Date().getTime()), new WorldDistance(1, WorldDistance.DEGS), 55d, origin, java.awt.Color.red, "my label", 1, "theSensorName"); break; case "Debrief.Wrappers.FixWrapper": final Fix fx = new Fix(new HiResDate(12, 0), new WorldLocation(2d, 2d, 2d), 2d, 2d); final TrackWrapper tw = new TrackWrapper(); tw.setName("here ew arw"); FixWrapper ed = new FixWrapper(fx); ed.setTrackWrapper(tw); editable = ed; break; case "Debrief.Wrappers.ShapeWrapper": centre = new WorldLocation(2d, 2d, 2d); editable = new ShapeWrapper("new ellipse", new EllipseShape(centre, 0, new WorldDistance(0, WorldDistance.DEGS), new WorldDistance(0, WorldDistance.DEGS)), java.awt.Color.red, null); break; case "Debrief.GUI.Tote.Painters.PainterManager": final StepControl stepper = new Debrief.GUI.Tote.Swing.SwingStepControl(null, null, null, null, null, null); editable = new PainterManager(stepper); break; case "Debrief.Wrappers.TMAContactWrapper": origin = new WorldLocation(2, 2, 0); final HiResDate theDTG = new HiResDate(new java.util.Date().getTime()); final EllipseShape theEllipse = new EllipseShape(origin, 45, new WorldDistance(10, WorldDistance.DEGS), new WorldDistance(5, WorldDistance.DEGS)); theEllipse.setName("test ellipse"); editable = new TMAContactWrapper("blank sensor", "blank track", theDTG, origin, 5d, 6d, 1d, Color.pink, "my label", theEllipse, "some symbol"); break; case "MWC.GUI.JFreeChart.NewFormattedJFreeChart": XYPlot plot = new XYPlot(); DefaultXYItemRenderer renderer = new DefaultXYItemRenderer(); plot.setRenderer(renderer); editable = new NewFormattedJFreeChart("test", new java.awt.Font("Dialog", 0, 18), plot, false); break; case "org.mwc.cmap.core.ui_support.swt.SWTCanvasAdapter": final Editable[] edit = new Editable[1]; Display.getDefault().syncExec(new Runnable() { @Override public void run() { edit[0] = new SWTCanvasAdapter(null); } }); editable = edit[0]; break; case "ASSET.Models.Decision.Conditions.OrCondition": System.out.println(type.getFullyQualifiedName() + " hasn't public constructor."); return null; case "ASSET.Models.Decision.Movement.RectangleWander": final WorldLocation topLeft = SupportTesting.createLocation(0, 10000); final WorldLocation bottomRight = SupportTesting.createLocation(10000, 0); final WorldArea theArea = new WorldArea(topLeft, bottomRight); editable = new RectangleWander(theArea, "rect wander"); break; case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper$BearingMeasurementWrapper": bmc = new BearingMeasurementContribution(); bmc.setName("Measured bearing"); bmc.setAutoDetect(false); CoreMeasurement cm = new CoreMeasurement(new Date()); BMC_Wrapper bmcw = new BMC_Wrapper(bmc); editable = bmcw.new BearingMeasurementWrapper(cm); break; case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper$FrequencyMeasurementEditable": fmc = new FrequencyMeasurementContribution(); fmc.setName("Measured frequence"); FMC_Wrapper fmcw = new FMC_Wrapper(fmc); cm = new CoreMeasurement(new Date()); editable = fmcw.new FrequencyMeasurementEditable(cm); break; case "ASSET.GUI.SuperSearch.Plotters.SSGuiSupport$ParticipantListener": SSGuiSupport ssgs = new SSGuiSupport(); ssgs.setScenario(new MultiForceScenario()); editable = new SSGuiSupport.ParticipantListener(new CoreParticipant(12), ssgs); break; case "ASSET.GUI.Workbench.Plotters.BasePlottable": // skip it return null; case "MWC.TacticalData.GND.GTrack": // skip it return null; default: break; } if (editable != null) { return editable; } Class<?> clazz; try { clazz = Class.forName(type.getFullyQualifiedName()); } catch (ClassNotFoundException e1) { //e1.printStackTrace(); System.out.println("CNFE " + e1.getMessage() + " " + type.getFullyQualifiedName()); return null; } try { @SuppressWarnings("unused") Method infoMethod = clazz.getDeclaredMethod("getInfo", new Class[0]); } catch (Exception e) { return null; } try { editable = (Editable) clazz.newInstance(); } catch (Exception e) { Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { try { Class<?>[] paramTypes = constructor.getParameterTypes(); Object[] params = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { Class<?> paramType = paramTypes[i]; if (HiResDate.class.equals(paramType)) { params[i] = new HiResDate(new Date()); } else if (WorldDistance.class.equals(paramType)) { params[i] = new WorldDistance(12d, WorldDistance.DEGS); } else if (WorldSpeed.class.equals(paramType)) { params[i] = new WorldSpeed(12, WorldSpeed.M_sec); } else if (WorldLocation.class.equals(paramType)) { params[i] = new WorldLocation(12, 12, 12); } else if ("java.lang.String".equals(paramType.getName())) { params[i] = "test"; } else if (!paramType.isPrimitive()) { params[i] = null; } else { if (paramType.equals(int.class)) { params[i] = new Integer("0"); } if (paramType.equals(boolean.class)) { params[i] = Boolean.FALSE; } if (paramType.equals(long.class)) { params[i] = new Long("0"); } if (paramType.equals(double.class)) { params[i] = new Double("0"); } if (paramType.equals(float.class)) { params[i] = new Float("0"); } if (paramType.equals(short.class)) { params[i] = new Short("0"); } } } editable = (Editable) constructor.newInstance(params); break; } catch (Exception e1) { // ignore //System.out.println(e1.getMessage()); //e1.printStackTrace(); } } } if (editable == null) { System.out.println("Can't instantiate type " + type.getFullyQualifiedName()); } return editable; }
From source file:org.apache.http.impl.client.AbstractHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { final SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; final HttpParams params = getParams(); ClientConnectionManagerFactory factory = null; final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try {/*from w w w.ja v a2s . c o m*/ final Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (final ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (final InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new BasicClientConnectionManager(registry); } return connManager; }
From source file:org.apache.axis2.jaxws.spi.ServiceDelegate.java
public <T> T getPort(org.apache.axis2.addressing.EndpointReference axis2EPR, String addressingNamespace, Class<T> sei, WebServiceFeature... features) { verifyServiceDescriptionActive();/*www . j a v a2s .c om*/ DescriptionBuilderComposite sparseComposite = getPortMetadata(); resetPortMetadata(); EndpointDescription endpointDesc = null; if (sparseComposite != null) { endpointDesc = DescriptionFactory.updateEndpoint(serviceDescription, sei, axis2EPR, addressingNamespace, DescriptionFactory.UpdateType.GET_PORT, sparseComposite, this); } else { endpointDesc = DescriptionFactory.updateEndpoint(serviceDescription, sei, axis2EPR, addressingNamespace, DescriptionFactory.UpdateType.GET_PORT, null, this); } if (endpointDesc == null) { throw ExceptionFactory .makeWebServiceException(Messages.getMessage("serviceDelegateNoPort", axis2EPR.toString())); } String[] interfacesNames = new String[] { sei.getName(), org.apache.axis2.jaxws.spi.BindingProvider.class.getName() }; // As required by java.lang.reflect.Proxy, ensure that the interfaces // for the proxy are loadable by the same class loader. Class[] interfaces = null; // First, let's try loading the interfaces with the SEI classLoader ClassLoader classLoader = getClassLoader(sei); try { interfaces = loadClasses(classLoader, interfacesNames); } catch (ClassNotFoundException e1) { // Let's try with context classLoader now classLoader = getContextClassLoader(); try { interfaces = loadClasses(classLoader, interfacesNames); } catch (ClassNotFoundException e2) { throw ExceptionFactory .makeWebServiceException(Messages.getMessage("serviceDelegateProxyError", e2.getMessage())); } } JAXWSProxyHandler proxyHandler = new JAXWSProxyHandler(this, interfaces[0], endpointDesc, axis2EPR, addressingNamespace, features); Object proxyClass = Proxy.newProxyInstance(classLoader, interfaces, proxyHandler); return sei.cast(proxyClass); }
From source file:org.apache.http2.impl.client.AbstractHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; HttpParams params = getParams();/* w ww.j a v a2 s . c o m*/ ClientConnectionManagerFactory factory = null; String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try { Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new BasicClientConnectionManager(registry); } return connManager; }
From source file:ch.rgw.tools.JdbcLink.java
/** * Verbindung zur Datenbank herstellen//from w w w . j a va2 s. c o m * * TODO return value is always true because exception is thrown on error * * @param user * Username, kann null sein * @param password * Passwort, kann null sein * @return errcode * * @throws JdbcLinkException */ public boolean connect(String user, String password) { Exception cause = null; try { sUser = user; sPwd = password; Driver driver = (Driver) Class.forName(sDrv).newInstance(); verMajor = driver.getMajorVersion(); verMinor = driver.getMinorVersion(); log.log(Level.INFO, "Loading database driver " + sDrv); log.log(Level.INFO, "Connecting with database " + sConn); // // First, we'll create a ConnectionFactory that the // pool will use to create Connections. // Properties properties = new Properties(); properties.put("user", user); properties.put("password", password); ConnectionFactory connectionFactory = new DriverConnectionFactory(driver, sConn, properties); // // Next we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // connectionPool = new GenericObjectPool<Connection>(null); // configure the connection pool connectionPool.setMaxActive(32); connectionPool.setMinIdle(2); connectionPool.setMaxWait(10000); connectionPool.setTestOnBorrow(true); new PoolableConnectionFactory(connectionFactory, connectionPool, null, VALIDATION_QUERY, false, true); dataSource = new PoolingDataSource(connectionPool); // test establishing a connection Connection conn = dataSource.getConnection(); conn.close(); lastErrorCode = CONNECT_SUCCESS; lastErrorString = "Connect successful"; log.log("Connect successful", Log.DEBUGMSG); return true; } catch (ClassNotFoundException ex) { lastErrorCode = CONNECT_CLASSNOTFOUND; lastErrorString = "Class not found exception: " + ex.getMessage(); cause = ex; } catch (InstantiationException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Instantiation exception: " + e.getMessage(); cause = e; } catch (IllegalAccessException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal access exception: " + e.getMessage(); cause = e; } catch (SQLException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "SQL exception: " + e.getMessage(); cause = e; } catch (IllegalStateException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal state exception: " + e.getMessage(); cause = e; } throw JdbcLinkExceptionTranslation.translateException("Connect failed: " + lastErrorString, cause); }
From source file:com.evolveum.midpoint.web.component.objectdetails.FocusMainPanel.java
protected WebMarkupContainer createTabPanel(String panelId, FormSpecificationType formSpecificationType, PageAdminObjectDetails<F> parentPage) { String panelClassName = formSpecificationType.getPanelClass(); Class<?> panelClass;//from w w w . java 2 s . c o m try { panelClass = Class.forName(panelClassName); } catch (ClassNotFoundException e) { throw new SystemException( "Panel class '" + panelClassName + "' as specified in admin GUI configuration was not found", e); } if (AbstractFocusTabPanel.class.isAssignableFrom(panelClass)) { Constructor<?> constructor; try { constructor = panelClass.getConstructor(String.class, Form.class, LoadableModel.class, LoadableModel.class, PageBase.class); } catch (NoSuchMethodException | SecurityException e) { throw new SystemException( "Unable to locate constructor (String,Form,LoadableModel,LoadableModel,LoadableModel,PageBase) in " + panelClass + ": " + e.getMessage(), e); } AbstractFocusTabPanel<F> tabPanel; try { tabPanel = (AbstractFocusTabPanel<F>) constructor.newInstance(panelId, getMainForm(), getObjectModel(), projectionModel, parentPage); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new SystemException("Error instantiating " + panelClass + ": " + e.getMessage(), e); } return tabPanel; } else if (AbstractObjectTabPanel.class.isAssignableFrom(panelClass)) { Constructor<?> constructor; try { constructor = panelClass.getConstructor(String.class, Form.class, LoadableModel.class, PageBase.class); } catch (NoSuchMethodException | SecurityException e) { throw new SystemException("Unable to locate constructor (String,Form,LoadableModel,PageBase) in " + panelClass + ": " + e.getMessage(), e); } AbstractObjectTabPanel<F> tabPanel; try { tabPanel = (AbstractObjectTabPanel<F>) constructor.newInstance(panelId, getMainForm(), getObjectModel(), parentPage); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new SystemException("Error instantiating " + panelClass + ": " + e.getMessage(), e); } return tabPanel; } else { throw new UnsupportedOperationException( "Tab panels that are not subclasses of AbstractObjectTabPanel or AbstractFocusTabPanel are not supported yet (got " + panelClass + ")"); } }
From source file:com.gemstone.gemfire.management.internal.cli.functions.DataCommandFunction.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public DataCommandResult locateEntry(String key, String keyClass, String valueClass, String regionPath, boolean recursive) { Cache cache = CacheFactory.getAnyInstance(); if (regionPath == null || regionPath.isEmpty()) { return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__REGIONNAME_EMPTY, false); }/*w w w. j ava 2 s . co m*/ if (key == null || key.isEmpty()) { return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_EMPTY, false); } List<Region> listofRegionStartingwithRegionPath = new ArrayList<Region>(); if (recursive) { // Recursively find the keys starting from the specified region path. List<String> regionPaths = getAllRegionPaths(cache, true); for (int i = 0; i < regionPaths.size(); i++) { String path = regionPaths.get(i); if (path.startsWith(regionPath) || path.startsWith(Region.SEPARATOR + regionPath)) { Region targetRegion = cache.getRegion(path); listofRegionStartingwithRegionPath.add(targetRegion); } } if (listofRegionStartingwithRegionPath.size() == 0) { if (logger.isDebugEnabled()) logger.debug("Region Not Found - {}", regionPath); return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND, regionPath), false); } } else { Region region = cache.getRegion(regionPath); if (region == null) { if (logger.isDebugEnabled()) logger.debug("Region Not Found - {}", regionPath); return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND, regionPath), false); } else listofRegionStartingwithRegionPath.add(region); } Object keyObject = null; try { keyObject = getClassObject(key, keyClass); } catch (ClassNotFoundException e) { logger.fatal(e.getMessage(), e); return DataCommandResult.createLocateEntryResult(key, null, null, "ClassNotFoundException " + keyClass, false); } catch (IllegalArgumentException e) { logger.fatal(e.getMessage(), e); return DataCommandResult.createLocateEntryResult(key, null, null, "Error in converting JSON " + e.getMessage(), false); } Object value = null; DataCommandResult.KeyInfo keyInfo = null; keyInfo = new DataCommandResult.KeyInfo(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); keyInfo.setHost(member.getHost()); keyInfo.setMemberId(member.getId()); keyInfo.setMemberName(member.getName()); for (Region region : listofRegionStartingwithRegionPath) { if (region instanceof PartitionedRegion) { //Following code is adaptation of which.java of old Gfsh PartitionedRegion pr = (PartitionedRegion) region; Region localRegion = PartitionRegionHelper.getLocalData((PartitionedRegion) region); value = localRegion.get(keyObject); if (value != null) { DistributedMember primaryMember = PartitionRegionHelper.getPrimaryMemberForKey(region, keyObject); int bucketId = pr.getKeyInfo(keyObject).getBucketId(); boolean isPrimary = member == primaryMember; keyInfo.addLocation(new Object[] { region.getFullPath(), true, getJSONForNonPrimitiveObject(value)[1], isPrimary, "" + bucketId }); } else { if (logger.isDebugEnabled()) logger.debug("Key is not present in the region {}", regionPath); return DataCommandResult.createLocateEntryInfoResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_NOT_FOUND_REGION, false); } } else { if (region.containsKey(keyObject)) { value = region.get(keyObject); if (logger.isDebugEnabled()) logger.debug("Get for key {} value {} in region {}", key, value, region.getFullPath()); if (value != null) keyInfo.addLocation(new Object[] { region.getFullPath(), true, getJSONForNonPrimitiveObject(value)[1], false, null }); else keyInfo.addLocation(new Object[] { region.getFullPath(), false, null, false, null }); } else { if (logger.isDebugEnabled()) logger.debug("Key is not present in the region {}", regionPath); keyInfo.addLocation(new Object[] { region.getFullPath(), false, null, false, null }); } } } if (keyInfo.hasLocation()) { return DataCommandResult.createLocateEntryResult(key, keyInfo, null, null, true); } else { return DataCommandResult.createLocateEntryInfoResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_NOT_FOUND_REGION, false); } }
From source file:org.apache.geode.management.internal.cli.functions.DataCommandFunction.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public DataCommandResult locateEntry(String key, String keyClass, String valueClass, String regionPath, boolean recursive) { Cache cache = CacheFactory.getAnyInstance(); if (regionPath == null || regionPath.isEmpty()) { return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__REGIONNAME_EMPTY, false); }//w w w . j a v a 2 s . c o m if (key == null || key.isEmpty()) { return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_EMPTY, false); } List<Region> listofRegionStartingwithRegionPath = new ArrayList<Region>(); if (recursive) { // Recursively find the keys starting from the specified region path. List<String> regionPaths = getAllRegionPaths(cache, true); for (int i = 0; i < regionPaths.size(); i++) { String path = regionPaths.get(i); if (path.startsWith(regionPath) || path.startsWith(Region.SEPARATOR + regionPath)) { Region targetRegion = cache.getRegion(path); listofRegionStartingwithRegionPath.add(targetRegion); } } if (listofRegionStartingwithRegionPath.size() == 0) { if (logger.isDebugEnabled()) logger.debug("Region Not Found - {}", regionPath); return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND, regionPath), false); } } else { Region region = cache.getRegion(regionPath); if (region == null) { if (logger.isDebugEnabled()) logger.debug("Region Not Found - {}", regionPath); return DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND, regionPath), false); } else listofRegionStartingwithRegionPath.add(region); } Object keyObject = null; try { keyObject = getClassObject(key, keyClass); } catch (ClassNotFoundException e) { logger.fatal(e.getMessage(), e); return DataCommandResult.createLocateEntryResult(key, null, null, "ClassNotFoundException " + keyClass, false); } catch (IllegalArgumentException e) { logger.fatal(e.getMessage(), e); return DataCommandResult.createLocateEntryResult(key, null, null, "Error in converting JSON " + e.getMessage(), false); } Object value = null; DataCommandResult.KeyInfo keyInfo = null; keyInfo = new DataCommandResult.KeyInfo(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); keyInfo.setHost(member.getHost()); keyInfo.setMemberId(member.getId()); keyInfo.setMemberName(member.getName()); for (Region region : listofRegionStartingwithRegionPath) { if (region instanceof PartitionedRegion) { // Following code is adaptation of which.java of old Gfsh PartitionedRegion pr = (PartitionedRegion) region; Region localRegion = PartitionRegionHelper.getLocalData((PartitionedRegion) region); value = localRegion.get(keyObject); if (value != null) { DistributedMember primaryMember = PartitionRegionHelper.getPrimaryMemberForKey(region, keyObject); int bucketId = pr.getKeyInfo(keyObject).getBucketId(); boolean isPrimary = member == primaryMember; keyInfo.addLocation(new Object[] { region.getFullPath(), true, getJSONForNonPrimitiveObject(value)[1], isPrimary, "" + bucketId }); } else { if (logger.isDebugEnabled()) logger.debug("Key is not present in the region {}", regionPath); return DataCommandResult.createLocateEntryInfoResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_NOT_FOUND_REGION, false); } } else { if (region.containsKey(keyObject)) { value = region.get(keyObject); if (logger.isDebugEnabled()) logger.debug("Get for key {} value {} in region {}", key, value, region.getFullPath()); if (value != null) keyInfo.addLocation(new Object[] { region.getFullPath(), true, getJSONForNonPrimitiveObject(value)[1], false, null }); else keyInfo.addLocation(new Object[] { region.getFullPath(), false, null, false, null }); } else { if (logger.isDebugEnabled()) logger.debug("Key is not present in the region {}", regionPath); keyInfo.addLocation(new Object[] { region.getFullPath(), false, null, false, null }); } } } if (keyInfo.hasLocation()) { return DataCommandResult.createLocateEntryResult(key, keyInfo, null, null, true); } else { return DataCommandResult.createLocateEntryInfoResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_NOT_FOUND_REGION, false); } }
From source file:com.zenesis.qx.remote.RequestHandler.java
/** * Handles a server method call from the client; expects a serverId, methodName, and an optional * array of parameters//from w w w . j av a2 s .c om * @param jp * @throws ServletException * @throws IOException */ protected void cmdCallServerMethod(JsonParser jp) throws ServletException, IOException { // Get the basics Object obj = getFieldValue(jp, "serverId", Object.class); Class serverClass = null; Proxied serverObject = null; if (obj instanceof Integer) { int serverId = (Integer) obj; serverObject = getProxied(serverId); serverClass = serverObject.getClass(); } else if (obj != null) { try { serverClass = Class.forName(obj.toString()); } catch (ClassNotFoundException e) { log.error("Cannot find server class " + obj + ": " + e.getMessage()); } } String methodName = getFieldValue(jp, "methodName", String.class); int asyncId = getFieldValue(jp, "asyncId", Integer.class); // Onto what should be parameters jp.nextToken(); // Find the method by hand - we have already guaranteed that there will not be conflicting // method names (ie no overridden methods) but Java needs a list of parameter types // so we do it ourselves. boolean found = false; // Check for property accessors; if serverObject is null then it's static method call and // properties are not supported if (serverObject != null && methodName.length() > 3 && (methodName.startsWith("get") || methodName.startsWith("set"))) { String name = methodName.substring(3, 4).toLowerCase(); if (methodName.length() > 4) name += methodName.substring(4); for (ProxyType type = ProxyTypeManager.INSTANCE.getProxyType(serverClass); type != null; type = type .getSuperType()) { ProxyProperty property = type.getProperties().get(name); if (property != null) { Object result = null; if (methodName.startsWith("get")) { readParameters(jp, null); result = property.getValue(serverObject); } else { Object[] values = readParameters(jp, new Class[] { property.getPropertyClass().getJavaType() }); property.setValue(serverObject, values[0]); } if (property.isOnDemand()) tracker.setClientHasValue(serverObject, property); tracker.getQueue().queueCommand(CommandId.CommandType.FUNCTION_RETURN, serverObject, null, new FunctionReturn(asyncId, result)); found = true; break; } } } if (!found) { for (ProxyType type = ProxyTypeManager.INSTANCE.getProxyType(serverClass); type != null && !found; type = type.getSuperType()) { ProxyMethod[] methods = type.getMethods(); for (int i = 0; i < methods.length; i++) if (methods[i].getName().equals(methodName)) { Method method = methods[i].getMethod(); // Call the method Object[] values = null; try { values = readParameters(jp, method.getParameterTypes()); Object result = method.invoke(serverObject, values); tracker.getQueue().queueCommand(CommandId.CommandType.FUNCTION_RETURN, serverObject, null, new FunctionReturn(asyncId, result)); } catch (InvocationTargetException e) { Throwable t = e.getCause(); log.error("Exception while invoking " + method + "(" + Helpers.toString(values) + ") on " + serverObject + ": " + t.getMessage(), t); throw new ProxyException(serverObject, "Exception while invoking " + method + " on " + serverObject + ": " + t.getMessage(), t); } catch (RuntimeException e) { log.error("Exception while invoking " + method + "(" + Helpers.toString(values) + ") on " + serverObject + ": " + e.getMessage(), e); throw new ProxyException(serverObject, "Exception while invoking " + method + " on " + serverObject + ": " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new ServletException("Exception while running " + method + "(" + Helpers.toString(values) + "): " + e.getMessage(), e); } found = true; break; } } } if (!found) throw new ServletException("Cannot find method called " + methodName + " in " + (serverObject != null ? serverObject : serverClass)); jp.nextToken(); }