Server-Side XML Validation with CXF Webservice

You can override validation error messages, inserting a line number, by using a custom ValidationEventHandler: package example; import javax.xml.bind.ValidationEvent; import javax.xml.bind.helpers.DefaultValidationEventHandler; public class MyValidationEventHandler extends DefaultValidationEventHandler { @Override public boolean handleEvent(ValidationEvent event) { if (event.getSeverity() == ValidationEvent.WARNING) { return super.handleEvent(event); } else { throw new RuntimeException(event.getMessage() + ” [line:”+event.getLocator().getLineNumber()+”]”); } } } If you configure … Read more

How to call a web service from Ant script or from within Jenkins?

Option 1: “get” task Ant’s get task can be used to invoke web services, but it restricted to GET operations. Only works for very simple web services Option 2: curl Invoke the unix curl command to call the webservice (See this post for examples) <target name=”invoke-webservice”> <exec executable=”curl”> <arg line=”-d ‘param1=value1&param2=value2’ http://example.com/resource.cgi”/> </exec> </target> Note: … Read more

Jersey client exception: A message body writer was not found

Register the MultiPartWriter provider when creating the Client: ClientConfig cc = new DefaultClientConfig(); Client client; cc.getClasses().add(MultiPartWriter.class); client = Client.create(cc); If using Maven, these are the dependencies you need in your pom.xml: <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.17.1</version> </dependency> <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-multipart</artifactId> <version>1.17.1</version> </dependency>

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`

You need to add a metadata exchange (mex) endpoint to your service: <services> <service name=”MyService.MyService” behaviorConfiguration=”metadataBehavior”> <endpoint address=”http://localhost/MyService.svc” binding=”customBinding” bindingConfiguration=”jsonpBinding” behaviorConfiguration=”MyService.MyService” contract=”MyService.IMyService”/> <endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/> </service> </services> Now, you should be able to get metadata for your service Update: ok, so you’re just launching this from Visual Studio – in that case, it will … Read more