List of usage examples for java.net URISyntaxException printStackTrace
public void printStackTrace(PrintStream s)
From source file:edu.stanford.junction.props2.PropDaemon.java
/** * Conveniance runner for PropDaemon/* w w w .j a v a 2 s . c o m*/ * Expects two arguments: junction-url propName */ public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: PROGRAM junction-url propName"); System.exit(0); } final String urlStr = args[0]; final String propName = args[1]; JunctionActor actor = new JunctionActor("prop-daemon") { public void onActivityJoin() { System.out.println("Joined activity!"); } public void onActivityCreate() { System.out.println("Created activity!"); } public void onMessageReceived(MessageHeader header, JSONObject msg) { System.out.println("Got message!"); } public List<JunctionExtra> getInitialExtras() { ArrayList<JunctionExtra> l = new ArrayList<JunctionExtra>(); l.add(new PropDaemon(propName)); return l; } }; try { URI uri = new URI(urlStr); SwitchboardConfig sb = JunctionMaker.getDefaultSwitchboardConfig(uri); JunctionMaker jxMaker = JunctionMaker.getInstance(sb); Junction jx = jxMaker.newJunction(uri, actor); } catch (URISyntaxException e) { System.err.println("Failed to parse url!"); e.printStackTrace(System.err); } catch (JunctionException e) { System.err.println("Failed to connect to junction activity!"); e.printStackTrace(System.err); } catch (Exception e) { System.err.println("Failed to connect to junction activity!"); e.printStackTrace(System.err); } }
From source file:hudson.plugins.doclinks.artifacts.testtools.TestZipBuilder.java
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { FilePath file = build.getWorkspace().child(filename); FilePath dir = file.getParent();//from w w w. jav a2s . c om if (dir != null && !dir.exists()) { dir.mkdirs(); } String seperator = System.getProperty("file.separator"); String resourceDirName = StringUtils.join(getClass().getName().split("\\."), seperator); File resourceDir = null; try { resourceDir = new File(ClassLoader.getSystemResource(resourceDirName).toURI()); } catch (URISyntaxException e) { listener.getLogger().println("Failed to retrieve contents to zip"); e.printStackTrace(listener.getLogger()); } OutputStream os = null; ZipOutputStream zos = null; try { os = file.write(); zos = new ZipOutputStream(os); compress(zos, resourceDir, null); } finally { if (zos != null) { zos.close(); } if (os != null) { os.close(); } } return true; }
From source file:de.elomagic.carafile.client.CaraFileClientTest.java
private URI getURI() { try {// www.j a v a2 s.c o m return new URI("http://localhost:" + Integer.toString(PORT)); } catch (URISyntaxException ex) { ex.printStackTrace(System.err); return null; } }
From source file:openscim.restful.server.resources.user.ldap.LdapUserResource.java
@Override public Response retrieveUser(@Context UriInfo uriInfo, @PathParam("uid") String uid) { // check the ldap template has been setup correctly if (ldapTemplate != null) { // create the mapper if it doesn't already exists if (mapper == null) mapper = new UserAttributesMapper(properties); // build the user dn String dn = uid;/*from w w w . ja v a2s . com*/ if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { // utilise ldap formated dn dn = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE) + "=" + uid + "," + properties.getProperty(UserAttributesMapper.ACCOUNT_BASEDN, UserAttributesMapper.DEFAULT_ACCOUNT_BASEDN); } try { // retrieve the user User user = (User) ldapTemplate.lookup(dn, mapper); // check if the user was found if (user == null) { logger.debug("Resource " + dn + " not found"); // user not found, return an error message return ResourceUtilities.buildErrorResponse(HttpStatus.NOT_FOUND, "Resource " + uid + " not found"); } // determine the url of the new resource URI location = new URI("/User/" + dn); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { location = new URI("/User/" + user.getId()); } // set the internal id to the dn user.setId(dn); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { user.setId(user.getId()); } // user stored successfully, return the user return Response.ok(user).location(location).build(); } catch (URISyntaxException usException) { // problem generating entity location logger.error("problem generating entity location"); usException.printStackTrace(System.out); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider problem generating entity location"); } catch (Exception nException) { logger.debug("Resource " + dn + " not found"); nException.printStackTrace(System.out); // user not found, return an error message return ResourceUtilities.buildErrorResponse(HttpStatus.NOT_FOUND, "Resource " + uid + " not found"); } } else { // ldap not configured logger.error("ldap not configured"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider user ldap repository not configured"); } }
From source file:openscim.restful.server.resources.user.ldap.LdapUserResource.java
@Override public Response createUser(UriInfo uriInfo, User user) { // check the ldap template has been setup correctly if (ldapTemplate != null) { // create the mapper if it doesn't already exists if (mapper == null) mapper = new UserAttributesMapper(properties); // build the user dn String dn = user.getId(); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { // utilise ldap formated dn dn = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE) + "=" + user.getId() + "," + properties.getProperty(UserAttributesMapper.ACCOUNT_BASEDN, UserAttributesMapper.DEFAULT_ACCOUNT_BASEDN); }// w w w. j a v a 2 s. c om try { try { // create the mapper if it doesn't already exists if (mapper == null) mapper = new UserAttributesMapper(properties); // retrieve the user User lookedUser = (User) ldapTemplate.lookup(dn, mapper); // check if the user was found if (lookedUser != null) { // user already exists return ResourceUtilities.buildErrorResponse(HttpStatus.CONFLICT, HttpStatus.CONFLICT.getMessage() + ": Resource " + user.getId() + " already exists"); } } catch (Exception nException) { // user not found, do nothing } Attributes userAttributes = new BasicAttributes(); // get the objectclasses String objectclasses = properties.getProperty(UserAttributesMapper.ACCOUNT_OBJECTCLASS_ATTRIBUTE, UserAttributesMapper.DEFAULT_ACCOUNT_OBJECTCLASS_ATTRIBUTE); // set the objectclass of the user /* Attribute objectclassAttribute = new BasicAttribute("objectclass"); Scanner scanner = new Scanner(objectclasses); scanner.useDelimiter(","); while(scanner.hasNext()) { objectclassAttribute.add(scanner.next()); } */ BasicAttribute objectclassAttribute = new BasicAttribute("objectclass"); objectclassAttribute.add("inetOrgPerson"); objectclassAttribute.add("organizationalPerson"); objectclassAttribute.add("person"); objectclassAttribute.add("top"); userAttributes.put(objectclassAttribute); // get the uid attribute name String uidAtttributeName = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE); // set the uid userAttributes.put(uidAtttributeName, user.getId()); // get the display name attribute name String displayAtttributeName = properties.getProperty(UserAttributesMapper.DISPLAYNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_DISPLAYNAME_ATTRIBUTE); // set the display name if (user.getDisplayName() != null) userAttributes.put(displayAtttributeName, user.getDisplayName()); // get the surname attribute name String surnameAtttributeName = properties.getProperty(UserAttributesMapper.FAMILYNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_FAMILYNAME_ATTRIBUTE); // get the given name attribute name String givenAtttributeName = properties.getProperty(UserAttributesMapper.GIVENNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_GIVENNAME_ATTRIBUTE); // set the names if (user.getName() != null) { if (user.getName().getFamilyName() != null) userAttributes.put(surnameAtttributeName, user.getName().getFamilyName()); if (user.getName().getGivenName() != null) userAttributes.put(givenAtttributeName, user.getName().getGivenName()); } // get the email attribute name String mailAtttributeName = properties.getProperty(UserAttributesMapper.MAIL_ATTRIBUTE, UserAttributesMapper.DEFAULT_MAIL_ATTRIBUTE); // set the emails if (user.getEmails() != null) { Attribute attribute = new BasicAttribute(mailAtttributeName); List<PluralAttribute> emails = user.getEmails().getEmail(); for (PluralAttribute email : emails) { attribute.add(email.getValue()); } userAttributes.put(attribute); } // get the telephone attribute name String telephoneAtttributeName = properties.getProperty(UserAttributesMapper.TELEPHONE_ATTRIBUTE, UserAttributesMapper.DEFAULT_TELEPHONE_ATTRIBUTE); // set the telephones if (user.getPhoneNumbers() != null) { Attribute attribute = new BasicAttribute(telephoneAtttributeName); List<PluralAttribute> telephones = user.getPhoneNumbers().getPhoneNumber(); for (PluralAttribute telephone : telephones) { attribute.add(telephone.getValue()); } userAttributes.put(attribute); } // get the password attribute name String passwordAtttributeName = properties.getProperty(UserAttributesMapper.PASSWORD_ATTRIBUTE, UserAttributesMapper.DEFAULT_PASSWORD_ATTRIBUTE); // set the password if (user.getPassword() != null) userAttributes.put(passwordAtttributeName, user.getPassword()); // create the user ldapTemplate.bind(dn, null, userAttributes); // determine the url of the new resource URI location = new URI("/User/" + dn); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { location = new URI("/User/" + user.getId()); } // set the internal id to the dn user.setId(dn); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { user.setId(user.getId()); } // user stored successfully, return the user return Response.created(location).entity(user).build(); } catch (URISyntaxException usException) { // problem generating entity location logger.error("problem generating entity location"); usException.printStackTrace(System.out); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider problem generating entity location"); } catch (Exception nException) { // problem creating user logger.error("problem creating user"); nException.printStackTrace(System.out); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider problem creating user"); } } else { // ldap not configured logger.error("ldap not configured"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider user ldap repository not configured"); } }