XML (with namespace) to Object unmarshalling - namespaces

I got following repsonse from a Web service call, I tried to unmarshal the same using JAXB to map it to a java class. I was getting unmarshal exception while doing so.
<?xml version="1.0" encoding="UTF-8"?>
<ns0:QueryByLNResponse xmlns:ns0="UIS_CTMPeople_WS" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns0:getListValues>
<ns0:First_Name>Pradeep</ns0:First_Name>
<ns0:Internet_E-mail/>
<ns0:ManagersName/>
<ns0:Person_ID>PPL1</ns0:Person_ID>
<ns0:Last_Name>Srinivasa Reddy</ns0:Last_Name>
<ns0:Full_Name>Pradeep M Srinivasa Reddy</ns0:Full_Name>
</ns0:getListValues>
<ns0:getListValues>
<ns0:First_Name>Geeth </ns0:First_Name>
<ns0:Internet_E-mail>bas#yahoo.com</ns0:Internet_E-mail>
<ns0:ManagersName/>
<ns0:Person_ID>PPL2</ns0:Person_ID>
<ns0:Last_Name>Srinivasan</ns0:Last_Name>
<ns0:Full_Name>Geeth Srinivasan</ns0:Full_Name>
</ns0:getListValues>
</ns0:QueryByLNResponse>
I tried to unmarshal the above code using
public static Object xmlToObject(String xml, Class... objClass) throws Exception {
JAXBContext jc = JAXBContext.newInstance(objClass);
final Unmarshaller unmarshaller = jc.createUnmarshaller();
return unmarshaller.unmarshal(new StringReader(xml.toString()));
}
It was throwing following error
javax.xml.bind.UnmarshalException: unexpected element (uri:"UIS_CTMPeople_WS", local:"QueryByLNeResponse"). Expected elements are (none)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
How can i unmarshalling this using JAXB ( xml to object ).

Below are a few items that should help:
NAMESPACES
You should use a the #XmlSchema annotation on the package-info class to specify the namespace qualification. Below is an example, you will need to change the package name to match your model.
package-info.java
#XmlSchema(
namespace = "UIS_CTMPeople_WS",
elementFormDefault = XmlNsForm.QUALIFIED)
package example;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
For More Information
http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
ROOT ELEMENTS
It appears that you do not have any of your classes mapped with #XmlRootElement (or #XmlElementDecl). I would expect you to have something like the following:
QueryByLNResponse
package example;
#XmlRootElement(name="QueryByLNResponse")
public class QueryByLNResponse {
}
Alternatively you could specify the class you wish to unmarshal to, by using one of the unmarshal methods that take a Class parameter:
return unmarshaller.unmarshal(xml, QueryByLNResponse.class)
For More Information
http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html
PERFORMANCE
In your same code you are creating a new JAXBContext each time you do an unmarshal. JAXBContext is a thread safe object which can be created once and reused to improve performance.

Related

Powermock - Unable to mock ScheduledExecutorService

I am unable to mock the ScheduledExcecutorService. Unsure where I am making the mistake. One weird part about the exception is "Cannot find method schedule in Object hierarchy", why is it trying to find method in Object class instead of ScheduledExecutorService?
Any help would be appreciated. Thanks in advance.
#RunWith(PowerMockRunner.class)
#PrepareForTest({ ScheduledExecutorService.class, GenericCache.class, ConfigurationDAO.class, ScheduledFuture.class })
#PowerMockIgnore("javax.management.*")
public class CacheManagerTestCase {
// Fields
#Mock
private ScheduledExecutorService mockScheduledExecutorService;
#Mock
private ScheduledFuture scheduledFutureMock;
// Within Test method
when(mockScheduledExecutorService
.schedule(any(Runnable.class), anyLong(), eq(TimeUnit.SECONDS)))
.thenReturn(scheduledFutureMock);
When running the above code, following exception is thrown
org.powermock.reflect.exceptions.MethodNotFoundException: No methods matching the name(s) schedule were found in the class hierarchy of class java.lang.Object.
at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1720)
at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1745)
at org.powermock.reflect.internal.WhiteboxImpl.getBestMethodCandidate(WhiteboxImpl.java:983)
at org.powermock.core.MockGateway$MockInvocation.findMethodToInvoke(MockGateway.java:317)
at org.powermock.core.MockGateway$MockInvocation.init(MockGateway.java:356)
at org.powermock.core.MockGateway$MockInvocation.<init>(MockGateway.java:307)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:142)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:125)
at CacheManagerTestCase.testPeriodicRefreshPropertyFalse(CacheManagerTestCase.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 3 recorded:
-> at CacheManagerTestCase.testPeriodicRefreshPropertyFalse(CacheManagerTestCase.java:82)
-> at CacheManagerTestCase.testPeriodicRefreshPropertyFalse(CacheManagerTestCase.java:82)
-> at CacheManagerTestCase.testPeriodicRefreshPropertyFalse(CacheManagerTestCase.java:82)
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));

how to implement custom DefaultComboBoxModel

I'm need to implement my custom DefaultComboboxModel. Reason for doing this is that every time I call the
DefaultComboBoxModel model = (DefaultComboBoxModel)getModel();
model.removeAllElements();
or
model.addElement(Object);
or
model.insertElementAt(Object,int)
I see that it automatically fires an ItemStateChanged event. This is causing some random item to automatically get selected from the list. This is not what I want, since it populates the editable JTextField with random selected item.
This is the stacktrace I see when debugging using Thread.dumpStack() from my custom Itemlistener that I see when calling above methods:
at javax.swing.JComboBox.fireItemStatehanged(Unknown source)
at javax.swing.JComboBox.selectedItemChanged(Unknown source)
at javax.swing.JComboBox.contentsChanged(Unknown source)
at javax.swing.JComboBox.fireContentsChanged(Unknown source)
at javax.swing.JComboBox.setSelectedItem(Unknown source)
at javax.swing.JComboBox.addElement(Unknown source)
I already tried using setSelectedIndex(-1) before updating model and also after model has been updated, but same problem. I guess having my custom model is the way to go.
Question is how do I implement my custom combo box model? Do I just extend DefaultComboBoxModel? Do I have to override all methods from DefaultComboBoxMode?
Below is what I have so far. But if you see below, I dont have a reference to the actual Vector list to remove the item. If I declare a Vector list field in my custom AutocompleteComboBoxModel, then do I need to override all methods to avoid other SWING code from referencing the Vector in super class?
Remember my goal is to NEVER allow the model to automatically call setSelectedItem(Object), since this seem to be causing problem, unless there is a better way to do this.
public class AutocompleteComboBoxModel extends DefaultComboBoxModel{
public void removeElementAt(int index){
list.removeElementAt(index);
fireIntervalRemoved(this, index, index);
}
}
Also this is how I'm calling the method that does the model manipulation:
public class AutocompleteDocumentListener implementts DocumentListener{
JTextField tf;
public AutocompleteDocumentListener (JTextfield tf){
this.tf = tf;
}
#Override
public void changedUpdate(DocumentEvent e){
}
#Override
public void insertUpdate(DocumentEvent e){
update();
}
#Override
public void removeUpdate(DocumentEvent e){
update();
}
public void update(){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
performSearch(tf.getText());//Search user input
}
)
}
}
EDIT: just want to mention that this weird behavior only occurs when I type very fast. If I type slow, then SWING does not autoselect a random item. So why would this occur when typing fast if I'm using the SwingUtlities.invokeLater? Currently when SWING calls the setSelectedItem(Object), will this fired event execute before other invokeLater requests?
EDIT: I'm removing the ItemListener and still not working. I then kept going and removed the JComboBox KeyListeners, ActionListeners, ComponentListeners and FocusListeners and still it auto selects Item. It seems that sometime after the invokeLater is done that I see the item being selected, probably as I'm still typing on the JTextField:
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at com.artificialmed.coderdx.encoder.TermSelectionListener.itemStateChanged(TermSelectionListener.java:23)
at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
at javax.swing.JComboBox.contentsChanged(Unknown Source)
at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.JComboBox.selectWithKeyChar(Unknown Source)
at javax.swing.plaf.basic.BasicComboBoxUI$Handler.keyPressed(Unknown Source)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at javax.swing.JComboBox.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Thanks in advance.
The addElement(...) or insertElementAt(...) methods should not cause an ItemStateChanged event to be generated since the selection should not change.
The removeAll() elements would cause the selected item to be unselected so it makes sense that an event is generated.
A couple of solutions:
only handle the "item selected" event. This way when you remove all the items you ignore the "item deselected" event.
In your logic that gets invoked when the state changes your code should invoke getSelectedItem(). If this value is null, then you don't do anything.
a) remove the listener, b) invoke the removeAll() method, c) add the listener. Since the listener doesn't exist at the time the removeAll() method is invoked no events will be generated.

JavaFX main application won't start

I need to get this working for an exam in my cisc class, but java and I don't seem to get a long very well. I keep getting these errors on start up and I have searched everywhere for an answer, and just don't get it. Can anyone tell me what I'm doing wrong...?
These are the main method and the fxml I am trying to link to it. There isn't much of anything there at the moment because I am just trying to make it run.
package main;
import java.io.IOException;
import calculator.view.calcController;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
private AnchorPane Layout;
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Calculator");
this.primaryStage.getIcons().add(new Image("file: C://Users/Amanda/Documents/1427173308_Address_Book.png"));
initRootLayout();
}
/**
* Initializes the root layout.
*/
#FXML
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(main.Main.class.getResource("view/Layout.fxml"));
Layout = (AnchorPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(Layout);
primaryStage.setScene(scene);
// Give the controller access to the main app.
calcController controller = loader.getController();
controller.setMain(this);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This is the error I get. I have tried changing the location to everything I can imagine, but it just won't work.
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow`enter code here`n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1108411398.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at main.Main.initRootLayout(Main.java:39)
at main.Main.start(Main.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1905880089.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1184208461.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
... 1 more

Error loading google maps v3 in gwt

I am searching for a library to visualize data as glyphs over a map. Therefore I thought of using google maps api v3 in gwt and dwar the glyohs as an overlay overlay.
Unfortunately I couldn't find any working sample code to get started.
I followed this tutorial
and while executing the project I got this Error:
Unable to load module entry point
classcom.example.google.gwt.mapstutorial.client.SimpleMaps (see associated exception or
details)
java.lang.RuntimeException: Deferred binding failed for
'com.google.gwt.maps.client.impl.MapOptionsImpl' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.google.gwt.maps.client.impl.MapOptionsImpl.<clinit>(MapOptionsImpl.java:31)
at com.google.gwt.maps.client.MapOptions.<init>(MapOptions.java:40)
at com.example.google.gwt.mapstutorial.client.SimpleMaps.onModuleLoad(SimpleMaps.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)Caused by: java.lang.IncompatibleClassChangeError: Found interface com.google.gwt.core.ext.typeinfo.JClassType, but class was expected
at com.google.gwt.jsio.rebind.JSWrapperGenerator.generate(JSWrapperGenerator.java:276)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind(ShellModuleSpaceHost.java:141)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:585)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.google.gwt.maps.client.impl.MapOptionsImpl.<clinit>(MapOptionsImpl.java:31)
at com.google.gwt.maps.client.MapOptions.<init>(MapOptions.java:40)
at com.example.google.gwt.mapstutorial.client.SimpleMaps.onModuleLoad(SimpleMaps.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Could anyone help me out here, or does anyone has another suggestion for a library to use in gwt, thanks!
Here is my Code:
package com.example.google.gwt.mapstutorial.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.maps.client.MapOptions;
import com.google.gwt.maps.client.MapTypeId;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.base.LatLng;
import com.google.gwt.user.client.ui.RootPanel;
public class SimpleMaps implements EntryPoint {
private MapWidget mapWidget;
// GWT module entry point method.
public void onModuleLoad() {
final MapOptions options = new MapOptions();
// Zoom level. Required
options.setZoom(8);
// Open a map centered on Cawker City, KS USA. Required
options.setCenter(new LatLng(39.509, -98.434));
// Map type. Required.
options.setMapTypeId(new MapTypeId().getRoadmap());
// Enable maps drag feature. Disabled by default.
options.setDraggable(true);
// Enable and add default navigation control. Disabled by default.
options.setNavigationControl(true);
// Enable and add map type control. Disabled by default.
options.setMapTypeControl(true);
mapWidget = new MapWidget(options);
mapWidget.setSize("800px", "600px");
// Add the map to the HTML host page
RootPanel.get("mapsTutorial").add(mapWidget);
}
}

SAXException: bad envelope tag

I'm trying to connect to a webservice https protected through a webservice client. Eclipse generated a stub based webservice client and looks nice to me. The problem comes when I try to call a method from the webservice:
String a = (String)webservice.userProfileServices(xml);
I'm also using the following SOAP headers:
esgGatewayPort = (new EsgGatewayLocator()).getesgGatewayPort();
//setting the authentication header
PrefixedQName name = new PrefixedQName("http://schemas.xmlsoap.org/ws/2002/07/secext","Security","wsse");
System.out.println("Setting headers for authentication");
org.apache.axis.message.SOAPHeaderElement sh = new org.apache.axis.message.SOAPHeaderElement(name);
SOAPElement sub;
try {
String clntUserName="myUser";
String clntPassword="myPassword";
sub = sh.addChildElement("UsernameToken");
SOAPElement element = sub.addChildElement("Username");
element.addTextNode(clntUserName);
element = sub.addChildElement("Password");
element.addTextNode(clntPassword);
((org.apache.axis.client.Stub) esgGatewayPort).setHeader(sh);
} catch (SOAPException e) {
e.printStackTrace();
}
I receive the following:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Bad envelope tag: HTML
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Bad envelope tag: HTML
at org.apache.axis.message.EnvelopeBuilder.startElement(EnvelopeBuilder.java:71)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133)
at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:153)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
Any help will be truly appreciated.
Wrong format of the endpoint
Ex: http://localhost:8080/YourService/
Ex: http://localhost:8080/YourService?wsdl
Correct endpoint format to set the constructor
Ex: http://localhost:8080/YourService
I resolved the problem in WAS (WebSphere Application Server), following http://www-01.ibm.com/support/docview.wss?uid=swg1PK54518. Applying the appropriate Fix Pack for your version of WAS resolved the issue.
The problem is probably that you are trying to bind to a https service using http. I had this problem when eclipse generated the stubs for me from a wsdl that was hosted on a https server.
Edit the generated files by eclipse that points to the server URL and it should connect correctly.
Hope that helps.
In my case it got resolved after removing "/" from end of the URL in Axis (not Axis2)
The URL which I was using http://localhost:7000/myWS/
After changing it to http://localhost:7000/myWS worked fine!
Exception:
Main: org.xml.sax.SAXException: Bad envelope tag: table
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
Main: org.xml.sax.SAXException: Bad envelope tag: script
In our case error "Bad envelope tag: script" occurred because of user id got locked