I' m writing a class to run xjc in java. my code goes as follows:
SchemaCompiler sc = XJC.createSchemaCompiler();
URL url = new URL("file://E:\\JAXB\\books.xsd");
sc.parseSchema(new InputSource(url.toExternalForm()));
S2JJAXBModel model = sc.bind();
JCodeModel cm = model.generateCode(null, null);
cm.build(new FileCodeWriter(new File("E:\\JAXBTest")));
i get model as null when i run this.
Can anyone pls help me or provide any link where i can know abt this.
If you look in the SchemaCompiler API for bind() method it says:
bind() returns null if the compilation
fails. The errors should have been
delivered to the registered error
handler in such a case.
So, you need to register an error listener using SchemaCompiler.setErrorListener() with something like this:
sc.setErrorListener(new ErrorListener(){
public void error(SAXParseException exception){
exception.printStackTrace();
}
});
And hopefully you will get more information on what is going wrong.
Related
A bit of background: PropertyFunction is an interface in Jena API that allows doing performing custom operations using SPARQL syntax. Example:
select ?result { ?result f:myPropertyFunction 'someObject' . }
So I made a class Launch that implements this interface and extends a class Client. Within the body of the exec method of my Launch class I establish a connection to a server and, while sending information is no problem, waiting for the server to respond is. Whenever I try to wait() for server response I get the following exception: java.lang.IllegalMonitorStateException.
Here is the body of my exec method for reference:
QueryIterator it = null;
try {
this.connect(); // works well
this.send(algorithmAndArgs); // works well
this.wait(); // exception is thrown
#SuppressWarnings("unused")
ResultSet rs = ResultSetFactory.create(it, Arrays.asList(resultIdentifiers));
} catch (Exception e) {
e.printStackTrace();
}
return it;
Anyone know what the problem may be? Thank you for your answer.
EDIT 1: One thing that I forgot to mention is that the Client class has a method called onObjectReceived(Object o, Socket s) that is triggered each time something is received from the server. I tried using a isDone variable with a while loop in the exec method and set it to true once an object is received, but it did not work.
I solved my own problem: I created an attribute private final CountDownLatch objectWasReceivedLatch = new CountDownLatch(1) and, in the exec method I do boolean objectWasReceived = objectWasReceivedLatch.await(60, TimeUnit.SECONDS); when I want to wait for a response; in the onObjectReceived method I call objectWasReceivedLatch.countDown().
I need to set a custom message for the user when Retrofit reaches the timeout. I've searched through stackoverflow and couldn't find a solution for this. I've also searched through github and found this (probably the line that's responsible for the message I'm seeing at this point):
ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
This is in the class okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java
So I went to that class, and since it belongs to OkHttp lib, it wouldn't let me edit this message.
Does anyone have any idea how I could use my own custom timeout handler?
Relevant build.gradle entries:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
EDIT:
Both solutions given below would kind-of work probably, but it's really ugly and I'd have to actually change the onFailure method in about 70-80 places which is less than ideal.
On failure block of retrofit network call.
#Override
public void onFailure(Call<Void> call, Throwable t) {
if (t.toString().contains("SocketTimeoutException")) {
// set your custom message here
//view.showToast(R.string.poor_internet_connection);
} else {
.....
}
}
In your error callback method use below code
#Override
public void error(Throwable exception) {
String errorMsg
if (exception instanceof java.net.SocketException || exception instanceof java.net.SocketTimeoutException) {
errorMsg = "Your custom message here"
}
}
I am new to building web applications using spark java.
I am trying to use 'Before' filter but getting the below error. please help. I have pasted my code below.Bootstrap is my class having the main method.
Error: "The method before is undefined for the type BootStrap"
public class BootStrap {
public static void main(String[] args) throws Exception {
ipAddress("localhost");
port(3003);
staticFileLocation("/public/html");
before((request, response) -> {
String user = request.queryParams("user");
String password = request.queryParams("password");
String dbPassword = usernamePasswords.get(user);
if (!(password != null && password.equals(dbPassword))) {
halt(401, "You are not welcome here!!!");
}
});
}
I think it's just lacking to statically import Spark.*;
Not sure this helps, but according to this "Access-Control-Request-Method" is a request header, not a response header. That said, a 404 always shows that the resource you want to find does not exist. Are you sure your url is correct?
I am trying to dispatch fault event in GraniteDS service
method call (Flex):
userService.addUser(user, null, function addUserFault(e:TideFaultEvent):void {
Alert.show(e.fault.faultString);
});
server method (Spring):
#Override
public User addUser(User user) throws Exception{
if(findUserByName(user.getUsername()) != null)
throw new Exception("Username Already Exist");
entityManager.persist(user);
return user;
}
But what i get is silence on client side and java.lang.NoSuchMethodException in server console.
How can i use default graniteds exception converter to deliver fault event to client (Flex)?
Solved. I dont know if it's a bug or not, but you cannot set result function to null and specify fault function only - this wont work. My call method should look like:
userService.addUser(user, function addUserResult(e:TideResultEvent){
// do nothing
}, function addUserFault(e:TideFaultEvent):void {
Alert.show(e.fault.faultString);
});
in this case java Exception in remote method will be send back to flex as TideFaultEvent.
I want to generate a client program using the service
I am unable to display the results, how can I do so?
import java.rmi.RemoteException;
public class searchtry {
public static void main(String[] args) throws RemoteException {
SearchRequest request=new SearchRequest();
SearchRequestType1 type1=new SearchRequestType1();
query.setAppId("*********************************"); //Windows Live gave this id for using that service
query.setSources(new SourceType[]{SourceType.Web});
query.setQuery("Java");
aratip.setParameters(request);
SearchResponseType0 answer= client.search(type1);
System.out.println(answer.toString());
}
For starters, calling
answer.toString();
May or may not result in anything (usually won't). You might just get a string that represents the instance, not the string you're expecting. You need to find a method on SearchResponseType0 that will give you the string representation of the response. Perhaps a method like getContent() or getResponse() or something like that but without understanding more about the web service it's difficult to give you more help. Bottom line, you're using the wrong method to attempt to get the string content of the result.
It looks like your are using the bing-search-java-sdk. They have a very nice example on their homepage you might want to look at:
BingSearchServiceClientFactory factory = BingSearchServiceClientFactory.newInstance();
BingSearchClient client = factory.createBingSearchClient();
SearchRequestBuilder builder = client.newSearchRequestBuilder();
builder.withAppId(applicationId);
builder.withQuery("msdn blogs");
builder.withSourceType(SourceType.WEB);
builder.withVersion("2.0");
builder.withMarket("en-us");
builder.withAdultOption(AdultOption.MODERATE);
builder.withSearchOption(SearchOption.ENABLE_HIGHLIGHTING);
builder.withWebRequestCount(10L);
builder.withWebRequestOffset(0L);
builder.withWebRequestSearchOption(WebSearchOption.DISABLE_HOST_COLLAPSING);
builder.withWebRequestSearchOption(WebSearchOption.DISABLE_QUERY_ALTERATIONS);
SearchResponse response = client.search(builder.getResult());
for (WebResult result : response.getWeb().getResults()) {
System.out.println(result.getTitle());
System.out.println(result.getDescription());
System.out.println(result.getUrl());
System.out.println(result.getDateTime());
}