EWS signature updation error - exchangewebservices

public void updateSignature(ExchangeService exchange, String signature) {
try {
FolderId f = new FolderId(WellKnownFolderName.Root);
UserConfiguration user = UserConfiguration.bind(exchange,
"OWA.UserOptions", f, UserConfigurationProperties.All);
if (user.getDictionary().containsKey("signaturetext"))
user.getDictionary().setElements("signaturetext", signature);
else
user.getDictionary().addElement("signaturetext", signature);
user.update();
} catch (Exception e) {
e.printStackTrace();
}
}
I am getting a null pointer exception for user.update(); I am able to print the old signature in the console before setting the new one and also the new one after setting it in the dictionary. But, I am not able to update the changes permanently. Thanks in advance
.

in the others code it's using root.parentFolderId not root.
maybe it's that problem:
attached the code
static void SetSigniture(ExchangeService service) throws Exception {
Folder Root = Folder.bind(service, WellKnownFolderName.Root);
UserConfiguration OWAConfig = UserConfiguration.bind(service, "OWA.UserOptions", Root.getParentFolderId(), UserConfigurationProperties.All);
String hsHtmlSigniture = "<img src='http://www.baidu.com/img/baidu_jgylogo3.gif' />";
String stTextSig = "Text sig";
System.out.println(OWAConfig.getDictionary().getElements("timezone"));;
if (OWAConfig.getDictionary().containsKey("signaturehtml")) {
OWAConfig.getDictionary().setElements("signaturehtml", new Object());
} else {
OWAConfig.getDictionary().addElement("signaturehtml", hsHtmlSigniture);
}
if (OWAConfig.getDictionary().containsKey("signaturetext")) {
OWAConfig.getDictionary().setElements("signaturetext", stTextSig);
} else {
OWAConfig.getDictionary().addElement("signaturetext", stTextSig);
}
OWAConfig.update();
}

Related

actframework can't save in database using $.merge

i'am trying to read data from a form and save it to database.first i read entity from database and use $.merge(formdata).filter("-id").to(entity) .I print the value and it's changed successful.But when i call dao.save it do nothing;
the action code below
#PutAction("{id}")
public void update(#DbBind("id") #NotNull Category cate,Category category, ActionContext context) {
notFoundIfNull(cate);
try {
$.merge(category).filter("-id").to(cate);
System.out.print("name is " + cate.getName());
// cate.setName("test"); // success
this.dao.save(cate);
// redirect("/admin/categories");
} catch (io.ebean.DataIntegrityException e) {
context.flash().error(e.getMessage());
render("edit", category);
}
}
dao.save successful when i call cate.setName("test");
Can someone help me solve this problem?
I solved this problem by myself using the following code
public void mergeTo(Base target){
if(!this.getClass().isAssignableFrom(target.getClass())){
return;
}
Method[] methods = this.getClass().getMethods();
for(Method fromMethod: methods){
if(fromMethod.getDeclaringClass().equals(this.getClass())
&& fromMethod.getName().startsWith("get")){
String fromName = fromMethod.getName();
String toName = fromName.replace("get", "set");
try {
Method toMetod = target.getClass().getMethod(toName, fromMethod.getReturnType());
Object value = fromMethod.invoke(this, (Object[])null);
if(value != null){
toMetod.invoke(target, value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

How to list and click on all links found in webpage and how to check if that link is redirecting to 404 page and throw error in selenium? [duplicate]

This question already has answers here:
Error for HttpResponseCode cannot be resolved to a type while checking URL status code for links
(1 answer)
requests.exceptions.MissingSchema: Invalid URL 'None': No schema supplied while trying to find broken links through Selenium and Python
(2 answers)
Closed 3 years ago.
Please check the below code which i tried
Here i want to check if all links are getting opened that should not contain any 404 page
public void alllinks() {
suites.setupEnviroment();
WebDriver driver = suites.getWebDriver();
driver.get(suites.WEB_PATH5);
Dimension d = new Dimension(1455, 900);
driver.manage().window().setSize(d);
try {
List<WebElement> links = driver.findElements(By.tagName("a"));
ArrayList<String> targets = new ArrayList<String>();
// collect targets locations
for (WebElement link : links) {
targets.add(link.getAttribute("href"));
}
for (String target : targets) {
driver.get(target);
try {
((WebDriver) links).getPageSource().contains("404");
} catch (Exception e) {
System.out.println("error");
}
// do what is needed in the target
}
Logger.getLogger("results").log(new LogRecord(Level.INFO,
MethodHandles.lookup().lookupClass().getCanonicalName() != null ? "success" : "failure"));
driver.close();
} catch (Exception e) {
Logger.getLogger("results").log(new LogRecord(Level.INFO,
MethodHandles.lookup().lookupClass().getCanonicalName() == null ? "success" : "failure"));
}
Thanks in advance!
this sample should do the job. Adapt it to your needs.
public class FindBrokenLinks {
private WebDriver driver;
private int invalidLinks = 0;
#BeforeClass
public void setUp() {
driver = new ChromeDriver();
driver.get("http://google.com"); // change the url
}
#Test
public void checkForBrokenLinks() {
try {
List<WebElement> links = driver.findElements(By.tagName("a"));
for (WebElement link : links) {
if (link != null) {
checkLink(link);
}
}
System.out.println("Total broken links: " + invalidLinks);
} catch (Exception e) {
e.printStackTrace();
}
}
#AfterClass
public void tearDown() {
if (driver != null)
driver.quit();
}
public void checkLink(WebElement linkElement) throws IOException {
HttpURLConnection connection = null;
try {
String link = linkElement.getAttribute("href");
URL url = new URL(link);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
// change the code for your needs.
if (responseCode == 404) {
// you can trow error also ...
System.out.println("Found invalid link: " + link);
invalidLinks++;
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
if (connection != null) {
connection.getErrorStream().close();
}
}
}
}

Java Service Error - webMethods

In a java service, without a function declaration, a function call is there and only compile time error comes. But the output is as expected with no run time errors. How is that possible? Can anyone please explain?
"The method functionName() is undefined" is the error it shows.
Below is the code.
public static final void documentToStringVals(IData pipeline)
throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String success = "false";
IData inputDoc = null;
String outputValue = "";
String headerYN = "N";
boolean headerValue = false;
String delimiter = ",";
String newline = System.getProperty("line.separator");
if (pipelineCursor.first("inputDocument") ) {
inputDoc = (IData) pipelineCursor.getValue();
}
else {
throw new ServiceException("inputDocument is a required parameter");
}
if (pipelineCursor.first("delimiter") ) {
delimiter = (String) pipelineCursor.getValue();
}
if (pipelineCursor.first("headerYN") ) {
headerYN = (String) pipelineCursor.getValue();
}
if (headerYN.equalsIgnoreCase("Y")) {
headerValue = true;
}
try {
outputValue = docValuesToString(inputDoc, headerValue, delimiter);
outputValue += newline;
success = "true";
}
catch (Exception e) {
System.out.println("Exception in getting string from document: " + e.getMessage());
pipelineCursor.insertAfter("errorMessage", e.getMessage());
}
pipelineCursor.insertAfter("success", success);
pipelineCursor.insertAfter("outputValue", outputValue);
pipelineCursor.destroy();
}
The code you posted has no reference to "functionName", so I suspect there's a reference to it either in the shared code section or in another Java service in the same folder. Given that all Java services in a folder get compiled into a single class, and therefore all those services need to be compiled together, this could cause the error message when you're compiling the service above.

Handle Stream in Custom URI Resolver for Saxon Parser

I have to process an xml against an xslt with result-document that create many xml.
As suggested here:
Catch output stream of xsl result-document
I wrote my personal URI Resolver:
public class CustomOutputURIResolver implements OutputURIResolver{
private File directoryOut;
public CustomOutputURIResolver(File directoryOut) {
super();
this.directoryOut = directoryOut;
}
public void close(Result arg0) throws TransformerException {
}
public Result resolve(String href, String base) throws TransformerException {
FileOutputStream fout = null;
try {
File f = new File(directoryOut.getAbsolutePath() + File.separator + href + File.separator + href + ".xml");
f.getParentFile().mkdirs();
fout = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return new StreamResult(fout);
}
}
that get the output directory and then saves here the files.
But then when I tested it in a junit I had some problems in the clean-up phase, when trying to delete the created files and noticed that the FileOutputStream fout is not well handled.
Trying to solve the problem gave me some thoughts:
First I came out with this idea:
public class CustomOutputURIResolver implements OutputURIResolver{
private File directoryOut;
private FileOutputStream fout
public CustomOutputURIResolver(File directoryOut) {
super();
this.directoryOut = directoryOut;
this.fout = null;
}
public void close(Result arg0) throws TransformerException {
try {
if (null != fout) {
fout.flush();
fout.close();
fout = null;
}
} catch (Exception e) {}
}
public Result resolve(String href, String base) throws TransformerException {
try {
if (null != fout) {
fout.flush();
fout.close();
}
} catch (Exception e) {}
fout = null;
try {
File f = new File(directoryOut.getAbsolutePath() + File.separator + href + File.separator + href + ".xml");
f.getParentFile().mkdirs();
fout = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return new StreamResult(fout);
}
}
So the fileOutputStream is closed anytime another one is opened.
But:
1) I don't like this solution very much
2) what if this function is called in a multithread process? (I'm not very skilled about Saxon parsing, so i really don't know..)
3) Is there a chance to create and handle one FileOutputStream for each resolve ?
The reason close() takes a Result argument is so that you can identify which stream to close. Why not:
public void close(Result arg0) throws TransformerException {
try {
if (arg0 instanceof StreamResult) {
OutputStream os = ((StreamResult)arg0).getOutputStream();
os.flush();
os.close();
}
} catch (Exception e) {}
}
From Saxon-EE 9.5, xsl:result-document executes in a new thread, so it's very important that the OutputURIResolver should be thread-safe. Because of this change, from 9.5 an OutputURIResolver must implement an additional method getInstance() which makes it easier to manage state: if your newInstance() method actually creates a new instance, then there will be one instance of the OutputURIResolver for each result document being processed, and it can hold the output stream and close it when requested.

MvvmCross: NotImplementedException calling EnsureFolderExists method of IMvxFileStore

I'm developing my first Windows Store App, using MvvmCross framework and I have a problem with images management. In particular I have the following simple ViewModel in my PCL project, and a Store project with a button bound with AddPictureCommand.
public class FirstViewModel : MvxViewModel
{
IMvxPictureChooserTask _pictureChooserTask;
IMvxFileStore _fileStore;
public FirstViewModel(IMvxPictureChooserTask pictureChooserTask, IMvxFileStore fileStore)
{
_pictureChooserTask = pictureChooserTask;
_fileStore = fileStore;
}
private byte[] _pictureBytes;
public byte[] PictureBytes
{
get { return _pictureBytes; }
set
{
if (_pictureBytes == value) return;
_pictureBytes = value;
RaisePropertyChanged(() => PictureBytes);
}
}
public ICommand AddPictureCommand
{
get { return new MvxCommand(() =>
{
_pictureChooserTask.ChoosePictureFromLibrary(400, 95, pictureAvailable, () => { });
}); }
}
private void pictureAvailable(Stream stream)
{
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
PictureBytes = memoryStream.ToArray();
GenerateImagePath();
}
private string GenerateImagePath()
{
if (PictureBytes == null) return null;
var RandomFileName = "Image" + Guid.NewGuid().ToString("N") + ".jpg";
_fileStore.EnsureFolderExists("Images");
var path = _fileStore.PathCombine("Images", RandomFileName);
_fileStore.WriteFile(path, PictureBytes);
return path;
}
}
The problem is that the method _fileStore.EnsureFolderExists("Images");
gives me the an "NotImplementedException" with message: "Need to implement this - doesn't seem obvious from the StorageFolder API".
Has anyone already seen it before?
Thank you
This not implemented exception is documented in the wiki - see https://github.com/MvvmCross/MvvmCross/wiki/MvvmCross-plugins#File
It should be fairly straightforward to implement these missing methods if they are required. Indeed I know of at least 2 users that have implemented these - but sadly they've not contributed them back.
to implement them, just
fork (copy) the code from https://github.com/MvvmCross/MvvmCross/blob/v3/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File.WindowsStore/MvxWindowsStoreBlockingFileStore.cs
implement the missing methods using the winrt StorageFolder apis
in your Store UI project, don't load the File plugin - so comment out or remove the File bootstrap class.
during setup, register your implementation with ioc using Mvx.RegisterType - e.g.:
protected override void InitializeFirstChance()
{
base.InitializeFirstChance();
Cirrious.CrossCore.Mvx.RegisterType<IMvxFileStore, MyFileStore>();
}
For more on using ioc, see https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control
For more on customising the setup sequence, see https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup
Following Stuart's suggestions I've implemented the following methods for Windows 8 Store App:
public bool FolderExists(string folderPath)
{
try
{
var directory = ToFullPath(folderPath);
var storageFolder = StorageFolder.GetFolderFromPathAsync(directory).Await();
}
catch (FileNotFoundException)
{
return false;
}
catch (Exception ex)
{
MvxTrace.Trace("Exception in FolderExists - folderPath: {0} - {1}", folderPath, ex.ToLongString());
throw ex;
}
return true;
//throw new NotImplementedException("Need to implement this - See EnsureFolderExists");
}
public void EnsureFolderExists(string folderPath)
{
try
{
var directory = ToFullPath(folderPath);
var storageFolder = StorageFolder.GetFolderFromPathAsync(directory).Await();
}
catch (FileNotFoundException)
{
var localFolder = ToFullPath(string.Empty);
var storageFolder = StorageFolder.GetFolderFromPathAsync(localFolder).Await();
storageFolder.CreateFolderAsync(folderPath).Await();
}
catch (Exception ex)
{
MvxTrace.Trace("Exception in EnsureFolderExists - folderPath: {0} - {1}", folderPath, ex.ToLongString());
throw ex;
}
//throw new NotImplementedException("Need to implement this - doesn't seem obvious from the StorageFolder API");
//var folder = StorageFolder.GetFolderFromPathAsync(ToFullPath(folderPath)).Await();
}
The third method we need to implement is DeleteFolder(string folderPath, bool recursive). Unfortunately StorageFolder method "DeleteFolder" doesn't have a "recursive" parameter. So I should implement DeleteFolder ignoring it:
public void DeleteFolder(string folderPath, bool recursive)
{
try
{
var directory = ToFullPath(folderPath);
var storageFolder = StorageFolder.GetFolderFromPathAsync(directory).Await();
storageFolder.DeleteAsync().Await();
}
catch (FileNotFoundException)
{
//Folder doesn't exist. Nothing to do
}
catch (Exception ex)
{
MvxTrace.Trace("Exception in DeleteFolder - folderPath: {0} - {1}", folderPath, ex.ToLongString());
throw ex;
}
//throw new NotImplementedException("Need to implement this - See EnsureFolderExists");
}
or I should check if the folder is empty before to delete it if "recursive" equals false.
Better implementations are welcomed.